Example #1
0
 public GensonBuilder withDeserializers(Deserializer<?>... deserializer) {
   for (Deserializer<?> d : deserializer) {
     Type typeOfConverter =
         TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Deserializer.class, d.getClass()));
     typeOfConverter = TypeUtil.expandType(typeOfConverter, d.getClass());
     registerDeserializer(d, typeOfConverter);
   }
   return this;
 }
Example #2
0
 public GensonBuilder withSerializers(Serializer<?>... serializer) {
   for (Serializer<?> s : serializer) {
     Type typeOfConverter =
         TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Serializer.class, s.getClass()));
     typeOfConverter = TypeUtil.expandType(typeOfConverter, s.getClass());
     registerSerializer(s, typeOfConverter);
   }
   return this;
 }
Example #3
0
 /**
  * Registers converters mapping them to their corresponding parameterized type.
  *
  * @param converter
  * @return a reference to this builder.
  */
 public GensonBuilder withConverters(Converter<?>... converter) {
   for (Converter<?> c : converter) {
     Type typeOfConverter =
         TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Converter.class, c.getClass()));
     typeOfConverter = TypeUtil.expandType(typeOfConverter, c.getClass());
     registerConverter(c, typeOfConverter);
   }
   return this;
 }
Example #4
0
 private void addDefaultSerializers(List<? extends Serializer<?>> serializers) {
   if (serializers != null) {
     for (Serializer<?> serializer : serializers) {
       Type typeOfConverter =
           TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Serializer.class, serializer.getClass()));
       typeOfConverter = TypeUtil.expandType(typeOfConverter, serializer.getClass());
       if (!serializersMap.containsKey(typeOfConverter))
         serializersMap.put(typeOfConverter, serializer);
     }
   }
 }
Example #5
0
 private void addDefaultDeserializers(List<? extends Deserializer<?>> deserializers) {
   if (deserializers != null) {
     for (Deserializer<?> deserializer : deserializers) {
       Type typeOfConverter =
           TypeUtil.typeOf(
               0, TypeUtil.lookupGenericType(Deserializer.class, deserializer.getClass()));
       typeOfConverter = TypeUtil.expandType(typeOfConverter, deserializer.getClass());
       if (!deserializersMap.containsKey(typeOfConverter))
         deserializersMap.put(typeOfConverter, deserializer);
     }
   }
 }
  /**
   * Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned.
   *
   * @return a shallow copy of this set.
   * @throws RuntimeException
   * @see java.lang.Object#clone()
   */
  public Object clone() {
    try {
      TypeUtil<AbstractBaseGraph<V, E>> typeDecl = null;

      AbstractBaseGraph<V, E> newGraph = TypeUtil.uncheckedCast(super.clone(), typeDecl);

      newGraph.edgeMap = new LinkedHashMap<E, IntrusiveEdge>();

      newGraph.edgeFactory = this.edgeFactory;
      newGraph.unmodifiableEdgeSet = null;
      newGraph.unmodifiableVertexSet = null;

      // NOTE:  it's important for this to happen in an object
      // method so that the new inner class instance gets associated with
      // the right outer class instance
      newGraph.specifics = newGraph.createSpecifics();

      Graphs.addGraph(newGraph, this);

      return newGraph;
    } catch (CloneNotSupportedException e) {
      e.printStackTrace();
      throw new RuntimeException();
    }
  }
Example #7
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {
      StorelessUnivariateStatistic statistic = createStatistic();

      DataType dataType = null;

      for (FieldValue value : values) {

        // "Missing values in the input to an aggregate function are simply ignored"
        if (value == null) {
          continue;
        }

        statistic.increment((value.asNumber()).doubleValue());

        if (dataType != null) {
          dataType = TypeUtil.getResultDataType(dataType, value.getDataType());
        } else {
          dataType = value.getDataType();
        }
      }

      if (statistic.getN() == 0) {
        throw new MissingResultException(null);
      }

      Object result = cast(getResultType(dataType), statistic.getResult());

      return FieldValueUtil.create(result);
    }
Example #8
0
    @Override
    public FieldValue evaluate(List<FieldValue> values) {

      if (values.size() != 2) {
        throw new EvaluationException();
      }

      FieldValue left = values.get(0);
      FieldValue right = values.get(1);

      // "If one of the input fields of a simple arithmetic function is a missing value, the result
      // evaluates to missing value"
      if (left == null || right == null) {
        return null;
      }

      DataType dataType = TypeUtil.getResultDataType(left.getDataType(), right.getDataType());

      Number result;

      try {
        result = evaluate(left.asNumber(), right.asNumber());
      } catch (ArithmeticException ae) {
        throw new InvalidResultException(null);
      }

      return FieldValueUtil.create(cast(dataType, result));
    }
 /** @see Graph#getEdgeTarget(Object) */
 public V getEdgeTarget(E e) {
   return TypeUtil.uncheckedCast(getIntrusiveEdge(e).target, vertexTypeDecl);
 }
 /** @see Graph#getEdgeSource(Object) */
 public V getEdgeSource(E e) {
   return TypeUtil.uncheckedCast(getIntrusiveEdge(e).source, vertexTypeDecl);
 }