Java Code Examples for com.google.common.collect.UnmodifiableIterator#next()

The following examples show how to use com.google.common.collect.UnmodifiableIterator#next() . 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: RelCollationImpl.java    From Bats with Apache License 2.0 6 votes vote down vote up
public int compareTo(RelMultipleTrait o) {
  final RelCollationImpl that = (RelCollationImpl) o;
  final UnmodifiableIterator<RelFieldCollation> iterator =
      that.fieldCollations.iterator();
  for (RelFieldCollation f : fieldCollations) {
    if (!iterator.hasNext()) {
      return 1;
    }
    final RelFieldCollation f2 = iterator.next();
    int c = Utilities.compare(f.getFieldIndex(), f2.getFieldIndex());
    if (c != 0) {
      return c;
    }
  }
  return iterator.hasNext() ? -1 : 0;
}
 
Example 2
Source File: RelCollationImpl.java    From Quicksql with MIT License 6 votes vote down vote up
public int compareTo(@Nonnull RelMultipleTrait o) {
  final RelCollationImpl that = (RelCollationImpl) o;
  final UnmodifiableIterator<RelFieldCollation> iterator =
      that.fieldCollations.iterator();
  for (RelFieldCollation f : fieldCollations) {
    if (!iterator.hasNext()) {
      return 1;
    }
    final RelFieldCollation f2 = iterator.next();
    int c = Utilities.compare(f.getFieldIndex(), f2.getFieldIndex());
    if (c != 0) {
      return c;
    }
  }
  return iterator.hasNext() ? -1 : 0;
}
 
Example 3
Source File: AbstractEventQueryImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public synchronized void addListener ( final EventListener eventListener )
{
    this.listeners.add ( eventListener );

    final UnmodifiableIterator<List<Event>> it = Iterators.partition ( AbstractEventQueryImpl.this.events.iterator (), chunkSize );
    while ( it.hasNext () )
    {
        final List<org.eclipse.scada.ae.Event> chunk = it.next ();
        this.executor.execute ( new Runnable () {

            @Override
            public void run ()
            {
                eventListener.handleEvent ( chunk );
            }
        } );
    }

}
 
Example 4
Source File: BlockGenericPipe.java    From Logistics-Pipes-2 with MIT License 6 votes vote down vote up
@Override
public Optional<TRSRTransformation> apply(Optional<? extends IModelPart> part)
      {
          if(part.isPresent())
          {
              // This whole thing is subject to change, but should do for now.
              UnmodifiableIterator<String> parts = Models.getParts(part.get());
              if(parts.hasNext())
              {
                  String name = parts.next();
                  // only interested in the root level
                  if(!parts.hasNext() && hidden.contains(name))
                  {
                      return value;
                  }
              }
          }
          return Optional.absent();
      }
 
Example 5
Source File: RelCollationImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
public int compareTo(@Nonnull RelMultipleTrait o) {
  final RelCollationImpl that = (RelCollationImpl) o;
  final UnmodifiableIterator<RelFieldCollation> iterator =
      that.fieldCollations.iterator();
  for (RelFieldCollation f : fieldCollations) {
    if (!iterator.hasNext()) {
      return 1;
    }
    final RelFieldCollation f2 = iterator.next();
    int c = Utilities.compare(f.getFieldIndex(), f2.getFieldIndex());
    if (c != 0) {
      return c;
    }
  }
  return iterator.hasNext() ? -1 : 0;
}
 
Example 6
Source File: TestTopicTreeImplEdgeCases.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@Test
public void test_add_same_topic_twice_different_qos_more_than_32_subscribers() throws Exception {

    topicTree.addTopic("client1", new Topic("a/b", QoS.EXACTLY_ONCE), (byte) 0, null);
    for (int i = 0; i < 32; i++) {
        topicTree.addTopic("client" + (i + 2), new Topic("a/b", QoS.EXACTLY_ONCE), (byte) 0, null);
    }

    topicTree.addTopic("client1", new Topic("a/b", QoS.AT_LEAST_ONCE), (byte) 0, null);

    final ImmutableSet<SubscriberWithIdentifiers> subscribers = topicTree.getSubscribers("a/b");
    assertEquals(33, subscribers.size());

    assertEquals(33, topicTree.subscriptionCounter.getCount());

    final UnmodifiableIterator<SubscriberWithIdentifiers> subscribersIterator = subscribers.iterator();
    boolean found = false;
    while (subscribersIterator.hasNext()) {
        final SubscriberWithIdentifiers next = subscribersIterator.next();
        if (next.getSubscriber().equals("client1")) {
            found = true;
            assertEquals(1, next.getQos());
        }
    }

    assertTrue(found);
}
 
Example 7
Source File: DocSchemaInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Collection<String> tableNames() {
    // TODO: once we support closing/opening tables change this to concreteIndices()
    // and add  state info to the TableInfo.

    Set<String> tables = new HashSet<>();
    tables.addAll(Collections2.filter(Collections2.transform(
            Arrays.asList(clusterService.state().metaData().concreteAllOpenIndices()), indexToTableName), tablesFilter));

    // Search for partitioned table templates
    UnmodifiableIterator<String> templates = clusterService.state().metaData().getTemplates().keysIt();
    while (templates.hasNext()) {
        String templateName = templates.next();
        if (!PartitionName.isPartition(templateName)) {
            continue;
        }
        try {
            PartitionName partitionName = PartitionName.fromIndexOrTemplate(templateName);
            TableIdent ti = partitionName.tableIdent();
            if (schemaName.equalsIgnoreCase(ti.schema())) {
                tables.add(ti.name());
            }
        } catch (IllegalArgumentException e) {
            // do nothing
        }
    }

    return tables;
}
 
Example 8
Source File: ImmutableCollectionSerializers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final Kryo kryo, final Output output, final ImmutableList<Object> object) {
  output.writeInt(object.size(), true);
  final UnmodifiableIterator iterator = object.iterator();

  while (iterator.hasNext()) {
    final Object value = iterator.next();
    kryo.writeClassAndObject(output, value);
  }
}
 
Example 9
Source File: ImmutableCollectionSerializers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void write(final Kryo kryo, final Output output, final ImmutableSet<Object> object) {
  output.writeInt(object.size(), true);
  final UnmodifiableIterator iterator = object.iterator();

  while (iterator.hasNext()) {
    final Object value = iterator.next();
    kryo.writeClassAndObject(output, value);
  }
}
 
Example 10
Source File: MultiUnifierImpl.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Unifier getAny() {
    UnmodifiableIterator<Unifier> iterator = multiUnifier.iterator();
    if (!iterator.hasNext()){
        throw ReasonerException.nonExistentUnifier();
    }
    return iterator.next();
}
 
Example 11
Source File: MapReadWriteGenerator.java    From parceler with Apache License 2.0 5 votes vote down vote up
@Override
public void generateWriter(JBlock body, JExpression parcel, JVar flags, ASTType type, JExpression getExpression, JDefinedClass parcelableClass, JVar writeIdentitySet) {

    ASTType keyComponentType = astClassFactory.getType(Object.class);
    ASTType valueComponentType = astClassFactory.getType(Object.class);

    if(type.getGenericArgumentTypes().size() == 2){
        UnmodifiableIterator<ASTType> iterator = type.getGenericArgumentTypes().iterator();
        keyComponentType = iterator.next();
        valueComponentType = iterator.next();
    }
    JClass keyType = generationUtil.narrowRef(keyComponentType);
    JClass valueType = generationUtil.narrowRef(valueComponentType);

    JClass inputType = generationUtil.ref(Map.Entry.class).narrow(keyType, valueType);


    JConditional nullConditional = body._if(getExpression.eq(JExpr._null()));
    nullConditional._then().invoke(parcel, "writeInt").arg(JExpr.lit(-1));

    JBlock writeBody = nullConditional._else();

    writeBody.invoke(parcel, "writeInt").arg(getExpression.invoke("size"));

    JForEach forEach = writeBody.forEach(inputType, namer.generateName(inputType), getExpression.invoke("entrySet"));

    ReadWriteGenerator keyGenerator = generators.getGenerator(keyComponentType);
    ReadWriteGenerator valueGenerator = generators.getGenerator(valueComponentType);

    keyGenerator.generateWriter(forEach.body(), parcel, flags, keyComponentType, forEach.var().invoke("getKey"), parcelableClass, writeIdentitySet);
    valueGenerator.generateWriter(forEach.body(), parcel, flags, valueComponentType, forEach.var().invoke("getValue"), parcelableClass, writeIdentitySet);
}
 
Example 12
Source File: EventPoolImpl.java    From neoscada with Eclipse Public License 1.0 4 votes vote down vote up
private void loadFromStorage ()
{
    // load initial set from storage, but restrict it to *daysToRetrieve* days
    try
    {
        final long t = System.currentTimeMillis ();
        // retrieve data per day, to restrict database load
        for ( int daysBack = 1; daysBack <= daysToRetrieve; daysBack++ )
        {
            final Calendar calStart = new GregorianCalendar ();
            final Calendar calEnd = new GregorianCalendar ();
            calStart.setTimeInMillis ( t );
            calStart.add ( Calendar.DAY_OF_YEAR, -daysBack );
            calEnd.setTimeInMillis ( t );
            calEnd.add ( Calendar.DAY_OF_YEAR, -daysBack + 1 );
            final StringBuilder filter = new StringBuilder ();
            filter.append ( "(&" );
            if ( this.filter != null )
            {
                filter.append ( this.filter );
            }
            filter.append ( "(sourceTimestamp>=" + isoDateFormat.format ( calStart.getTime () ) + ")" );
            if ( daysBack > 1 )
            {
                filter.append ( "(sourceTimestamp<" + isoDateFormat.format ( calEnd.getTime () ) + ")" );
            }
            filter.append ( ")" );
            logger.debug ( "load events from filter: " + filter );
            final Query query = this.storage.query ( filter.toString () );
            try
            {
                int count;
                synchronized ( this )
                {
                    count = this.events.getCapacity ();
                }

                final Collection<Event> result = query.getNext ( count );

                logger.debug ( "Loaded {} entries from storage", result.size () );
                synchronized ( this )
                {
                    this.events.addAll ( result );

                    final UnmodifiableIterator<List<Event>> it = Iterators.partition ( this.events.iterator (), chunkSize );
                    while ( it.hasNext () )
                    {
                        final List<org.eclipse.scada.ae.Event> chunk = it.next ();
                        notifyEvent ( chunk );
                    }
                }
            }
            finally
            {
                query.dispose ();
            }
            if ( this.events.size () >= this.events.getCapacity () )
            {
                return;
            }
        }
        logger.debug ( "load of events complete" );
    }
    catch ( final Exception e )
    {
        logger.error ( "loadFromStorage failed", e );
    }
}
 
Example 13
Source File: MapReadWriteGenerator.java    From parceler with Apache License 2.0 4 votes vote down vote up
@Override
public JExpression generateReader(JBlock body, JVar parcelParam, ASTType type, JClass returnJClassRef, JDefinedClass parcelableClass, JVar identity, JVar readIdentityMap) {

    JClass mapImplType = generationUtil.ref(mapType);

    ASTType keyComponentType = astClassFactory.getType(Object.class);
    ASTType valueComponentType = astClassFactory.getType(Object.class);
    JClass keyType = generationUtil.ref(Object.class);
    JClass valueType = generationUtil.ref(Object.class);

    if(type.getGenericArgumentTypes().size() == 2){
        UnmodifiableIterator<ASTType> iterator = type.getGenericArgumentTypes().iterator();
        keyComponentType = iterator.next();
        valueComponentType = iterator.next();
        keyType = generationUtil.narrowRef(keyComponentType);
        valueType = generationUtil.narrowRef(valueComponentType);
        mapImplType = mapImplType.narrow(keyType, valueType);
    }

    JVar sizeVar = body.decl(codeModel.INT, namer.generateName(codeModel.INT), parcelParam.invoke("readInt"));

    JVar outputVar = body.decl(mapImplType, namer.generateName(Map.class));

    JConditional nullInputConditional = body._if(sizeVar.lt(JExpr.lit(0)));

    JBlock nullBody = nullInputConditional._then();

    nullBody.assign(outputVar, JExpr._null());

    JBlock nonNullBody = nullInputConditional._else();

    JInvocation mapConstruction = JExpr._new(mapImplType);
    if(mapInitialCapacityArgument) {
        JExpression initialCapacityExpression;
        if(initialCapacityLoadFactor) {
            initialCapacityExpression = generationUtil.ref(MapsUtil.class).staticInvoke(MapsUtil.INITIAL_HASH_MAP_CAPACITY_METHOD).arg(sizeVar);
        }
        else{
            initialCapacityExpression = sizeVar;
        }
        mapConstruction = mapConstruction.arg(initialCapacityExpression);
    }

    nonNullBody.assign(outputVar, mapConstruction);

    JForLoop forLoop = nonNullBody._for();
    JVar nVar = forLoop.init(codeModel.INT, namer.generateName(codeModel.INT), JExpr.lit(0));
    forLoop.test(nVar.lt(sizeVar));
    forLoop.update(nVar.incr());
    JBlock readLoopBody = forLoop.body();

    ReadWriteGenerator keyGenerator = generators.getGenerator(keyComponentType);
    ReadWriteGenerator valueGenerator = generators.getGenerator(valueComponentType);

    JExpression readKeyExpression = keyGenerator.generateReader(readLoopBody, parcelParam, keyComponentType, generationUtil.ref(keyComponentType), parcelableClass, identity, readIdentityMap);
    JVar keyVar = readLoopBody.decl(keyType, namer.generateName(keyComponentType), readKeyExpression);

    JExpression readValueExpression = valueGenerator.generateReader(readLoopBody, parcelParam, valueComponentType, generationUtil.ref(valueComponentType), parcelableClass, identity, readIdentityMap);
    JVar valueVar = readLoopBody.decl(valueType, namer.generateName(valueComponentType), readValueExpression);

    readLoopBody.invoke(outputVar, "put").arg(keyVar).arg(valueVar);

    return outputVar;
}