示例#1
0
文件: DataType.java 项目: inexas/oak
 public static long getLong(Object value)
     throws NullValueException, TypeMismatchException, OverflowException {
   final Long result;
   if (value == null) {
     throw new NullValueException();
   }
   result = convert(value, Long.class);
   return result.longValue();
 }
示例#2
0
文件: DataType.java 项目: inexas/oak
  /**
   * Given the parsing context and what numerical data type is expected convert a string to the
   * correct type. Note no attempt is made to let the magnitude of the number influence our choice.
   *
   * @param string The string to convert to a number. E.g. "123.3e2". If it contains a '.' or an 'e'
   *     then the type must either be f or F.
   * @param requiredType Either z, Z, f, F or any.
   * @param tb The source. The cursor will be at the end of the number but any type specifier will
   *     not have been consumed. If there is one then we'll eat it.
   * @return The derived type.
   * @throws ParsingException If there is a clash of types.
   */
  private static Object deriveType(String string, DataType requiredType, Text t, int radix) {
    final Object result;

    // Figure out the correct type...
    final DataType derivedType;
    if (t.isEof()) {
      if (requiredType == DataType.any) {
        if (string.indexOf('.') >= 0 || string.indexOf('e') >= 0) {
          derivedType = DataType.f;
        } else {
          derivedType = DataType.z;
        }
      } else {
        derivedType = requiredType;
      }
    } else {
      final char c = t.peek();
      if (c == 'z' || c == 'Z' || c == 'f' || c == 'F') {
        t.consume(c);
        derivedType = DataType.valueOf(String.valueOf(c));
        if (!(requiredType == DataType.any || requiredType == derivedType)) {
          throw new ParsingException("Incompatible type: " + string + c);
        }
      } else {
        if (requiredType == DataType.any) {
          if (string.indexOf('.') >= 0 || string.indexOf('e') >= 0) {
            derivedType = DataType.f;
          } else {
            derivedType = DataType.z;
          }
        } else {
          derivedType = requiredType;
        }
      }
    }

    switch (derivedType) {
      case z:
        result = new Long(Long.parseLong(string, radix));
        break;
      case Z:
        result = new BigInteger(string, radix);
        break;
      case f:
        result = new Double(string);
        break;
      case F:
        result = new BigDecimal(string);
        break;
        // $CASES-OMITTED$
      default:
        throw new UnexpectedException("toType: " + derivedType);
    }

    return result;
  }
示例#3
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((id == null) ? 0 : id.hashCode());
   result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
   result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
   result = prime * result + ((birthdate == null) ? 0 : birthdate.hashCode());
   result = prime * result + ((active == null) ? 0 : active.hashCode());
   result = prime * result + ((role == null) ? 0 : role.hashCode());
   result = prime * result + ((email == null) ? 0 : email.hashCode());
   return result;
 }
示例#4
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   final SignUpResponse other = (SignUpResponse) obj;
   if ((id == null && other.id != null) || !id.equals(other.id)) return false;
   if ((firstName == null && other.firstName != null) || !firstName.equals(other.firstName))
     return false;
   if ((lastName == null && other.lastName != null) || !lastName.equals(other.lastName))
     return false;
   if ((birthdate == null && other.birthdate != null) || !birthdate.equals(other.birthdate))
     return false;
   if ((active == null && other.active != null) || !active.equals(other.active)) return false;
   if ((role == null && other.role != null) || !role.equals(other.role)) return false;
   if ((email == null && other.email != null) || !email.equals(other.email)) return false;
   return true;
 }