Java Code Examples for org.apache.flink.api.common.operators.util.FieldSet#toArray()

The following examples show how to use org.apache.flink.api.common.operators.util.FieldSet#toArray() . 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: FieldSetTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void check(FieldSet set, int... elements) {
	if (elements == null) {
		assertEquals(0, set.size());
		return;
	}
	
	assertEquals(elements.length, set.size());
	
	// test contains
	for (int i : elements) {
		set.contains(i);
	}
	
	Arrays.sort(elements);
	
	// test to array
	{
		int[] arr = set.toArray();
		Arrays.sort(arr);
		assertTrue(Arrays.equals(arr, elements));
	}
	
	{
		int[] fromIter = new int[set.size()];
		Iterator<Integer> iter = set.iterator();
		
		for (int i = 0; i < fromIter.length; i++) {
			fromIter[i] = iter.next();
		}
		assertFalse(iter.hasNext());
		Arrays.sort(fromIter);
		assertTrue(Arrays.equals(fromIter, elements));
	}
}
 
Example 2
Source File: Utils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public static FieldList createOrderedFromSet(FieldSet set) {
	if (set instanceof FieldList) {
		return (FieldList) set;
	} else {
		final int[] cols = set.toArray();
		Arrays.sort(cols);
		return new FieldList(cols);
	}
}
 
Example 3
Source File: FieldSetTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void check(FieldSet set, int... elements) {
	if (elements == null) {
		assertEquals(0, set.size());
		return;
	}
	
	assertEquals(elements.length, set.size());
	
	// test contains
	for (int i : elements) {
		set.contains(i);
	}
	
	Arrays.sort(elements);
	
	// test to array
	{
		int[] arr = set.toArray();
		Arrays.sort(arr);
		assertTrue(Arrays.equals(arr, elements));
	}
	
	{
		int[] fromIter = new int[set.size()];
		Iterator<Integer> iter = set.iterator();
		
		for (int i = 0; i < fromIter.length; i++) {
			fromIter[i] = iter.next();
		}
		assertFalse(iter.hasNext());
		Arrays.sort(fromIter);
		assertTrue(Arrays.equals(fromIter, elements));
	}
}
 
Example 4
Source File: Utils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static FieldList createOrderedFromSet(FieldSet set) {
	if (set instanceof FieldList) {
		return (FieldList) set;
	} else {
		final int[] cols = set.toArray();
		Arrays.sort(cols);
		return new FieldList(cols);
	}
}
 
Example 5
Source File: FieldSetTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void check(FieldSet set, int... elements) {
	if (elements == null) {
		assertEquals(0, set.size());
		return;
	}
	
	assertEquals(elements.length, set.size());
	
	// test contains
	for (int i : elements) {
		set.contains(i);
	}
	
	Arrays.sort(elements);
	
	// test to array
	{
		int[] arr = set.toArray();
		Arrays.sort(arr);
		assertTrue(Arrays.equals(arr, elements));
	}
	
	{
		int[] fromIter = new int[set.size()];
		Iterator<Integer> iter = set.iterator();
		
		for (int i = 0; i < fromIter.length; i++) {
			fromIter[i] = iter.next();
		}
		assertFalse(iter.hasNext());
		Arrays.sort(fromIter);
		assertTrue(Arrays.equals(fromIter, elements));
	}
}
 
Example 6
Source File: Utils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static FieldList createOrderedFromSet(FieldSet set) {
	if (set instanceof FieldList) {
		return (FieldList) set;
	} else {
		final int[] cols = set.toArray();
		Arrays.sort(cols);
		return new FieldList(cols);
	}
}