当前位置: 首页>>代码示例>>Java>>正文


Java IteratorUtils.count方法代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.count方法的典型用法代码示例。如果您正苦于以下问题:Java IteratorUtils.count方法的具体用法?Java IteratorUtils.count怎么用?Java IteratorUtils.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils的用法示例。


在下文中一共展示了IteratorUtils.count方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: map

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Override
protected S map(final Traverser.Admin<S> traverser) {
    // We may consider optimizing the iteration of these containers using subtype-specific interfaces.  For
    // example, we could use descendingIterator if we have a Deque.  But in general, we cannot reliably iterate a
    // collection in reverse, so we use the range algorithm with dynamically computed boundaries.
    final S start = traverser.get();
    final long high =
            start instanceof Map ? ((Map) start).size() :
                    start instanceof Collection ? ((Collection) start).size() :
                            start instanceof Path ? ((Path) start).size() :
                                    start instanceof Iterable ? IteratorUtils.count((Iterable) start) :
                                            this.limit;
    final long low = high - this.limit;
    final S result = RangeLocalStep.applyRange(start, low, high);
    return result;
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:TailLocalStep.java

示例2: shouldExecuteCompetingThreadsOnMultipleDbInstances

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
public void shouldExecuteCompetingThreadsOnMultipleDbInstances() throws Exception {
    // the idea behind this test is to simulate a gremlin-server environment where two graphs of the same type
    // are being mutated by multiple threads. originally replicated a bug that was part of OrientDB.

    final Configuration configuration = graphProvider.newGraphConfiguration("g1", this.getClass(), name.getMethodName(), null);
    graphProvider.clear(configuration);
    final Graph g1 = graphProvider.openTestGraph(configuration);

    final Thread threadModFirstGraph = new Thread() {
        @Override
        public void run() {
            graph.addVertex();
            g.tx().commit();
        }
    };

    threadModFirstGraph.start();
    threadModFirstGraph.join();

    final Thread threadReadBothGraphs = new Thread() {
        @Override
        public void run() {
            final long gCounter = IteratorUtils.count(graph.vertices());
            assertEquals(1l, gCounter);

            final long g1Counter = IteratorUtils.count(g1.vertices());
            assertEquals(0l, g1Counter);
        }
    };

    threadReadBothGraphs.start();
    threadReadBothGraphs.join();

    // need to manually close the "g1" instance
    graphProvider.clear(g1, configuration);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:40,代码来源:TransactionTest.java

示例3: shouldSupportMultiPropertyIfTheSameKeyCanBeAssignedMoreThanOnce

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = VertexFeatures.FEATURE_MULTI_PROPERTIES, supported = false)
public void shouldSupportMultiPropertyIfTheSameKeyCanBeAssignedMoreThanOnce() throws Exception {
    try {
        final Vertex v = graph.addVertex("name", "stephen", "name", "steve");
        if (2 == IteratorUtils.count(v.properties()))
            fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), VertexFeatures.FEATURE_MULTI_PROPERTIES));
    } catch (Exception ex) {
        validateException(VertexProperty.Exceptions.multiPropertiesNotSupported(), ex);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:15,代码来源:FeatureSupportTest.java

示例4: validateFileSplits

import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; //导入方法依赖的package包/类
private static void validateFileSplits(final List<FileSplit> fileSplits, final Configuration configuration,
                                       final Class<? extends InputFormat<NullWritable, VertexWritable>> inputFormatClass,
                                       final Optional<Class<? extends OutputFormat<NullWritable, VertexWritable>>> outFormatClass) throws Exception {

    final InputFormat inputFormat = ReflectionUtils.newInstance(inputFormatClass, configuration);
    final TaskAttemptContext job = new TaskAttemptContextImpl(configuration, new TaskAttemptID(UUID.randomUUID().toString(), 0, TaskType.MAP, 0, 0));

    int vertexCount = 0;
    int outEdgeCount = 0;
    int inEdgeCount = 0;

    final OutputFormat<NullWritable, VertexWritable> outputFormat = outFormatClass.isPresent() ? ReflectionUtils.newInstance(outFormatClass.get(), configuration) : null;
    final RecordWriter<NullWritable, VertexWritable> writer = null == outputFormat ? null : outputFormat.getRecordWriter(job);

    boolean foundKeyValue = false;
    for (final FileSplit split : fileSplits) {
        logger.info("\treading file split {}", split.getPath().getName() + " ({}", split.getStart() + "..." + (split.getStart() + split.getLength()), "{} {} bytes)");
        final RecordReader reader = inputFormat.createRecordReader(split, job);

        float lastProgress = -1f;
        while (reader.nextKeyValue()) {
            //System.out.println("" + reader.getProgress() + "> " + reader.getCurrentKey() + ": " + reader.getCurrentValue());
            final float progress = reader.getProgress();
            assertTrue(progress >= lastProgress);
            assertEquals(NullWritable.class, reader.getCurrentKey().getClass());
            final VertexWritable vertexWritable = (VertexWritable) reader.getCurrentValue();
            if (null != writer) writer.write(NullWritable.get(), vertexWritable);
            vertexCount++;
            outEdgeCount = outEdgeCount + (int) IteratorUtils.count(vertexWritable.get().edges(Direction.OUT));
            inEdgeCount = inEdgeCount + (int) IteratorUtils.count(vertexWritable.get().edges(Direction.IN));
            //
            final Vertex vertex = vertexWritable.get();
            assertEquals(Integer.class, vertex.id().getClass());
            if (vertex.value("name").equals("SUGAR MAGNOLIA")) {
                foundKeyValue = true;
                assertEquals(92, IteratorUtils.count(vertex.edges(Direction.OUT)));
                assertEquals(77, IteratorUtils.count(vertex.edges(Direction.IN)));
            }
            lastProgress = progress;
        }
    }

    assertEquals(8049, outEdgeCount);
    assertEquals(8049, inEdgeCount);
    assertEquals(outEdgeCount, inEdgeCount);
    assertEquals(808, vertexCount);
    assertTrue(foundKeyValue);

    if (null != writer) {
        writer.close(new TaskAttemptContextImpl(configuration, job.getTaskAttemptID()));
        for (int i = 1; i < 10; i++) {
            final File outputDirectory = new File(new URL(configuration.get("mapreduce.output.fileoutputformat.outputdir")).toURI());
            final List<FileSplit> splits = generateFileSplits(new File(outputDirectory.getAbsoluteFile() + "/_temporary/0/_temporary/" + job.getTaskAttemptID().getTaskID().toString().replace("task", "attempt") + "_0" + "/part-m-00000"), i);
            validateFileSplits(splits, configuration, inputFormatClass, Optional.empty());
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:58,代码来源:RecordReaderWriterTest.java


注:本文中的org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils.count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。