-- | Simulates the @isDefined@ Java method. <http://docs.oracle.com/javase/6/docs/api/java/lang/Character.html#isDefined%28int%29>
module Language.Java.Character.IsDefined
(
  IsDefined(..)
) where

import Data.Char
import Data.Fixed
import Data.Word
import Data.Set(Set)
import qualified Data.Set as S

-- | Instances simulate Java characters and provide a decision on simulating @isDefined@.
class Enum c => IsDefined c where
  isDefined ::
    c
    -> Bool
  isNotDefined ::
    c
    -> Bool
  isNotDefined =
    not . isDefined

instance IsDefined Char where
  isDefined c =
    ord c `S.member` isDefinedSet

instance IsDefined Int where
  isDefined c =
    c `S.member` isDefinedSet

instance IsDefined Integer where
  isDefined c =
    c `S.member` isDefinedSet

instance IsDefined Word8 where
  isDefined c =
    c `S.member` isDefinedSet

instance IsDefined Word16 where
  isDefined c =
    c `S.member` isDefinedSet

instance IsDefined Word32 where
  isDefined c =
    c `S.member` isDefinedSet

instance IsDefined Word64 where
  isDefined c =
    c `S.member` isDefinedSet

instance HasResolution a => IsDefined (Fixed a) where
  isDefined c =
    c `S.member` isDefinedSet

isDefinedSet ::
  (Num a, Enum a, Ord a) =>
  Set a
isDefinedSet =
  let r = [
            [0..566]
          , [592..855]
          , [861..879]
          , [884..885]
          , [890]
          , [894]
          , [900..906]
          , [908]
          , [910..929]
          , [931..974]
          , [976..1019]
          , [1024..1158]
          , [1160..1230]
          , [1232..1269]
          , [1272..1273]
          , [1280..1295]
          , [1329..1366]
          , [1369..1375]
          , [1377..1415]
          , [1417..1418]
          , [1425..1441]
          , [1443..1465]
          , [1467..1476]
          , [1488..1514]
          , [1520..1524]
          , [1536..1539]
          , [1548..1557]
          , [1563]
          , [1567]
          , [1569..1594]
          , [1600..1624]
          , [1632..1805]
          , [1807..1866]
          , [1869..1871]
          , [1920..1969]
          , [2305..2361]
          , [2364..2381]
          , [2384..2388]
          , [2392..2416]
          , [2433..2435]
          , [2437..2444]
          , [2447..2448]
          , [2451..2472]
          , [2474..2480]
          , [2482]
          , [2486..2489]
          , [2492..2500]
          , [2503..2504]
          , [2507..2509]
          , [2519]
          , [2524..2525]
          , [2527..2531]
          , [2534..2554]
          , [2561..2563]
          , [2565..2570]
          , [2575..2576]
          , [2579..2600]
          , [2602..2608]
          , [2610..2611]
          , [2613..2614]
          , [2616..2617]
          , [2620]
          , [2622..2626]
          , [2631..2632]
          , [2635..2637]
          , [2649..2652]
          , [2654]
          , [2662..2676]
          , [2689..2691]
          , [2693..2701]
          , [2703..2705]
          , [2707..2728]
          , [2730..2736]
          , [2738..2739]
          , [2741..2745]
          , [2748..2757]
          , [2759..2761]
          , [2763..2765]
          , [2768]
          , [2784..2787]
          , [2790..2799]
          , [2801]
          , [2817..2819]
          , [2821..2828]
          , [2831..2832]
          , [2835..2856]
          , [2858..2864]
          , [2866..2867]
          , [2869..2873]
          , [2876..2883]
          , [2887..2888]
          , [2891..2893]
          , [2902..2903]
          , [2908..2909]
          , [2911..2913]
          , [2918..2929]
          , [2946..2947]
          , [2949..2954]
          , [2958..2960]
          , [2962..2965]
          , [2969..2970]
          , [2972]
          , [2974..2975]
          , [2979..2980]
          , [2984..2986]
          , [2990..2997]
          , [2999..3001]
          , [3006..3010]
          , [3014..3016]
          , [3018..3021]
          , [3031]
          , [3047..3066]
          , [3073..3075]
          , [3077..3084]
          , [3086..3088]
          , [3090..3112]
          , [3114..3123]
          , [3125..3129]
          , [3134..3140]
          , [3142..3144]
          , [3146..3149]
          , [3157..3158]
          , [3168..3169]
          , [3174..3183]
          , [3202..3203]
          , [3205..3212]
          , [3214..3216]
          , [3218..3240]
          , [3242..3251]
          , [3253..3257]
          , [3260..3268]
          , [3270..3272]
          , [3274..3277]
          , [3285..3286]
          , [3294]
          , [3296..3297]
          , [3302..3311]
          , [3330..3331]
          , [3333..3340]
          , [3342..3344]
          , [3346..3368]
          , [3370..3385]
          , [3390..3395]
          , [3398..3400]
          , [3402..3405]
          , [3415]
          , [3424..3425]
          , [3430..3439]
          , [3458..3459]
          , [3461..3478]
          , [3482..3505]
          , [3507..3515]
          , [3517]
          , [3520..3526]
          , [3530]
          , [3535..3540]
          , [3542]
          , [3544..3551]
          , [3570..3572]
          , [3585..3642]
          , [3647..3675]
          , [3713..3714]
          , [3716]
          , [3719..3720]
          , [3722]
          , [3725]
          , [3732..3735]
          , [3737..3743]
          , [3745..3747]
          , [3749]
          , [3751]
          , [3754..3755]
          , [3757..3769]
          , [3771..3773]
          , [3776..3780]
          , [3782]
          , [3784..3789]
          , [3792..3801]
          , [3804..3805]
          , [3840..3911]
          , [3913..3946]
          , [3953..3979]
          , [3984..3991]
          , [3993..4028]
          , [4030..4044]
          , [4047]
          , [4096..4129]
          , [4131..4135]
          , [4137..4138]
          , [4140..4146]
          , [4150..4153]
          , [4160..4185]
          , [4256..4293]
          , [4304..4344]
          , [4347]
          , [4352..4441]
          , [4447..4514]
          , [4520..4601]
          , [4608..4614]
          , [4616..4678]
          , [4680]
          , [4682..4685]
          , [4688..4694]
          , [4696]
          , [4698..4701]
          , [4704..4742]
          , [4744]
          , [4746..4749]
          , [4752..4782]
          , [4784]
          , [4786..4789]
          , [4792..4798]
          , [4800]
          , [4802..4805]
          , [4808..4814]
          , [4816..4822]
          , [4824..4846]
          , [4848..4878]
          , [4880]
          , [4882..4885]
          , [4888..4894]
          , [4896..4934]
          , [4936..4954]
          , [4961..4988]
          , [5024..5108]
          , [5121..5750]
          , [5760..5788]
          , [5792..5872]
          , [5888..5900]
          , [5902..5908]
          , [5920..5942]
          , [5952..5971]
          , [5984..5996]
          , [5998..6000]
          , [6002..6003]
          , [6016..6109]
          , [6112..6121]
          , [6128..6137]
          , [6144..6158]
          , [6160..6169]
          , [6176..6263]
          , [6272..6313]
          , [6400..6428]
          , [6432..6443]
          , [6448..6459]
          , [6464]
          , [6468..6509]
          , [6512..6516]
          , [6624..6655]
          , [7424..7531]
          , [7680..7835]
          , [7840..7929]
          , [7936..7957]
          , [7960..7965]
          , [7968..8005]
          , [8008..8013]
          , [8016..8023]
          , [8025]
          , [8027]
          , [8029]
          , [8031..8061]
          , [8064..8116]
          , [8118..8132]
          , [8134..8147]
          , [8150..8155]
          , [8157..8175]
          , [8178..8180]
          , [8182..8190]
          , [8192..8276]
          , [8279]
          , [8287..8291]
          , [8298..8305]
          , [8308..8334]
          , [8352..8369]
          , [8400..8426]
          , [8448..8507]
          , [8509..8523]
          , [8531..8579]
          , [8592..9168]
          , [9216..9254]
          , [9280..9290]
          , [9312..9751]
          , [9753..9853]
          , [9856..9873]
          , [9888..9889]
          , [9985..9988]
          , [9990..9993]
          , [9996..10023]
          , [10025..10059]
          , [10061]
          , [10063..10066]
          , [10070]
          , [10072..10078]
          , [10081..10132]
          , [10136..10159]
          , [10161..10174]
          , [10192..10219]
          , [10224..11021]
          , [11904..11929]
          , [11931..12019]
          , [12032..12245]
          , [12272..12283]
          , [12288..12351]
          , [12353..12438]
          , [12441..12543]
          , [12549..12588]
          , [12593..12686]
          , [12688..12727]
          , [12784..12830]
          , [12832..12867]
          , [12880..12925]
          , [12927..13054]
          , [13056..19893]
          , [19904..40869]
          , [40960..42124]
          , [42128..42182]
          , [44032..55203]
          , [55296..64045]
          , [64048..64106]
          , [64256..64262]
          , [64275..64279]
          , [64285..64310]
          , [64312..64316]
          , [64318]
          , [64320..64321]
          , [64323..64324]
          , [64326..64433]
          , [64467..64831]
          , [64848..64911]
          , [64914..64967]
          , [65008..65021]
          , [65024..65039]
          , [65056..65059]
          , [65072..65106]
          , [65108..65126]
          , [65128..65131]
          , [65136..65140]
          , [65142..65276]
          , [65279]
          , [65281..65470]
          , [65474..65479]
          , [65482..65487]
          , [65490..65495]
          , [65498..65500]
          , [65504..65510]
          , [65512..65518]
          , [65529..65533]
          , [65536..65547]
          , [65549..65574]
          , [65576..65594]
          , [65596..65597]
          , [65599..65613]
          , [65616..65629]
          , [65664..65786]
          , [65792..65794]
          , [65799..65843]
          , [65847..65855]
          , [66304..66334]
          , [66336..66339]
          , [66352..66378]
          , [66432..66461]
          , [66463]
          , [66560..66717]
          , [66720..66729]
          , [67584..67589]
          , [67592]
          , [67594..67637]
          , [67639..67640]
          , [67644]
          , [67647]
          , [118784..119029]
          , [119040..119078]
          , [119082..119261]
          , [119552..119638]
          , [119808..119892]
          , [119894..119964]
          , [119966..119967]
          , [119970]
          , [119973..119974]
          , [119977..119980]
          , [119982..119993]
          , [119995]
          , [119997..120003]
          , [120005..120069]
          , [120071..120074]
          , [120077..120084]
          , [120086..120092]
          , [120094..120121]
          , [120123..120126]
          , [120128..120132]
          , [120134]
          , [120138..120144]
          , [120146..120483]
          , [120488..120777]
          , [120782..120831]
          , [131072..173782]
          , [194560..195101]
          ]
  in S.fromList . concat $ r