1 28 29 package com.caucho.es; 30 31 34 public class ESBoolean extends ESBase { 35 public final static ESBoolean TRUE = new ESBoolean(true); 36 public final static ESBoolean FALSE = new ESBoolean(false); 37 38 boolean value; 39 40 public ESBase typeof() throws ESException 41 { 42 return ESString.create("boolean"); 43 } 44 45 public Class getJavaType() 46 { 47 return boolean.class; 48 } 49 50 public boolean isBoolean() 51 { 52 return true; 53 } 54 55 public boolean toBoolean() 56 { 57 return value; 58 } 59 60 public double toNum() 61 { 62 return value ? 1.0 : 0.0 ; 63 } 64 65 public ESBase getProperty(ESString key) throws Throwable 66 { 67 return Global.getGlobalProto().boolProto.getProperty(key); 68 } 69 70 73 public ESString toStr() 74 { 75 return ESString.create(value ? "true" : "false"); 76 } 77 78 public ESObject toObject() throws ESException 79 { 80 return new ESWrapper("Boolean", Global.getGlobalProto().boolProto, this); 81 } 82 83 public Object toJavaObject() 84 { 85 return new Boolean (value); 86 } 87 88 public boolean ecmaEquals(ESBase b) throws Throwable 89 { 90 if (b == esNull || b == esEmpty || b == esUndefined) 91 return false; 92 else 93 return toNum() == b.toNum(); 94 } 95 96 99 public static ESBoolean create(boolean value) 100 { 101 return value ? TRUE : FALSE; 102 } 103 104 107 private ESBoolean(boolean value) 108 { 109 super(null); 110 111 this.value = value; 112 } 113 } 114 115 116 117 | Popular Tags |