com.google.common.collect.UnmodifiableIterator Java Examples

The following examples show how to use com.google.common.collect.UnmodifiableIterator. 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 Project: atlas   Author: alibaba   File: AtlasVirtualFile.java    License: Apache License 2.0 7 votes vote down vote up
protected void fillForMainDexList(Set<DexProgramClass> classes) {
    if (!this.application.mainDexList.isEmpty()) {
        AtlasVirtualFile mainDexFile = (AtlasVirtualFile)this.nameToFileMap.get(0);

        for(UnmodifiableIterator var3 = this.application.mainDexList.iterator(); var3.hasNext(); mainDexFile.commitTransaction()) {
            DexType type = (DexType)var3.next();
            DexClass clazz = this.application.definitionFor(type);
            if (clazz != null && clazz.isProgramClass()) {
                DexProgramClass programClass = (DexProgramClass)clazz;
                mainDexFile.addClass(programClass);
                classes.remove(programClass);
            } else {
                System.out.println("WARNING: Application does not contain `" + type.toSourceString() + "` as referenced in main-dex-list.");
            }
        }

        mainDexFile.throwIfFull(true);
    }

}
 
Example #2
Source Project: Quicksql   Author: Qihoo360   File: RelCollationImpl.java    License: 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 Project: neoscada   Author: eclipse   File: AbstractEventQueryImpl.java    License: 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 Project: Elasticsearch   Author: baidu   File: AliasOrIndex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the unique alias metadata per concrete index.
 *
 * (note that although alias can point to the same concrete indices, each alias reference may have its own routing
 * and filters)
 */
public Iterable<Tuple<String, AliasMetaData>> getConcreteIndexAndAliasMetaDatas() {
    return new Iterable<Tuple<String, AliasMetaData>>() {
        @Override
        public Iterator<Tuple<String, AliasMetaData>> iterator() {
            return new UnmodifiableIterator<Tuple<String,AliasMetaData>>() {

                int index = 0;

                @Override
                public boolean hasNext() {
                    return index < referenceIndexMetaDatas.size();
                }

                @Override
                public Tuple<String, AliasMetaData> next() {
                    IndexMetaData indexMetaData = referenceIndexMetaDatas.get(index++);
                    return new Tuple<>(indexMetaData.getIndex(), indexMetaData.getAliases().get(aliasName));
                }

            };
        }
    };
}
 
Example #5
Source Project: hadoop   Author: naver   File: HostFileManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<InetSocketAddress> iterator() {
  return new UnmodifiableIterator<InetSocketAddress>() {
    private final Iterator<Map.Entry<InetAddress,
            Integer>> it = addrs.entries().iterator();

    @Override
    public boolean hasNext() {
      return it.hasNext();
    }

    @Override
    public InetSocketAddress next() {
      Map.Entry<InetAddress, Integer> e = it.next();
      return new InetSocketAddress(e.getKey(), e.getValue());
    }
  };
}
 
Example #6
Source Project: closure-stylesheets   Author: google   File: CssNode.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This node and the transitive closure of its {@link #parent}s.
 */
public Iterable<CssNode> ancestors() {
  return new Iterable<CssNode>() {
    @Override
    public Iterator<CssNode> iterator() {
      return new UnmodifiableIterator<CssNode>() {

        private CssNode current = CssNode.this;

        @Override
        public boolean hasNext() {
          return current != null;
        }

        @Override
        public CssNode next() {
          CssNode result = current;
          current = current.getParent();
          return result;
        }
      };
    }
  };
}
 
Example #7
Source Project: emodb   Author: bazaarvoice   File: DataStoreJerseyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testListTablesRestricted() {
    final TableOptions options = new TableOptionsBuilder().setPlacement("my:placement").build();
    final ImmutableMap<String, Object> template = ImmutableMap.<String, Object>of("key", "value1");
    final TableAvailability availability = new TableAvailability("my:placement", false);
    final DefaultTable a1 = new DefaultTable("a-table-1", options, template, availability);
    final DefaultTable a2 = new DefaultTable("a-table-2", options, template, availability);
    final DefaultTable b1 = new DefaultTable("b-table-1", options, template, availability);
    final DefaultTable b2 = new DefaultTable("b-table-2", options, template, availability);
    final DefaultTable a3 = new DefaultTable("a-table-3", options, template, availability);
    final ImmutableList<Table> tables = ImmutableList.of(a1, a2, b1, b2, a3);

    final UnmodifiableIterator<Table> iterator = tables.iterator();
    //noinspection unchecked
    when(_server.listTables(null, Long.MAX_VALUE)).thenAnswer(invocation -> iterator);

    {
        final Iterator<Table> tableIterator = sorClient(APIKEY_READ_TABLES_A).listTables(null, 3);
        final ImmutableList<Table> result = ImmutableList.copyOf(tableIterator);
        assertEquals(ImmutableList.<Table>of(a1, a2, a3), result);
    }
    verify(_server, times(1)).listTables(null, Long.MAX_VALUE);
}
 
Example #8
Source Project: Logistics-Pipes-2   Author: SonOfTheStars   File: BlockGenericPipe.java    License: 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 #9
Source Project: james-project   Author: apache   File: MailDelivrerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldReturnPermanentErrorWhenLimitDNSProblemExceeded() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);
    DeliveryRetriesHelper.incrementRetries(mail);

    UnmodifiableIterator<HostAddress> empty = ImmutableList.<HostAddress>of().iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(empty);

    ExecutionResult executionResult = testee.deliver(mail);

    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.PERMANENT_FAILURE);
}
 
Example #10
Source Project: james-project   Author: apache   File: MailDelivrerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldTryTwiceOnIOException() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_1)))
        .thenThrow(new MessagingException("400 : Horrible way to manage Server Return code", new IOException()));
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_2)))
        .thenReturn(ExecutionResult.success());
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.SUCCESS);
}
 
Example #11
Source Project: james-project   Author: apache   File: MailDelivrerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldAttemptDeliveryOnBothMXIfStillRecipients() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();
    Address[] validSent = {};
    Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())};
    Address[] invalid = {};
    SendFailedException sfe = new SendFailedException("Message",
        new Exception(),
        validSent,
        validUnsent,
        invalid);

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class)))
        .thenThrow(sfe);
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE);
}
 
Example #12
Source Project: james-project   Author: apache   File: MailDelivrerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void deliverShouldWorkIfOnlyMX2Valid() throws Exception {
    Mail mail = FakeMail.builder().name("name").recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build();
    Address[] validSent = {};
    Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())};
    Address[] invalid = {};
    SendFailedException sfe = new SendFailedException("Message",
        new Exception(),
        validSent,
        validUnsent,
        invalid);

    UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of(
        HOST_ADDRESS_1,
        HOST_ADDRESS_2).iterator();
    when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_1)))
        .thenThrow(sfe);
    when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(Collection.class), eq(HOST_ADDRESS_2)))
        .thenReturn(ExecutionResult.success());
    ExecutionResult executionResult = testee.deliver(mail);

    verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(Collection.class), any(HostAddress.class));
    assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.SUCCESS);
}
 
Example #13
Source Project: yangtools   Author: opendaylight   File: ImmutableOffsetMap.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public @NonNull Iterator<Entry<K, V>> iterator() {
    final Iterator<Entry<K, Integer>> it = offsets.entrySet().iterator();
    return new UnmodifiableIterator<Entry<K, V>>() {
        @Override
        public boolean hasNext() {
            return it.hasNext();
        }

        @Override
        public Entry<K, V> next() {
            final Entry<K, Integer> e = it.next();
            return new SimpleImmutableEntry<>(e.getKey(), objects[e.getValue()]);
        }
    };
}
 
Example #14
Source Project: yangtools   Author: opendaylight   File: SchemaPath.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the list of nodes which need to be traversed to get from this
 * node to the starting point (root for absolute SchemaPaths).
 *
 * @return list of <code>qname</code> instances which represents
 *         path from the schema node towards the root.
 */
public Iterable<QName> getPathTowardsRoot() {
    return () -> new UnmodifiableIterator<>() {
        private SchemaPath current = SchemaPath.this;

        @Override
        public boolean hasNext() {
            return current.parent != null;
        }

        @Override
        public QName next() {
            if (current.parent != null) {
                final QName ret = current.qname;
                current = current.parent;
                return ret;
            }

            throw new NoSuchElementException("No more elements available");
        }
    };
}
 
Example #15
Source Project: calcite   Author: apache   File: RelCollationImpl.java    License: 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 #16
Source Project: bazel   Author: bazelbuild   File: RangeList.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<Integer> iterator() {
  return new UnmodifiableIterator<Integer>() {
    int cursor = start;

    @Override
    public boolean hasNext() {
      return (step > 0) ? (cursor < stop) : (cursor > stop);
    }

    @Override
    public Integer next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      int current = cursor;
      cursor += step;
      return current;
    }
  };
}
 
Example #17
Source Project: bazel   Author: bazelbuild   File: Bug62456849TestDataGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
  checkArgument(
      args.length == 2,
      "Usage: %s <input-jar> <output-jar>",
      Bug62456849TestDataGenerator.class.getName());
  Path inputJar = Paths.get(args[0]);
  checkArgument(Files.isRegularFile(inputJar), "The input jar %s is not a file", inputJar);
  Path outputJar = Paths.get(args[1]);

  try (ZipFile inputZip = new ZipFile(inputJar.toFile());
      ZipOutputStream outZip =
          new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(outputJar)))) {
    for (UnmodifiableIterator<? extends ZipEntry> it =
            Iterators.forEnumeration(inputZip.entries());
        it.hasNext(); ) {
      ZipEntry entry = it.next();
      String entryName = entry.getName();
      byte[] content =
          entryName.endsWith(".class")
              ? convertClass(inputZip, entry)
              : readEntry(inputZip, entry);
      writeToZipFile(outZip, entryName, content);
    }
  }
}
 
Example #18
Source Project: tez   Author: apache   File: FairShuffleVertexManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<DestinationTaskInputsProperty> iterator() {
  return new UnmodifiableIterator<DestinationTaskInputsProperty>() {
    private int j = 0;
    private boolean visitedAtLeastOnce = false;
    private int groupIndex = 0;

    // Get number of source tasks in the current group.
    private int getNumOfSourceTasks() {
      return groupIndex++ < numOfBaseDestinationTasks ?
          numOfBaseSourceTasks : numOfBaseSourceTasks + 1;
    }

    @Override
    public boolean hasNext() {
      return j < sourceVertexInfo.numTasks || !visitedAtLeastOnce;
    }

    @Override
    public DestinationTaskInputsProperty next() {
      if (hasNext()) {
        visitedAtLeastOnce = true;
        int start = j;
        int numOfSourceTasks = getNumOfSourceTasks();
        j += numOfSourceTasks;
        return new DestinationTaskInputsProperty(firstPartitionId,
            numOfPartitions, start, numOfSourceTasks);
      }
      throw new NoSuchElementException();
    }
  };
}
 
Example #19
Source Project: hivemq-community-edition   Author: hivemq   File: TestTopicTreeImplEdgeCases.java    License: 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 #20
Source Project: ghidra   Author: NationalSecurityAgency   File: FilterVerticesJob.java    License: Apache License 2.0 5 votes vote down vote up
private Set<V> findCurrentVerticesFailingTheFilter(Set<V> validVertices) {

		UnmodifiableIterator<V> nonMatchingIterator =
			Iterators.filter(filterGraph.getUnfilteredVertices(), v -> !validVertices.contains(v));
		Set<V> nonMatching = asSet(nonMatchingIterator);
		return nonMatching;
	}
 
Example #21
Source Project: cloud-opensource-java   Author: GoogleCloudPlatform   File: ClassPathResultTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetClassPathEntries() {
  ImmutableListMultimap<ClassPathEntry, DependencyPath> tree =
      ImmutableListMultimap.of(
          jarA, dependencyPath_A,
          jarB, dependencyPath_B,
          jarA, dependencyPath_A_B_A);

  ClassPathResult result = new ClassPathResult(tree, ImmutableSet.of());

  ImmutableSet<ClassPathEntry> classPathEntries = result.getClassPathEntries("com.google:a:1");
  assertEquals(1, classPathEntries.size());
  UnmodifiableIterator<ClassPathEntry> iterator = classPathEntries.iterator();
  assertEquals(Paths.get("a.jar"), iterator.next().getJar());
}
 
Example #22
Source Project: Elasticsearch   Author: baidu   File: DocSchemaInfo.java    License: 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 #23
Source Project: Elasticsearch   Author: baidu   File: FieldNamesFieldMapper.java    License: Apache License 2.0 5 votes vote down vote up
static Iterable<String> extractFieldNames(final String fullPath) {
    return new Iterable<String>() {
        @Override
        public Iterator<String> iterator() {
            return new UnmodifiableIterator<String>() {

                int endIndex = nextEndIndex(0);

                private int nextEndIndex(int index) {
                    while (index < fullPath.length() && fullPath.charAt(index) != '.') {
                        index += 1;
                    }
                    return index;
                }

                @Override
                public boolean hasNext() {
                    return endIndex <= fullPath.length();
                }

                @Override
                public String next() {
                    final String result = fullPath.substring(0, endIndex);
                    endIndex = nextEndIndex(endIndex + 1);
                    return result;
                }

            };
        }
    };
}
 
Example #24
Source Project: Elasticsearch   Author: baidu   File: ImmutableOpenIntMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a direct iterator over the keys.
 */
public UnmodifiableIterator<Integer> keysIt() {
    final Iterator<IntCursor> iterator = map.keys().iterator();
    return new UnmodifiableIterator<Integer>() {
        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public Integer next() {
            return iterator.next().value;
        }
    };
}
 
Example #25
Source Project: Elasticsearch   Author: baidu   File: ImmutableOpenIntMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a direct iterator over the keys.
 */
public UnmodifiableIterator<VType> valuesIt() {
    final Iterator<ObjectCursor<VType>> iterator = map.values().iterator();
    return new UnmodifiableIterator<VType>() {
        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public VType next() {
            return iterator.next().value;
        }
    };
}
 
Example #26
Source Project: Elasticsearch   Author: baidu   File: ImmutableOpenMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a direct iterator over the keys.
 */
public UnmodifiableIterator<KType> keysIt() {
    final Iterator<ObjectCursor<KType>> iterator = map.keys().iterator();
    return new UnmodifiableIterator<KType>() {
        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public KType next() {
            return iterator.next().value;
        }
    };
}
 
Example #27
Source Project: Elasticsearch   Author: baidu   File: ImmutableOpenMap.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a direct iterator over the keys.
 */
public UnmodifiableIterator<VType> valuesIt() {
    final Iterator<ObjectCursor<VType>> iterator = map.values().iterator();
    return new UnmodifiableIterator<VType>() {
        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public VType next() {
            return iterator.next().value;
        }
    };
}
 
Example #28
Source Project: OpenModsLib   Author: OpenMods   File: BitMapUtils.java    License: MIT License 5 votes vote down vote up
public static <T> Iterator<Map.Entry<T, Boolean>> createFlagIterator(final IReadableBitMap<T> map, final Iterator<T> values) {
	return new UnmodifiableIterator<Map.Entry<T, Boolean>>() {
		@Override
		public boolean hasNext() {
			return values.hasNext();
		}

		@Override
		public Entry<T, Boolean> next() {
			final T key = values.next();
			final boolean value = map.get(key);
			return Maps.immutableEntry(key, value);
		}
	};
}
 
Example #29
Source Project: dremio-oss   Author: dremio   File: ImmutableCollectionSerializers.java    License: 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 #30
Source Project: grakn   Author: graknlabs   File: MultiUnifierImpl.java    License: 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();
}