本文整理汇总了Java中org.apache.calcite.linq4j.Enumerator类的典型用法代码示例。如果您正苦于以下问题:Java Enumerator类的具体用法?Java Enumerator怎么用?Java Enumerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Enumerator类属于org.apache.calcite.linq4j包,在下文中一共展示了Enumerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asQueryable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Override
public Queryable<Integer> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String tableName) {
return new AbstractTableQueryable<Integer>(queryProvider, schemaPlus, this, tableName) {
@Override
public Enumerator<Integer> enumerator() {
FluentIterable<Integer> it = FluentIterable
.from(classesList.getClasses())
.transformAndConcat(
new Function<IClass, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(IClass input) {
try {
return Ints.asList(input
.getObjectIds());
} catch (SnapshotException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
});
return Linq4j.iterableEnumerator(it);
}
};
}
示例2: asQueryable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Override
public Queryable<Object[]> asQueryable(QueryProvider queryProvider, SchemaPlus schemaPlus, String tableName) {
return new AbstractTableQueryable<Object[]>(queryProvider, schemaPlus, this, tableName) {
@Override
public Enumerator<Object[]> enumerator() {
FluentIterable<Object[]> it = FluentIterable
.from(references)
.transform(new Function<NamedReference, Object[]>() {
@Nullable
@Override
public Object[] apply(@Nullable NamedReference namedReference) {
HeapReference ref = null;
try {
ref = HeapReference.valueOf(namedReference.getObject());
} catch (SnapshotException e) {
e.printStackTrace();
}
return new Object[]{namedReference.getName(), ref};
}
});
return Linq4j.iterableEnumerator(it);
}
};
}
示例3: enumerator
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/** Generates a list of lines representing the maze in text form. */
public Enumerator<String> enumerator(final Set<Integer> solutionSet) {
final CellContent cellContent;
if (solutionSet == null) {
cellContent = CellContent.SPACE;
} else {
cellContent = new CellContent() {
public String get(int c) {
return solutionSet.contains(c) ? "* " : " ";
}
};
}
return new Enumerator<String>() {
int i = -1;
final StringBuilder b = new StringBuilder();
final StringBuilder b2 = new StringBuilder();
示例4: scan
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public Enumerable<Object[]> scan(DataContext root) {
final Random random = seed >= 0 ? new Random(seed) : new Random();
final Maze maze = new Maze(width, height);
final PrintWriter pw = Util.printWriter(System.out);
maze.layout(random, pw);
if (Maze.DEBUG) {
maze.print(pw, true);
}
return new AbstractEnumerable<Object[]>() {
public Enumerator<Object[]> enumerator() {
final Set<Integer> solutionSet;
if (solution) {
solutionSet = maze.solve(0, 0);
} else {
solutionSet = null;
}
return Linq4j.transform(maze.enumerator(solutionSet),
new Function1<String, Object[]>() {
public Object[] apply(String s) {
return new Object[] {s};
}
});
}
};
}
示例5: scan
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public Enumerable<Object[]> scan(DataContext root, List<RexNode> filters) {
final String[] filterValues = new String[fieldTypes.size()];
for (final Iterator<RexNode> i = filters.iterator(); i.hasNext();) {
final RexNode filter = i.next();
if (addFilter(filter, filterValues)) {
i.remove();
}
}
final int[] fields = CsvEnumerator.identityList(fieldTypes.size());
final AtomicBoolean cancelFlag = DataContext.Variable.CANCEL_FLAG.get(root);
return new AbstractEnumerable<Object[]>() {
public Enumerator<Object[]> enumerator() {
return new CsvEnumerator<>(source, cancelFlag, false, filterValues,
new CsvEnumerator.ArrayRowConverter(fieldTypes, fields));
}
};
}
示例6: find
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Override protected Enumerable<Object> find(String index, List<String> ops,
List<Map.Entry<String, Class>> fields) {
final String dbName = index;
final String queryString = "{" + Util.toString(ops, "", ", ", "") + "}";
final Function1<SearchHit, Object> getter = Elasticsearch2Enumerator.getter(fields);
return new AbstractEnumerable<Object>() {
public Enumerator<Object> enumerator() {
final Iterator<SearchHit> cursor = client.prepareSearch(dbName).setTypes(typeName)
.setSource(queryString).execute().actionGet().getHits().iterator();
return new Elasticsearch2Enumerator(cursor, getter);
}
};
}
示例7: getElementType
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/**
* Returns the element type of a {@link Collection}, {@link Iterable}
* (including {@link org.apache.calcite.linq4j.Queryable Queryable} and
* {@link org.apache.calcite.linq4j.Enumerable Enumerable}), {@link Iterator},
* {@link Enumerator}, or an array.
*
* <p>Returns null if the type is not one of these.</p>
*/
public static Type getElementType(Type type) {
if (type instanceof ArrayType) {
return ((ArrayType) type).getComponentType();
}
if (type instanceof GenericArrayType) {
return ((GenericArrayType) type).getGenericComponentType();
}
Class clazz = toClass(type);
if (clazz.isArray()) {
return clazz.getComponentType();
}
if (Collection.class.isAssignableFrom(clazz)
|| Iterable.class.isAssignableFrom(clazz)
|| Iterator.class.isAssignableFrom(clazz)
|| Enumerator.class.isAssignableFrom(clazz)) {
if (type instanceof ParameterizedType) {
return ((ParameterizedType) type).getActualTypeArguments()[0];
}
return Object.class;
}
return null;
}
示例8: myEnumerable
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
private Enumerable<String> myEnumerable(final int[] closes, final int size) {
return new AbstractEnumerable<String>() {
public Enumerator<String> enumerator() {
return new Enumerator<String>() {
int i = 0;
public String current() {
return "x";
}
public boolean moveNext() {
return i++ < size;
}
public void reset() {
}
public void close() {
++closes[0];
}
};
}
};
}
示例9: testTransformEnumerator
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testTransformEnumerator() {
final List<String> strings = Arrays.asList("one", "two", "three");
final Function1<String, Integer> func = new Function1<String, Integer>() {
public Integer apply(String a0) {
return a0.length();
}
};
final Enumerator<Integer> enumerator =
Linq4j.transform(Linq4j.enumerator(strings), func);
assertThat(enumerator.moveNext(), is(true));
assertThat(enumerator.current(), is(3));
assertThat(enumerator.moveNext(), is(true));
assertThat(enumerator.current(), is(3));
assertThat(enumerator.moveNext(), is(true));
assertThat(enumerator.current(), is(5));
assertThat(enumerator.moveNext(), is(false));
final Enumerator<Integer> enumerator2 =
Linq4j.transform(Linq4j.<String>emptyEnumerator(), func);
assertThat(enumerator2.moveNext(), is(false));
}
示例10: checkCast
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
private void checkCast(Enumerator<Integer> enumerator) {
assertTrue(enumerator.moveNext());
assertEquals(Integer.valueOf(2), enumerator.current());
assertTrue(enumerator.moveNext());
assertNull(enumerator.current());
assertTrue(enumerator.moveNext());
try {
Object x = enumerator.current();
fail("expected error, got " + x);
} catch (ClassCastException e) {
// good
}
assertTrue(enumerator.moveNext());
assertEquals(Integer.valueOf(5), enumerator.current());
assertFalse(enumerator.moveNext());
enumerator.reset();
assertTrue(enumerator.moveNext());
assertEquals(Integer.valueOf(2), enumerator.current());
}
示例11: testList2
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testList2() {
final List<String> experience = Arrays.asList("jimi", "mitch", "noel");
final Enumerator<String> enumerator = Linq4j.enumerator(experience);
assertThat(enumerator.getClass().getName(), endsWith("ListEnumerator"));
assertThat(count(enumerator), equalTo(3));
final Enumerable<String> listEnumerable = Linq4j.asEnumerable(experience);
final Enumerator<String> listEnumerator = listEnumerable.enumerator();
assertThat(listEnumerator.getClass().getName(),
endsWith("ListEnumerator"));
assertThat(count(listEnumerator), equalTo(3));
final Enumerable<String> linkedListEnumerable =
Linq4j.asEnumerable(Lists.newLinkedList(experience));
final Enumerator<String> iterableEnumerator =
linkedListEnumerable.enumerator();
assertThat(iterableEnumerator.getClass().getName(),
endsWith("IterableEnumerator"));
assertThat(count(iterableEnumerator), equalTo(3));
}
示例12: testDefaultIfEmpty
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testDefaultIfEmpty() {
final List<String> experience = Arrays.asList("jimi", "mitch", "noel");
final Enumerable<String> notEmptyEnumerable = Linq4j.asEnumerable(experience).defaultIfEmpty();
final Enumerator<String> notEmptyEnumerator = notEmptyEnumerable.enumerator();
notEmptyEnumerator.moveNext();
assertEquals("jimi", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("mitch", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("noel", notEmptyEnumerator.current());
final Enumerable<String> emptyEnumerable =
Linq4j.asEnumerable(Linq4j.<String>emptyEnumerable()).defaultIfEmpty();
final Enumerator<String> emptyEnumerator = emptyEnumerable.enumerator();
assertTrue(emptyEnumerator.moveNext());
assertNull(emptyEnumerator.current());
assertFalse(emptyEnumerator.moveNext());
}
示例13: testDefaultIfEmpty2
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
@Test public void testDefaultIfEmpty2() {
final List<String> experience = Arrays.asList("jimi", "mitch", "noel");
final Enumerable<String> notEmptyEnumerable =
Linq4j.asEnumerable(experience).defaultIfEmpty("dummy");
final Enumerator<String> notEmptyEnumerator = notEmptyEnumerable.enumerator();
notEmptyEnumerator.moveNext();
assertEquals("jimi", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("mitch", notEmptyEnumerator.current());
notEmptyEnumerator.moveNext();
assertEquals("noel", notEmptyEnumerator.current());
final Enumerable<String> emptyEnumerable =
Linq4j.asEnumerable(Linq4j.<String>emptyEnumerable()).defaultIfEmpty("N/A");
final Enumerator<String> emptyEnumerator = emptyEnumerable.enumerator();
assertTrue(emptyEnumerator.moveNext());
assertEquals("N/A", emptyEnumerator.current());
assertFalse(emptyEnumerator.moveNext());
}
示例14: testJoin
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
public void testJoin(CorrelateJoinType joinType, Integer[][] expected) {
Enumerable<Integer[]> join =
Linq4j.asEnumerable(ImmutableList.of(1, 2, 3, 10, 20, 30))
.correlateJoin(joinType,
new Function1<Integer, Enumerable<Integer>>() {
public Enumerable<Integer> apply(Integer a0) {
if (a0 == 1 || a0 == 10) {
return Linq4j.emptyEnumerable();
}
if (a0 == 2 || a0 == 20) {
return Linq4j.singletonEnumerable(a0 * 10);
}
if (a0 == 3 || a0 == 30) {
return Linq4j.asEnumerable(
ImmutableList.of(-a0 * 10, -a0 * 20));
}
throw new IllegalArgumentException(
"Unexpected input " + a0);
}
}, SELECT_BOTH);
for (int i = 0; i < 2; i++) {
Enumerator<Integer[]> e = join.enumerator();
checkResults(e, expected);
e.close();
}
}
示例15: find
import org.apache.calcite.linq4j.Enumerator; //导入依赖的package包/类
/** Executes a "find" operation on the underlying collection.
*
* <p>For example,
* <code>zipsTable.find("{state: 'OR'}", "{city: 1, zipcode: 1}")</code></p>
*
* @param mongoDb MongoDB connection
* @param filterJson Filter JSON string, or null
* @param projectJson Project JSON string, or null
* @param fields List of fields to project; or null to return map
* @return Enumerator of results
*/
private Enumerable<Object> find(MongoDatabase mongoDb, String filterJson,
String projectJson, List<Map.Entry<String, Class>> fields) {
final MongoCollection collection =
mongoDb.getCollection(collectionName);
final Bson filter =
filterJson == null ? null : BsonDocument.parse(filterJson);
final Bson project =
projectJson == null ? null : BsonDocument.parse(projectJson);
final Function1<Document, Object> getter = MongoEnumerator.getter(fields);
return new AbstractEnumerable<Object>() {
public Enumerator<Object> enumerator() {
@SuppressWarnings("unchecked") final FindIterable<Document> cursor =
collection.find(filter).projection(project);
return new MongoEnumerator(cursor.iterator(), getter);
}
};
}