Java Code Examples for com.google.common.collect.Iterables#removeIf()

The following examples show how to use com.google.common.collect.Iterables#removeIf() . These examples are extracted from open source projects. 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: emodb   File: DefaultClaimSet.java    License: Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 2
Source Project: Ratel   File: InMemoryDiscoveryServer.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
@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));
    }
}
 
Example 4
/**
 * 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;
}
 
Example 5
@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));
}
 
Example 6
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;
}
 
Example 7
Source Project: attic-aurora   File: Iterables2Test.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 8
Source Project: emodb   File: DefaultClaimStore.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 9
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]
}
 
Example 10
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]
}
 
Example 11
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]
}
 
Example 12
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]
}
 
Example 13
Source Project: Kylin   File: ProjectInstance.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    });
}
 
Example 14
/**
 * 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;
}
 
Example 15
Source Project: phoenix   File: ColumnProjectionFilter.java    License: Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example 16
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);
}
 
Example 17
private void filterProposals(List<ICompletionProposal> proposals) {
    Iterables.removeIf(proposals, not(validProposal()));
}
 
Example 18
private void filterProposals(List<IGroovyProposal> proposals) {
    Iterables.removeIf(proposals, not(validProposal()));
}
 
Example 19
Source Project: immutables   File: Output.java    License: Apache License 2.0 4 votes vote down vote up
private void removeBlankLinesIn(Iterable<String> services) {
  Iterables.removeIf(services, Predicates.equalTo(""));
}
 
Example 20
Source Project: incubator-gobblin   File: JobListeners.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}