com.google.common.collect.Iterables#removeIf ( )源码实例Demo

下面列出了com.google.common.collect.Iterables#removeIf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: emodb   文件: DefaultClaimSet.java
private void removeEmptyExpirationQueues() {
    // Periodically go through and remove empty expiration queues so they don't accumulate forever.
    // This cleans up queues with really long TTLs where every member was explicitly removed.
    Iterables.removeIf(_expirationQueues.values(), new Predicate<LinkedHashSet<Claim>>() {
        @Override
        public boolean apply(LinkedHashSet<Claim> queue) {
            return queue.isEmpty();
        }
    });
    Iterables.removeIf(_schedule, new Predicate<ProcessAt>() {
        @Override
        public boolean apply(ProcessAt processAt) {
            return processAt.getQueue().isEmpty();
        }
    });
    checkState(_schedule.size() == _expirationQueues.size());
}
 
源代码2 项目: Ratel   文件: InMemoryDiscoveryServer.java
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@Scheduled(fixedRate = MINUTE)
public void checkActiveServices() {
    for (final Map.Entry<ServiceDescriptor, Long> entry : pingedServers.entrySet()) {
        if (isActive(entry.getValue())) {

            LOGGER.info("Removing services with address {}", entry.getKey());
            Iterables.removeIf(services, new Predicate<ServiceDescriptor>() {
                @Override
                public boolean apply(ServiceDescriptor service) {
                    return service.equals(entry.getKey());
                }
            });
            pingedServers.remove(entry.getKey());
        }
    }
    gaugeService.submit("registered.services.count", services.size());
    gaugeService.submit("registered.servers.count", pingedServers.size());
}
 
@Override
public void filterRowCells(List<Cell> kvs) throws IOException {
    if (kvs.isEmpty()) return;
    Cell firstKV = kvs.get(0);
    Iterables.removeIf(kvs, new Predicate<Cell>() {
        @Override
        public boolean apply(Cell kv) {
            int qualifier = encodingScheme.decode(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength());
            return !trackedColumns.get(qualifier);
        }
    });
    if (kvs.isEmpty()) {
        kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(), firstKV.getRowLength(),
                this.emptyCFName, 0, this.emptyCFName.length, ENCODED_EMPTY_COLUMN_BYTES, 0,
                ENCODED_EMPTY_COLUMN_BYTES.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0));
    }
}
 
源代码4 项目: jstarcraft-nlp   文件: LanguageProfileValidator.java
/**
 * Remove potential LanguageProfiles, e.g. in combination with {@link #loadAllBuiltInLanguageProfiles()}.
 * 
 * @param isoString the ISO string of the LanguageProfile to be removed.
 */
public LanguageProfileValidator removeLanguageProfile(final String isoString) {
    Iterables.removeIf(this.languageProfiles, new Predicate<LanguageProfile>() {
        @Override
        public boolean apply(LanguageProfile languageProfile) {
            return languageProfile.getLocale().getLanguage().equals(isoString);
        }
    });
    return this;
}
 
源代码5 项目: tutorials   文件: JavaCollectionCleanupUnitTest.java
@Test
public final void givenListContainsNulls_whenRemovingNullsWithGuavaV1_thenCorrect() {
    final List<Integer> list = Lists.newArrayList(null, 1, null);
    Iterables.removeIf(list, Predicates.isNull());

    assertThat(list, hasSize(1));
}
 
private Map<String, String> getContextMap(String processId, Request request) {
  Map<String, String> contextMap = (Map) request.getContext();
  ProjectLogger.log(
      "UserBulkMigrationActor:getContextMap:started preparing record for processId:"
          + processId
          + "with request context:"
          + contextMap,
      LoggerEnum.INFO.name());
  contextMap.put(JsonKey.ACTOR_TYPE, StringUtils.capitalize(JsonKey.SYSTEM));
  contextMap.put(JsonKey.ACTOR_ID, ProjectUtil.getUniqueIdFromTimestamp(0));
  Iterables.removeIf(contextMap.values(), value -> StringUtils.isBlank(value));
  return contextMap;
}
 
源代码7 项目: attic-aurora   文件: Iterables2Test.java
@Test
@SuppressWarnings("unchecked") // Needed because type information lost in vargs.
public void testZipRemove() {
  final int DEFAULT = 10;
  Iterable<List<Integer>> meta = Iterables2.zip(DEFAULT,
      list(1, 2, 3, 4),
      list(5, 6, 7, 8),
      list(9));

  // Attempt to trim all rows that have the default value.
  Iterables.removeIf(meta, input -> Iterables.contains(input, DEFAULT));

  assertValues(meta, list(1, 5, 9));
}
 
源代码8 项目: emodb   文件: DefaultClaimStore.java
/**
 * Cleans up old claim sets for subscriptions that have become inactive.  Ensures the map of claim sets doesn't
 * grow forever.
 */
private synchronized void removeEmptyClaimSets() {
    Iterables.removeIf(_map.values(), new Predicate<Handle>() {
        @Override
        public boolean apply(Handle handle) {
            handle.getClaimSet().pump();
            return handle.getRefCount().get() == 0 && handle.getClaimSet().size() == 0;
        }
    });
}
 
源代码9 项目: java_in_examples   文件: JavaTransformTest.java
private static void removeTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // remove if
    jdk.removeIf((s) -> s.contains("1")); // using jdk
    Iterables.removeIf(guava, (s) -> s.contains("1")); // using guava
    CollectionUtils.filter(apache, (s) -> !s.contains("1")); // using apache
    gs.removeIf((Predicate<String>) (s) -> s.contains("1"));  // using gs

    System.out.println("removeIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print removeIf = [a2, a3]:[a2, a3]:[a2, a3]:[a2, a3]
}
 
源代码10 项目: java_in_examples   文件: JavaTransformTest.java
private static void retainTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // remove if not
    jdk.removeIf((s) -> !s.contains("1")); // using jdk
    Iterables.removeIf(guava, (s) -> !s.contains("1")); // using guava
    CollectionUtils.filter(apache, (s) -> s.contains("1")); // using apache
    gs.removeIf((Predicate<String>) (s) -> !s.contains("1"));  //using gs

    System.out.println("retainIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print retainIf = [a1, a1]:[a1, a1]:[a1, a1]:[a1, a1]
}
 
源代码11 项目: java_in_examples   文件: JavaTransformTest.java
private static void removeTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // удаление по условию
    jdk.removeIf((s) -> s.contains("1")); // с помощью jdk
    Iterables.removeIf(guava, (s) -> s.contains("1")); // с помощью guava
    CollectionUtils.filter(apache, (s) -> !s.contains("1")); // с помощью apache
    gs.removeIf((Predicate<String>) (s) -> s.contains("1"));  // с помощью gs

    System.out.println("removeIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает removeIf = [a2, a3]:[a2, a3]:[a2, a3]:[a2, a3]
}
 
源代码12 项目: java_in_examples   文件: JavaTransformTest.java
private static void retainTest() {
    Collection<String> jdk = Lists.newArrayList("a1", "a2", "a3", "a1");
    Iterable<String> guava = Lists.newArrayList(jdk);
    Iterable<String> apache = Lists.newArrayList(jdk);
    MutableCollection<String> gs = FastList.newList(jdk);

    // удаление всех не равных условию
    jdk.removeIf((s) -> !s.contains("1")); // с помощью jdk
    Iterables.removeIf(guava, (s) -> !s.contains("1")); // с помощью guava
    CollectionUtils.filter(apache, (s) -> s.contains("1")); // с помощью apache
    gs.removeIf((Predicate<String>) (s) -> !s.contains("1"));  //с помощью gs

    System.out.println("retainIf = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает retainIf = [a1, a1]:[a1, a1]:[a1, a1]:[a1, a1]
}
 
源代码13 项目: Kylin   文件: ProjectInstance.java
public void removeRealization(final RealizationType type, final String realization) {
    Iterables.removeIf(this.realizationEntries, new Predicate<RealizationEntry>() {
        @Override
        public boolean apply(RealizationEntry input) {
            return input.getType() == type && input.getRealization().equalsIgnoreCase(realization);
        }
    });
}
 
/**
 * Remove potential LanguageProfiles, e.g. in combination with {@link #loadAllBuiltInLanguageProfiles()}.
 * @param isoString the ISO string of the LanguageProfile to be removed.
 */
public LanguageProfileValidator removeLanguageProfile(final String isoString) {
    Iterables.removeIf(this.languageProfiles, new Predicate<LanguageProfile>() {
        @Override
        public boolean apply(LanguageProfile languageProfile) {
            return languageProfile.getLocale().getLanguage().equals(isoString);
        }
    });
    return this;
}
 
源代码15 项目: phoenix   文件: ColumnProjectionFilter.java
@Override
public void filterRowCells(List<Cell> kvs) throws IOException {
    if (kvs.isEmpty()) return;
    Cell firstKV = kvs.get(0);
    Iterables.removeIf(kvs, new Predicate<Cell>() {
        @Override
        public boolean apply(Cell kv) {
            ptr.set(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength());
            if (columnsTracker.containsKey(ptr)) {
                Set<ImmutableBytesPtr> cols = columnsTracker.get(ptr);
                ptr.set(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength());
                if (cols != null && !(cols.contains(ptr))) {
                    return true;
                }
            } else {
                return true;
            }
            return false;
        }
    });
    // make sure we're not holding to any of the byte[]'s
    ptr.set(HConstants.EMPTY_BYTE_ARRAY);
    if (kvs.isEmpty()) {
        kvs.add(new KeyValue(firstKV.getRowArray(), firstKV.getRowOffset(), firstKV.getRowLength(),
                this.emptyCFName, 0, this.emptyCFName.length, emptyKVQualifier, 0,
                emptyKVQualifier.length, HConstants.LATEST_TIMESTAMP, Type.Maximum, null, 0, 0));
    }
}
 
源代码16 项目: j2cl   文件: JsInteropRestrictionsChecker.java
private static void addMember(
    Multimap<String, MemberDescriptor> memberByMemberName, MemberDescriptor member) {
  String name = member.getSimpleJsName();
  Iterables.removeIf(memberByMemberName.get(name), m -> overrides(member, m));
  memberByMemberName.put(name, member);
}
 
private void filterProposals(List<ICompletionProposal> proposals) {
    Iterables.removeIf(proposals, not(validProposal()));
}
 
源代码18 项目: bonita-studio   文件: GenericProposalFilter.java
private void filterProposals(List<IGroovyProposal> proposals) {
    Iterables.removeIf(proposals, not(validProposal()));
}
 
源代码19 项目: immutables   文件: Output.java
private void removeBlankLinesIn(Iterable<String> services) {
  Iterables.removeIf(services, Predicates.equalTo(""));
}
 
源代码20 项目: incubator-gobblin   文件: JobListeners.java
/**
 * Chains a given {@link List} of {@link JobListener}s into a single {@link JobListener}. The specified {@link JobListener}s
 * will all be executed in parallel.
 *
 * @param jobListeners is a {@link List} of {@link JobListener}s that need to be executed
 *
 * @return a {@link CloseableJobListener}, which is similar to {@link JobListener}, except
 * {@link CloseableJobListener#close()} will block until all {@link JobListener}s have finished their executions.
 */
public static CloseableJobListener parallelJobListener(List<JobListener> jobListeners) {
  Iterables.removeIf(jobListeners, Predicates.isNull());
  return new ParallelJobListener(jobListeners);
}