/** * Creates a new data set that contains the given elements. The elements must all be of the same type, * for example, all of the {@link String} or {@link Integer}. The sequence of elements must not be empty. * Furthermore, the elements must be serializable (as defined in {@link java.io.Serializable}, because the * execution environment may ship the elements into the cluster. * <p> * The framework will try and determine the exact type from the collection elements. * In case of generic elements, it may be necessary to manually supply the type information * via {@link #fromCollection(Collection, TypeInformation)}. * <p> * Note that this operation will result in a non-parallel data source, i.e. a data source with * a degree of parallelism of one. * * @param data The elements to make up the data set. * @return A DataSet representing the given list of elements. */ public <X> DataSource<X> fromElements(X... data) { if (data == null) { throw new IllegalArgumentException("The data must not be null."); } if (data.length == 0) { throw new IllegalArgumentException("The number of elements must not be zero."); } return fromCollection(Arrays.asList(data), TypeExtractor.getForObject(data[0])); }
return fromCollection(data, TypeExtractor.getForObject(firstValue));
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <X> TypeInformation<X> getForObject(X value) { Validate.notNull(value); // check if we can extract the types from tuples, otherwise work with the class if (value instanceof Tuple) { Tuple t = (Tuple) value; int numFields = t.getArity(); TypeInformation<?>[] infos = new TypeInformation[numFields]; for (int i = 0; i < numFields; i++) { Object field = t.getField(i); if (field == null) { throw new InvalidTypesException("Automatic type extraction is not possible on candidates with null values. " + "Please specify the types directly."); } infos[i] = getForObject(field); } return (TypeInformation<X>) new TupleTypeInfo(value.getClass(), infos); } else { return getForClass((Class<X>) value.getClass()); } }