/** * Creates an instance of {@link ObjectGenerator} which adds up values of given object generators. * * @param type Type object generator will return. * @param summand1 First object generator for addition. * @param summand2 Second object generator for addition. * @param <T> Type object generator will return. * @return An instance of {@link ObjectGenerator} which adds up values of given object generators. */ @SuppressWarnings("unchecked") public static <T> ObjectGenerator<T> add(Class<T> type, ObjectGenerator<T> summand1, ObjectGenerator<T> summand2) { if (type.equals(Byte.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueByte(summand1.value, summand2.value)); } else if (type.equals(Short.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueShort(summand1.value, summand2.value)); } else if (type.equals(Integer.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueInteger(summand1.value, summand2.value)); } else if (type.equals(Long.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueLong(summand1.value, summand2.value)); } else if (type.equals(Float.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueFloat(summand1.value, summand2.value)); } else if (type.equals(Double.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueDouble(summand1.value, summand2.value)); } else { throw new RuntimeException("Type: " + type.getName() + " not supported."); } }
/** * Creates an instance of {@link ObjectGenerator} which adds up values of given object generators. * * @param type Type object generator will return. * @param summand1 First object generator for addition. * @param summand2 Second object generator for addition. * @param <T> Type object generator will return. * @return An instance of {@link ObjectGenerator} which adds up values of given object generators. */ @SuppressWarnings("unchecked") public static <T> ObjectGenerator<T> add(Class<T> type, ObjectGenerator<T> summand1, ObjectGenerator<T> summand2) { if (type.equals(Byte.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueByte(summand1.value, summand2.value)); } else if (type.equals(Short.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueShort(summand1.value, summand2.value)); } else if (type.equals(Integer.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueInteger(summand1.value, summand2.value)); } else if (type.equals(Long.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueLong(summand1.value, summand2.value)); } else if (type.equals(Float.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueFloat(summand1.value, summand2.value)); } else if (type.equals(Double.class)) { return (ObjectGenerator<T>) wrap(new AdditionValueDouble(summand1.value, summand2.value)); } else { throw new RuntimeException("Type: " + type.getName() + " not supported."); } }
/** * Creates addition value. * * @return An addition value. */ @SuppressWarnings("rawtypes") protected Object createAdditionValue() { String type = (String) pop(2); Value summand1 = (Value) pop(1); Value summand2 = (Value) pop(); switch (type) { case "byte": return new AdditionValueByte(summand1, summand2); case "short": return new AdditionValueShort(summand1, summand2); case "int": return new AdditionValueInteger(summand1, summand2); case "long": return new AdditionValueLong(summand1, summand2); case "float": return new AdditionValueFloat(summand1, summand2); case "double": return new AdditionValueDouble(summand1, summand2); default: throw new RuntimeException("Unsupported type for addition value. Type: " + type); } }
/** * Creates addition value. * * @return An addition value. */ @SuppressWarnings("rawtypes") protected Object createAdditionValue() { String type = (String) pop(2); Value summand1 = (Value) pop(1); Value summand2 = (Value) pop(); switch (type) { case "byte": return new AdditionValueByte(summand1, summand2); case "short": return new AdditionValueShort(summand1, summand2); case "int": return new AdditionValueInteger(summand1, summand2); case "long": return new AdditionValueLong(summand1, summand2); case "float": return new AdditionValueFloat(summand1, summand2); case "double": return new AdditionValueDouble(summand1, summand2); default: throw new RuntimeException("Unsupported type for addition value. Type: " + type); } }