Esempio n. 1
0
  /**
   * Gets the field value.
   *
   * @return the value of the field
   */
  public Object value() {
    if (!convert1st) {
      FieldAccess field = field();
      if (field != null) {
        switch (field.typeEnum()) {
          case NUMBER:
            this.value = (VALUE) Conversions.coerce(field.type(), this.value);
            return new MyNumber(this.value);

          case ARRAY:
          case ARRAY_INT:
          case ARRAY_BYTE:
          case ARRAY_SHORT:
          case ARRAY_FLOAT:
          case ARRAY_DOUBLE:
          case ARRAY_LONG:
          case ARRAY_STRING:
          case ARRAY_OBJECT:
          case COLLECTION:
          case SET:
          case LIST:
            this.value = (VALUE) Conversions.coerce(field.getComponentClass(), this.value);
            break;
          default:
            this.value = (VALUE) Conversions.coerce(field.type(), this.value);
        }
      }
      convert1st = true;
    }
    return value;
  }
Esempio n. 2
0
 /**
  * Gets the field value.
  *
  * @return the value of the field
  */
 public Object value2() {
   if (!convert2nd) {
     FieldAccess field = this.field();
     this.value2 = (VALUE) Conversions.coerce(field.type(), this.value2);
     convert2nd = true;
   }
   return value2;
 }
Esempio n. 3
0
 /**
  * Gets the field value.
  *
  * @return the value of the field
  */
 public Object value() {
   if (!convert1st) {
     FieldAccess field = field();
     if (field != null) {
       switch (field.typeEnum()) {
         case ARRAY:
         case COLLECTION:
         case SET:
         case LIST:
           this.value = (VALUE) Conversions.coerce(field.getComponentClass(), this.value);
           break;
         default:
           this.value = (VALUE) Conversions.coerce(field.type(), this.value);
       }
     }
     convert1st = true;
   }
   return value;
 }
Esempio n. 4
0
  public static <T> T[] toArray(Class<T> componentType, Collection<T> collection) {
    T[] array = (T[]) Array.newInstance(componentType, collection.size());

    if (componentType.isAssignableFrom(getComponentType(collection))) {
      return collection.toArray(array);
    } else {

      int index = 0;
      for (Object o : collection) {
        array[index] = Conversions.coerce(componentType, o);
        index++;
      }
      return array;
    }
  }
Esempio n. 5
0
  public Set<Object> valueSet() {

    if (!convert1st) {

      HashSet<Object> set = new HashSet<>(values.length);
      FieldAccess field = this.field();
      Class<?> classType = field.type();

      for (Object v : values) {
        v = Conversions.coerce(classType, this.value);
        set.add(v);
      }

      value = (VALUE) set;

      convert1st = true;
    }
    return (Set<Object>) value;
  }