org.javatuples.Quartet Java Examples
The following examples show how to use
org.javatuples.Quartet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NumberHelperTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldReturnHighestCommonNumberClass() { for (final Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>> q : COMMON_NUMBER_CLASSES) { assertEquals(q.getValue2(), getHighestCommonNumberClass(q.getValue0(), q.getValue1())); assertEquals(q.getValue2(), getHighestCommonNumberClass(q.getValue1(), q.getValue0())); assertEquals(q.getValue3(), getHighestCommonNumberClass(true, q.getValue0(), q.getValue1())); assertEquals(q.getValue3(), getHighestCommonNumberClass(true, q.getValue1(), q.getValue0())); } // Double.NaN and null are not numbers and thus should be ignored for (final Number number : EACH_NUMBER_TYPE) { assertEquals(number.getClass(), getHighestCommonNumberClass(number, Double.NaN)); assertEquals(number.getClass(), getHighestCommonNumberClass(Double.NaN, number)); assertEquals(number.getClass(), getHighestCommonNumberClass(number, null)); assertEquals(number.getClass(), getHighestCommonNumberClass(null, number)); } }
Example #2
Source File: JavaTuplesUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void whenAddNewElement_thenCreateNewTuple() { Pair<String, Integer> pair1 = Pair.with("john", 32); Triplet<String, Integer, String> triplet1 = pair1.add("1051 SW"); assertThat(triplet1.contains("john")); assertThat(triplet1.contains(32)); assertThat(triplet1.contains("1051 SW")); Pair<String, Integer> pair2 = Pair.with("alex", 45); Quartet<String, Integer, String, Integer> quartet2 = pair1.add(pair2); assertThat(quartet2.containsAll(pair1)); assertThat(quartet2.containsAll(pair2)); Quartet<String, Integer, String, Integer> quartet1 = pair1.add("alex", 45); assertThat(quartet1.containsAll("alex", "john", 32, 45)); Triplet<String, String, Integer> triplet2 = pair1.addAt1("1051 SW"); assertThat(triplet2.indexOf("john")).isEqualTo(0); assertThat(triplet2.indexOf("1051 SW")).isEqualTo(1); assertThat(triplet2.indexOf(32)).isEqualTo(2); Unit<Integer> unit = pair1.removeFrom0(); assertThat(unit.contains(32)); }
Example #3
Source File: MergeSingleImpl.java From business with Mozilla Public License 2.0 | 5 votes |
@Override public <A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> MergeFromRepository<Quartet<A0, A1, A2, A3>> into(Class<A0> first, Class<A1> second, Class<A2> third, Class<A3> fourth) { return new MergeSingleTupleFromRepositoryImpl<>(context, dto, first, second, third, fourth); }
Example #4
Source File: MergeSingleImpl.java From business with Mozilla Public License 2.0 | 5 votes |
@Override public <A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> void into(Quartet<A0, A1, A2, A3> quartet) { context.tupleAssemblerOf(Tuples.itemClasses(quartet), dtoClass) .mergeDtoIntoAggregate(dto, quartet); }
Example #5
Source File: MergeSingleImpl.java From business with Mozilla Public License 2.0 | 5 votes |
@Override public <A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> void into(A0 first, A1 second, A2 third, A3 fourth) { into(Quartet.with(first, second, third, fourth)); }
Example #6
Source File: MergeMultipleImpl.java From business with Mozilla Public License 2.0 | 5 votes |
@Override public <A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> MergeFromRepository<MergeAs<Quartet<A0, A1, A2, A3>>> into(Class<A0> first, Class<A1> second, Class<A2> third, Class<A3> fourth) { return new MergeMultipleTuplesFromRepositoryImpl<>(context, dtoStream, first, second, third, fourth); }
Example #7
Source File: Tuples.java From business with Mozilla Public License 2.0 | 5 votes |
/** * Returns the tuple class corresponding to the specified cardinality. * * @param cardinality the cardinality (must be less or equal than 10). * @return the corresponding tuple class. */ public static Class<? extends Tuple> classOfTuple(int cardinality) { switch (cardinality) { case 1: return Unit.class; case 2: return Pair.class; case 3: return Triplet.class; case 4: return Quartet.class; case 5: return Quintet.class; case 6: return Sextet.class; case 7: return Septet.class; case 8: return Octet.class; case 9: return Ennead.class; case 10: return Decade.class; default: throw new IllegalArgumentException("Cannot create a tuple with " + cardinality + " element(s)"); } }
Example #8
Source File: JavaTuplesUnitTest.java From tutorials with MIT License | 5 votes |
@SuppressWarnings("unused") @Test public void whenCreatingTuples_thenCreateTuples() { Pair<String, Integer> pair = new Pair<String, Integer>("This is a pair", 55); Triplet<String, Integer, Double> triplet = Triplet.with("hello", 23, 33.2); List<String> collectionOfNames = Arrays.asList("john", "doe", "anne", "alex"); Quartet<String, String, String, String> quartet = Quartet.fromCollection(collectionOfNames); Pair<String, String> pairFromList = Pair.fromIterable(collectionOfNames, 2); String[] names = new String[] { "john", "doe", "anne" }; Triplet<String, String, String> triplet2 = Triplet.fromArray(names); }
Example #9
Source File: JavaTuplesUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenGetValuexFromTuples_thenRetriveValueWithType() { Quartet<String, Double, Integer, String> quartet = Quartet.with("john", 72.5, 32, "1051 SW"); String name = quartet.getValue0(); Integer age = quartet.getValue2(); assertThat(name).isEqualTo("john"); assertThat(age).isEqualTo(32); }
Example #10
Source File: JavaTuplesUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenGetValueFromTuples_thenRetriveValueWithoutType() { Quartet<String, Double, Integer, String> quartet = Quartet.with("john", 72.5, 32, "1051 SW"); String name = (String) quartet.getValue(0); Integer age = (Integer) quartet.getValue(2); assertThat(name).isEqualTo("john"); assertThat(age).isEqualTo(32); }
Example #11
Source File: MergeSingle.java From business with Mozilla Public License 2.0 | 4 votes |
<A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> MergeFromRepository<Quartet<A0, A1, A2, A3>> into(Class<A0> first, Class<A1> second, Class<A2> third, Class<A3> fourth);
Example #12
Source File: MergeSingle.java From business with Mozilla Public License 2.0 | 4 votes |
<A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> void into(Quartet<A0, A1, A2, A3> quartet);
Example #13
Source File: MergeMultiple.java From business with Mozilla Public License 2.0 | 4 votes |
<A0 extends AggregateRoot<?>, A1 extends AggregateRoot<?>, A2 extends AggregateRoot<?>, A3 extends AggregateRoot<?>> MergeFromRepository<MergeAs<Quartet<A0, A1, A2, A3>>> into(Class<A0> first, Class<A1> second, Class<A2> third, Class<A3> fourth);
Example #14
Source File: TuplesTest.java From business with Mozilla Public License 2.0 | 4 votes |
@Test public void testClassOfTuple() { Class<?> type = Tuples.classOfTuple(String.class); Assertions.assertThat(type) .isEqualTo(Unit.class); type = Tuples.classOfTuple(String.class, Integer.class); Assertions.assertThat(type) .isEqualTo(Pair.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class); Assertions.assertThat(type) .isEqualTo(Triplet.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class); Assertions.assertThat(type) .isEqualTo(Quartet.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class, Boolean.class); Assertions.assertThat(type) .isEqualTo(Quintet.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class, Boolean.class, Byte.class); Assertions.assertThat(type) .isEqualTo(Sextet.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class, Boolean.class, Byte.class, Short.class); Assertions.assertThat(type) .isEqualTo(Septet.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class, Boolean.class, Byte.class, Short.class, Double.class); Assertions.assertThat(type) .isEqualTo(Octet.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class, Boolean.class, Byte.class, Short.class, Double.class, Number.class); Assertions.assertThat(type) .isEqualTo(Ennead.class); type = Tuples.classOfTuple(String.class, Integer.class, Long.class, Float.class, Boolean.class, Byte.class, Short.class, Double.class, Number.class, Character.class); Assertions.assertThat(type) .isEqualTo(Decade.class); }
Example #15
Source File: JavaTuplesUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenCallingToList_thenReturnList() { Quartet<String, Double, Integer, String> quartet = Quartet.with("john", 72.5, 32, "1051 SW"); List<Object> list = quartet.toList(); assertThat(list.size()).isEqualTo(4); }
Example #16
Source File: JavaTuplesUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenCallingToArray_thenReturnArray() { Quartet<String, Double, Integer, String> quartet = Quartet.with("john", 72.5, 32, "1051 SW"); Object[] array = quartet.toArray(); assertThat(array.length).isEqualTo(4); }