/** * Shallow tuple copy. * @return A new Tuple with the same fields as this. */ @Override @SuppressWarnings("unchecked") public Tuple1<T0> copy() { return new Tuple1<>(this.f0); }
/** * Creates a new tuple and assigns the given values to the tuple's fields. * This is more convenient than using the constructor, because the compiler can * infer the generic type arguments implicitly. For example: * {@code Tuple3.of(n, x, s)} * instead of * {@code new Tuple3<Integer, Double, String>(n, x, s)} */ public static <T0> Tuple1<T0> of(T0 value0) { return new Tuple1<>(value0); } }
@Override public Tuple1<String> map(byte[] value) throws Exception { //5 = string type byte + string size return new Tuple1<>(new String(value, 5, value.length - 5, ConfigConstants.DEFAULT_CHARSET)); } }
public Tuple1<String> map(String value) { String[] tokens = value.split("\\s+"); String songId = tokens[1].substring(1); return new Tuple1<>(songId); } }
@Override public Tuple1<Long> map(Long l) throws Exception { return new Tuple1<Long>(l); } }
@Override public Tuple1<Integer> map(CustomType value) throws Exception { return new Tuple1<Integer>(value.myInt); } }
@Override public Tuple1<String> map(String value) throws Exception { return new Tuple1<>(value); } });
@Override public Tuple1<Long> map(Long value) throws Exception { return new Tuple1<>(value); } });
@Override public Tuple1<Long> map(Long value) throws Exception { return new Tuple1<Long>(value); } }
@Override public Tuple1<Long> getKey(POJO value) throws Exception { return new Tuple1<Long>(value.nestedPojo.longNumber); } }
@SuppressWarnings("unchecked") public Tuple2<Tuple1<String>, Tuple1<String>> map(Tuple2<String, Integer> value) throws Exception { Tuple2<?, ?> t = new Tuple2<Tuple1<String>, Tuple1<String>>(new Tuple1<String>(value.f0), new Tuple1<String>(value.f0)); t.f0 = null; return (Tuple2<Tuple1<String>, Tuple1<String>>) t; } }
@Override public Tuple1<Long> map(Long value) throws Exception { Thread.sleep(200); return new Tuple1<Long>(value); } }
@Test public void testTuple1Int() { @SuppressWarnings({"unchecked", "rawtypes"}) Tuple1<Integer>[] testTuples = new Tuple1[] { new Tuple1<Integer>(42), new Tuple1<Integer>(1), new Tuple1<Integer>(0), new Tuple1<Integer>(-1), new Tuple1<Integer>(Integer.MAX_VALUE), new Tuple1<Integer>(Integer.MIN_VALUE) }; runTests(4, testTuples); }
@Override protected Object[] getTestData() { return new Object[] { new Integer(7), // an object whose class is not on the classpath OBJECT_OUT_OF_CLASSPATH, // an object whose class IS on the classpath with a nested object whose class // is NOT on the classpath new Tuple1<>(OBJECT_OUT_OF_CLASSPATH) }; }
@Override public void flatMap(Tuple2<Integer, Integer> in, Collector<Tuple1<Integer>> out) throws Exception { if (in.f1 < in.f0) { out.collect(new Tuple1<Integer>(in.f0)); } } });
@Override public void flatMap(String word, Collector<Tuple1<String>> out) throws Exception { assertTrue("Unexpected word in stream! wordFromStream: " + word + ", shouldBeOneOf: " + wordList.toString(), wordList.contains(word)); out.collect(new Tuple1<>(word)); } }
@Test public void testGetOutputs() { OutputSelector<Tuple1<Integer>> selector = new MyOutputSelector(); List<String> expectedOutputs = new ArrayList<String>(); expectedOutputs.add("0"); expectedOutputs.add("1"); assertEquals(expectedOutputs, selector.select(new Tuple1<Integer>(2))); expectedOutputs.add("2"); assertEquals(expectedOutputs, selector.select(new Tuple1<Integer>(3))); }