Changeset 3722


Ignore:
Timestamp:
Apr 17, 2008, 4:31:10 PM (13 years ago)
Author:
yura
Message:
 
Location:
to-imperative/trunk/java/java
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/java/java/org/refal/plus/Native.java

    r3720 r3722  
    9696    // T typeValue (Comparable<?> term)
    9797   
    98     private static Comparable<?> getTerm (Expr expr) throws ClassCastException {
    99         if (expr.length() != 1)
    100             throw new ClassCastException();
    101         return expr.at(1);
    102     }
    103    
    104     @Deprecated
    105     public static boolean booleanValue (Comparable<?> term) {
     98    @Deprecated
     99    public static boolean booleanValue (Comparable<?> term) throws ClassCastException {
    106100        return Boolean.parseBoolean((String) term);
    107101    }
    108102
    109103    @Deprecated
    110     public static char charValue (Comparable<?> term) {
     104    public static char charValue (Comparable<?> term) throws ClassCastException {
    111105        return ((Character) term).charValue();
    112106    }
    113107
    114108    @Deprecated
    115     public static byte byteValue (Comparable<?> term) {
     109    public static byte byteValue (Comparable<?> term) throws ClassCastException {
    116110        return ((BigInteger) term).byteValue();
    117111    }
    118112
    119113    @Deprecated
    120     public static int intValue (Comparable<?> term) {
     114    public static int intValue (Comparable<?> term) throws ClassCastException {
    121115        return ((BigInteger) term).intValue();
    122116    }
    123117
    124118    @Deprecated
    125     public static long longValue (Comparable<?> term) {
     119    public static long longValue (Comparable<?> term) throws ClassCastException {
    126120        return ((BigInteger) term).longValue();
    127121    }
    128122
    129123    @Deprecated
    130     public static short shortValue (Comparable<?> term) {
     124    public static short shortValue (Comparable<?> term) throws ClassCastException {
    131125        return ((BigInteger) term).shortValue();
    132126    }
     
    138132
    139133    public static boolean booleanValue (Expr expr) throws ClassCastException {
    140         return booleanValue(getTerm(expr));
     134        return booleanValue(Symbol.getTerm(expr));
    141135    }
    142136
    143137    public static char charValue (Expr expr) throws ClassCastException {
    144         return charValue(getTerm(expr));
     138        return charValue(Symbol.getTerm(expr));
    145139    }
    146140
    147141    public static byte byteValue (Expr expr) throws ClassCastException {
    148         return byteValue(getTerm(expr));
     142        return byteValue(Symbol.getTerm(expr));
    149143    }
    150144
    151145    public static int intValue (Expr expr) throws ClassCastException {
    152         return intValue(getTerm(expr));
     146        return intValue(Symbol.getTerm(expr));
    153147    }
    154148
    155149    public static long longValue (Expr expr) throws ClassCastException {
    156         return longValue(getTerm(expr));
     150        return longValue(Symbol.getTerm(expr));
    157151    }
    158152
    159153    public static short shortValue (Expr expr) throws ClassCastException {
    160         return shortValue(getTerm(expr));
    161     }
    162 
    163     public static Object objectValue (Expr expr) throws ClassCastException {
    164         return objectValue(getTerm(expr));
     154        return shortValue(Symbol.getTerm(expr));
     155    }
     156
     157    public static Object objectValue (Expr expr) {
     158        return objectValue(Symbol.getTerm(expr));
    165159    }
    166160
  • to-imperative/trunk/java/java/org/refal/plus/Symbol.java

    r3719 r3722  
    3434    }
    3535
     36    public static Comparable<?> newBox (Comparable<?> term) {
     37        return new Reference<Box>(new Box(term));
     38    }
     39
    3640    public static Comparable<?> newChannel (String name) {
    3741        return new Reference<Channel>(name, new Channel());
     42    }
     43
     44    public static Comparable<?> newChannel (String name, InputStream is) {
     45        return new Reference<Channel>(name, new Channel(is));
     46    }
     47
     48    public static Comparable<?> newChannel (String name, OutputStream os) {
     49        return new Reference<Channel>(name, new Channel(os));
     50    }
     51
     52    public static Comparable<?> newFunc (String name, Func func) {
     53        return new Reference<Func>(name, func);
    3854    }
    3955
     
    5066    }
    5167
    52     public static Comparable<?> newFunc (String name, Func func) {
    53         return new Reference<Func>(name, func);
    54     }
    5568
    56     public static Reference<StringBuffer> newString () {
    57         return new Reference<StringBuffer>(new StringBuffer());
    58     }
    59 
    60     public static Comparable<?> newBox (Comparable<?> term) {
    61         return new Reference<Box>(new Box(term));
    62     }
    63 
    64     public static Comparable<?> newChannel (String name, InputStream is) {
    65         return new Reference<Channel>(name, new Channel(is));
    66     }
    67 
    68     public static Comparable<?> newChannel (String name, OutputStream os) {
    69         return new Reference<Channel>(name, new Channel(os));
    70     }
    7169
    7270    public static Box getBox (Expr expr) throws ClassCastException {
    73         assert expr.length() == 1;
    74         return (Box) ((Reference<?>) expr.at(0)).object;
     71        return (Box) getObject(expr);
    7572    }
    7673
    7774    public static Channel getChannel (Expr expr) throws ClassCastException {
    78         assert expr.length() == 1;
    79         return (Channel) ((Reference<?>) expr.at(0)).object;
     75        return (Channel) getObject(expr);
    8076    }
    8177
    8278    public static Table getTable (Expr expr) throws ClassCastException {
    83         assert expr.length() == 1;
    84         return (Table) ((Reference<?>) expr.at(0)).object;
     79        return (Table) getObject(expr);
    8580    }
    8681
    8782    public static Vector getVector (Expr expr) throws ClassCastException {
    88         assert expr.length() == 1;
    89         return (Vector) ((Reference<?>) expr.at(0)).object;
     83        return (Vector) getObject(expr);
    9084    }
    9185
    9286    public static org.refal.plus.objects.String getString (Expr expr) throws ClassCastException {
    93         assert expr.length() == 1;
    94         return (org.refal.plus.objects.String) ((Reference<?>) expr.at(0)).object;
     87        return (org.refal.plus.objects.String) getObject(expr);
    9588    }
    9689
    9790    public static Func getFunc (Expr expr) throws ClassCastException {
    98         assert expr.length() == 1;
    99         return (Func) ((Reference<?>) expr.at(0)).object;
     91        return (Func) getObject(expr);
    10092    }
    10193
     94
     95   
    10296    public static <T> void setToResult (T object, Result res) {
    10397        res.assign(new Reference<T>(object));
     
    10599
    106100    public static BigInteger getBigInteger (Expr expr) throws ClassCastException {
    107         assert expr.length() == 1;
    108         return (BigInteger) expr.at(0);
     101        return (BigInteger) getTerm(expr);
    109102    }
    110103
    111104    public static Character getCharacter (Expr expr) throws ClassCastException {
    112         assert expr.length() == 1;
    113         return (Character) expr.at(0);
     105        return (Character) getTerm(expr);
    114106    }
    115107
    116108    public static int intValue (Expr expr) throws ClassCastException, Util.ValueOutOfBoundsException {
    117         assert expr.length() == 1;
    118         return Util.intValue((BigInteger) expr.at(0));
     109        return Util.intValue(getBigInteger(expr));
    119110    }
    120111
    121112    public static int uintValue (Expr expr) throws ClassCastException, Util.NegativeValueException,
    122113            Util.ValueOutOfBoundsException {
    123         assert expr.length() == 1;
    124         return Util.uintValue((BigInteger) expr.at(0));
     114        return Util.uintValue(getBigInteger(expr));
    125115    }
    126116
    127117    public static long ulongValue (Expr expr) throws ClassCastException, Util.NegativeValueException,
    128118            Util.ValueOutOfBoundsException {
    129         assert expr.length() == 1;
    130         return Util.ulongValue((BigInteger) expr.at(0));
     119        return Util.ulongValue(getBigInteger(expr));
    131120    }
    132121
     122    static Comparable<?> getTerm (Expr expr) {
     123        assert expr.length() == 1;
     124        return expr.at(0);
     125    }
     126
     127    static Object getObject (Expr expr) throws ClassCastException {
     128        return ((Reference<?>) getTerm(expr)).object;
     129    }
    133130}
  • to-imperative/trunk/java/java/refal/plus/Class.java

    r3721 r3722  
    2020
    2121    /** Returns <code>null</code> if argument is not a term */
    22     private static Comparable<?> getTerm (Expr expr) {
     22    private static Comparable<?> isTerm (Expr expr) {
    2323        if (expr.length() == 1)
    2424            return expr.at(0);
     
    2727
    2828    /** Returns <code>null</code> if argument is not the Reference */
    29     private static Object getObject (Expr expr) {
    30         Comparable<?> term = getTerm(expr);
     29    private static Object isObject (Expr expr) {
     30        Comparable<?> term = isTerm(expr);
    3131        if (term instanceof Reference)
    3232            return ((Reference<?>) term).object;
     
    3636    @RefalFormat("$func? IsChar e.expr = ;")
    3737    public static boolean IsChar (Expr expr) {
    38         return getTerm(expr) instanceof Character;
     38        return isTerm(expr) instanceof Character;
    3939    }
    4040
    4141    @RefalFormat("$func? IsDigit e.expr = ;")
    4242    public static boolean IsDigit (Expr expr) {
    43         Comparable<?> term = getTerm(expr);
     43        Comparable<?> term = isTerm(expr);
    4444        if (term instanceof Character)
    4545            return Character.isDigit(((Character) term).charValue());
     
    4949    @RefalFormat("$func? IsLetter e.expr = ;")
    5050    public static boolean IsLetter (Expr expr) {
    51         Comparable<?> term = getTerm(expr);
     51        Comparable<?> term = isTerm(expr);
    5252        if (term instanceof Character)
    5353            return Character.isLetter(((Character) term).charValue());
     
    5757    @RefalFormat("$func? IsInt e.expr = ;")
    5858    public static boolean IsInt (Expr expr) {
    59         return getTerm(expr) instanceof BigInteger;
     59        return isTerm(expr) instanceof BigInteger;
    6060    }
    6161
    6262    @RefalFormat("$func? IsWord e.expr = ;")
    6363    public static boolean IsWord (Expr expr) {
    64         return getTerm(expr) instanceof java.lang.String;
     64        return isTerm(expr) instanceof java.lang.String;
    6565    }
    6666
    6767    @RefalFormat("$func? IsBox e.expr = ;")
    6868    public static boolean IsBox (Expr expr) {
    69         return getObject(expr) instanceof Box;
     69        return isObject(expr) instanceof Box;
    7070    }
    7171
    7272    @RefalFormat("$func? IsChannel e.expr = ;")
    7373    public static boolean IsChannel (Expr expr) {
    74         return getObject(expr) instanceof Channel;
     74        return isObject(expr) instanceof Channel;
    7575    }
    7676
    7777    @RefalFormat("$func? IsFunc e.expr = ;")
    7878    public static boolean IsFunc (Expr expr) {
    79         return getObject(expr) instanceof Func;
     79        return isObject(expr) instanceof Func;
    8080    }
    8181
    8282    @RefalFormat("$func? IsString e.expr = ;")
    8383    public static boolean IsString (Expr expr) {
    84         return getObject(expr) instanceof String;
     84        return isObject(expr) instanceof String;
    8585    }
    8686
    8787    @RefalFormat("$func? IsTable e.expr = ;")
    8888    public static boolean IsTable (Expr expr) {
    89         return getObject(expr) instanceof Table;
     89        return isObject(expr) instanceof Table;
    9090    }
    9191
    9292    @RefalFormat("$func? IsVector e.expr = ;")
    9393    public static boolean IsVector (Expr expr) {
    94         return getObject(expr) instanceof Vector;
     94        return isObject(expr) instanceof Vector;
    9595    }
    9696
Note: See TracChangeset for help on using the changeset viewer.