1 24 package javax.jcr; 25 26 import java.util.Calendar ; 27 import java.util.Date ; 28 29 35 public class LongValue extends BaseValue { 36 37 public static final int TYPE = PropertyType.LONG; 38 39 private final Long lNumber; 40 41 46 public LongValue(Long lNumber) { 47 super(TYPE); 48 this.lNumber = lNumber; 49 } 50 51 56 public LongValue(long l) { 57 super(TYPE); 58 this.lNumber = new Long (l); 59 } 60 61 71 public static LongValue valueOf(String s) throws ValueFormatException { 72 try { 73 return new LongValue(Long.parseLong(s)); 74 } catch (NumberFormatException e) { 75 throw new ValueFormatException("invalid format", e); 76 } 77 } 78 79 90 public boolean equals(Object obj) { 91 if (this == obj) { 92 return true; 93 } 94 if (obj instanceof LongValue) { 95 LongValue other = (LongValue) obj; 96 if (lNumber == other.lNumber) { 97 return true; 98 } else if (lNumber != null && other.lNumber != null) { 99 return lNumber.equals(other.lNumber); 100 } 101 } 102 return false; 103 } 104 105 109 public Calendar getDate() throws ValueFormatException, IllegalStateException , RepositoryException { 110 setValueConsumed(); 111 112 if (lNumber != null) { 113 Calendar cal = Calendar.getInstance(); 115 cal.setTime(new Date (lNumber.longValue())); 116 return cal; 117 } else { 118 throw new ValueFormatException("empty value"); 119 } 120 } 121 122 125 public long getLong() throws ValueFormatException, IllegalStateException , RepositoryException { 126 setValueConsumed(); 127 128 if (lNumber != null) { 129 return lNumber.longValue(); 130 } else { 131 throw new ValueFormatException("empty value"); 132 } 133 } 134 135 138 public boolean getBoolean() throws ValueFormatException, IllegalStateException , RepositoryException { 139 setValueConsumed(); 140 141 throw new ValueFormatException("conversion to boolean failed: inconvertible types"); 142 } 143 144 147 public double getDouble() throws ValueFormatException, IllegalStateException , RepositoryException { 148 setValueConsumed(); 149 150 if (lNumber != null) { 151 return lNumber.doubleValue(); 152 } else { 153 throw new ValueFormatException("empty value"); 154 } 155 } 156 157 160 public String getString() throws ValueFormatException, IllegalStateException , RepositoryException { 161 setValueConsumed(); 162 163 if (lNumber != null) { 164 return lNumber.toString(); 165 } else { 166 throw new ValueFormatException("empty value"); 167 } 168 } 169 } 170 | Popular Tags |