com.google.common.collect.Sets#filter ( )源码实例Demo

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

源代码1 项目: bistoury   文件: ImportCollector.java
private List<String> packImports() {

        /*return mapSimpleNames.entrySet().stream()
                .filter(ent ->
                        // exclude the current class or one of the nested ones
                        // empty, java.lang and the current packages
                        !setNotImportedNames.contains(ent.getKey()) &&
                                !ent.getValue().isEmpty() &&
                                !JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
                                !ent.getValue().equals(currentPackagePoint)
                )
                .sorted(Map.Entry.<String, String>comparingByValue().thenComparing(Map.Entry.comparingByKey()))
                .map(ent -> ent.getValue() + "." + ent.getKey())
                .collect(Collectors.toList());*/
        HashSet<Map.Entry<String, String>> set = Sets.newHashSet(mapSimpleNames.entrySet());
        Sets.filter(set, new Predicate<Map.Entry<String, String>>() {
            @Override
            public boolean apply(Map.Entry<String, String> ent) {
                return !setNotImportedNames.contains(ent.getKey()) &&
                        !ent.getValue().isEmpty() &&
                        !JAVA_LANG_PACKAGE.equals(ent.getValue()) &&
                        !ent.getValue().equals(currentPackagePoint);
            }
        });
        ArrayList<Map.Entry<String, String>> list = Lists.newArrayList(set);
        Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
            @Override
            public int compare(Map.Entry<String, String> c1, Map.Entry<String, String> c2) {
                int res = c1.getValue().compareTo(c2.getValue());
                return (res != 0) ? res : c1.getKey().compareTo(c2.getKey());
            }
        });
        List<String> result = Lists.newArrayList();
        for (Map.Entry<String, String> entry : list) {
            result.add(entry.getValue() + "." + entry.getKey());
        }
        return result;
    }
 
源代码2 项目: codebuff   文件: Graphs.java
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */
public static <N, E> void mergeEdgesFrom(
    Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
源代码3 项目: codebuff   文件: Graphs.java
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */


public static <N, E> void mergeEdgesFrom(Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
源代码4 项目: codebuff   文件: Graphs.java
/**
 * Copies all nodes from {@code original} into {@code copy} that satisfy {@code nodePredicate}.
 */


public static <N, E> void mergeNodesFrom(Graph<N> original, MutableGraph<N> copy, Predicate<? super N> nodePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(nodePredicate, "nodePredicate");
  for (N node : Sets.filter(original.nodes(), nodePredicate)) {
    copy.addNode(node);
  }
}
 
源代码5 项目: codebuff   文件: Graphs.java
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */


public static <N, E> void mergeEdgesFrom(Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
源代码7 项目: codebuff   文件: Graphs.java
/**
 * Copies all nodes from {@code original} into {@code copy} that satisfy {@code nodePredicate}.
 */


public static <N, E> void mergeNodesFrom(Graph<N> original, MutableGraph<N> copy, Predicate<? super N> nodePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(nodePredicate, "nodePredicate");
  for (N node : Sets.filter(original.nodes(), nodePredicate)) {
    copy.addNode(node);
  }
}
 
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
源代码10 项目: registry   文件: HdfsFileStorage.java
@Override
public void init(Map<String, String> config) throws IOException {
    String fsUrl = config.get(CONFIG_FSURL);
    String kerberosPrincipal = config.get(CONFIG_KERBEROS_PRINCIPAL);
    String keytabLocation = config.get(CONFIG_KERBEROS_KEYTAB);
    directory = config.getOrDefault(CONFIG_DIRECTORY, DEFAULT_DIR);

    hdfsConfig = new Configuration();

    for(Map.Entry<String, String> entry:
            Sets.filter(config.entrySet(), e -> !OWN_CONFIGS.contains(e.getKey()))) {
        hdfsConfig.set(entry.getKey(), entry.getValue());
    }

    // make sure fsUrl is set
    Preconditions.checkArgument(fsUrl != null, "fsUrl must be specified for HdfsFileStorage.");

    Preconditions.checkArgument(keytabLocation != null || kerberosPrincipal == null,
        "%s is needed when %s (== %s) is specified.",
        CONFIG_KERBEROS_KEYTAB, CONFIG_KERBEROS_PRINCIPAL, kerberosPrincipal);

    Preconditions.checkArgument(kerberosPrincipal != null || keytabLocation == null,
        "%s is needed when %s (== %s) is specified.",
        CONFIG_KERBEROS_PRINCIPAL, CONFIG_KERBEROS_KEYTAB, keytabLocation);

    if (kerberosPrincipal != null) {
        LOG.info("Logging in as kerberos principal {}", kerberosPrincipal);
        UserGroupInformation.loginUserFromKeytab(kerberosPrincipal, keytabLocation);
        kerberosEnabled = true;
    }

    directory = adjustDirectory(fsUrl, directory);
    fsUri = URI.create(fsUrl);

    LOG.info("Initialized with fsUrl={}, directory={}, kerberos principal={}", fsUrl, directory, kerberosPrincipal);
}
 
源代码11 项目: vscrawler   文件: RamScoredQueueStore.java
@Override
public Set<String> notExisted(String queueID, Set<String> resourceItemKeys) {
    final Map<String, ResourceItem> maps = createOrGet(queueID).maps;
    return Sets.filter(resourceItemKeys, new Predicate<String>() {
        @Override
        public boolean apply(String input) {
            return !maps.containsKey(input);
        }
    });
}
 
源代码12 项目: codebuff   文件: Graphs.java
/**
 * Copies all edges from {@code original} into {@code copy} that satisfy {@code edgePredicate}.
 * Also copies all nodes incident to these edges.
 */


public static <N, E> void mergeEdgesFrom(Network<N, E> original, MutableNetwork<N, E> copy, Predicate<? super E> edgePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(edgePredicate, "edgePredicate");
  for (E edge : Sets.filter(original.edges(), edgePredicate)) {
    addEdge(copy, edge, original.incidentNodes(edge));
  }
}
 
源代码13 项目: vscrawler   文件: JedisSegmentScoredQueueStore.java
@Override
public void addBatch(String queueID, Set<ResourceItem> resourceItems) {
    if (!lockQueue(queueID)) {
        return;
    }
    @Cleanup Jedis jedis = jedisPool.getResource();
    final String dataKey = makeDataKey(queueID);
    try {
        final Set<String> hkeys = jedis.hkeys(dataKey);
        Set<ResourceItem> filterSet = Sets.filter(resourceItems, new Predicate<ResourceItem>() {
            @Override
            public boolean apply(ResourceItem input) {
                return !hkeys.contains(input.getKey());
            }
        });
        List<String> sliceQueue = sliceQueue(queueID);
        Set<String> newSlices = Sets.newHashSet();
        long index = size(queueID) + 1;
        String tailSlice = null;
        for (ResourceItem resourceItem : filterSet) {
            jedis.hset(dataKey, resourceItem.getKey(), JSONObject.toJSONString(resourceItem));
            String sliceID = String.valueOf(blockID(index));
            if (sliceID.equals(tailSlice) || sliceQueue.contains(sliceID)) {
                sliceID = sliceQueue.get(sliceQueue.size() - 1);
                tailSlice = sliceID;
            } else if (!newSlices.contains(sliceID)) {
                jedis.rpush(makeSliceQueueKey(queueID), sliceID);
                newSlices.add(sliceID);
            }
            jedis.rpush(makePoolQueueKey(queueID, sliceID), resourceItem.getKey());
            index++;
        }
    } finally {
        unLockQueue(queueID);
    }
}
 
源代码14 项目: codebuff   文件: Graphs.java
/**
 * Copies all nodes from {@code original} into {@code copy} that satisfy {@code nodePredicate}.
 */


public static <N, E> void mergeNodesFrom(Graph<N> original, MutableGraph<N> copy, Predicate<? super N> nodePredicate) {
  checkNotNull(original, "original");
  checkNotNull(copy, "copy");
  checkNotNull(nodePredicate, "nodePredicate");
  for (N node : Sets.filter(original.nodes(), nodePredicate)) {
    copy.addNode(node);
  }
}
 
private SortedSet<byte[]> filterDeletedTableRegions(final Set<TableName> existingTables,
                                                    SortedSet<byte[]> transactionalRegions) {
  return Sets.filter(transactionalRegions,
                     new Predicate<byte[]>() {
                       @Override
                       public boolean apply(byte[] region) {
                         return existingTables.contains(HRegionInfo.getTable(region));
                       }
                     });
}
 
源代码16 项目: ProjectAres   文件: TypeMap.java
/**
 * Return all keys within the given bounds
 */
public Set<TypeToken<? extends K>> keysAssignableTo(TypeToken<? extends K> bounds) {
    return Sets.filter(keySet(), bounds::isAssignableFrom);
}
 
源代码17 项目: ProjectAres   文件: TypeMap.java
/**
 * Return all keys that bound the given type
 */
public Set<TypeToken<? extends K>> keysAssignableFrom(TypeToken<? extends K> type) {
    return Sets.filter(keySet(), bounds -> bounds.isAssignableFrom(type));
}
 
源代码18 项目: caffeine   文件: CacheGenerator.java
/** Returns the Cartesian set of the possible cache configurations. */
@SuppressWarnings("unchecked")
private Set<List<Object>> combinations() {
  Set<Boolean> asyncLoading = ImmutableSet.of(true, false);
  Set<Stats> statistics = filterTypes(options.stats(), cacheSpec.stats());
  Set<ReferenceType> keys = filterTypes(options.keys(), cacheSpec.keys());
  Set<ReferenceType> values = filterTypes(options.values(), cacheSpec.values());
  Set<Compute> computations = filterTypes(options.compute(), cacheSpec.compute());
  Set<Implementation> implementations = filterTypes(
      options.implementation(), cacheSpec.implementation());

  if (isAsyncOnly) {
    values = values.contains(ReferenceType.STRONG)
        ? ImmutableSet.of(ReferenceType.STRONG)
        : ImmutableSet.of();
    computations = Sets.filter(computations, Compute.ASYNC::equals);
  }
  if (isAsyncOnly || computations.equals(ImmutableSet.of(Compute.ASYNC))) {
    implementations = implementations.contains(Implementation.Caffeine)
        ? ImmutableSet.of(Implementation.Caffeine)
        : ImmutableSet.of();
  }
  if (computations.equals(ImmutableSet.of(Compute.SYNC))) {
    asyncLoading = ImmutableSet.of(false);
  }

  if (computations.isEmpty() || implementations.isEmpty() || keys.isEmpty() || values.isEmpty()) {
    return ImmutableSet.of();
  }
  return Sets.cartesianProduct(
      ImmutableSet.copyOf(cacheSpec.initialCapacity()),
      ImmutableSet.copyOf(statistics),
      ImmutableSet.copyOf(cacheSpec.weigher()),
      ImmutableSet.copyOf(cacheSpec.maximumSize()),
      ImmutableSet.copyOf(cacheSpec.expiry()),
      ImmutableSet.copyOf(cacheSpec.expireAfterAccess()),
      ImmutableSet.copyOf(cacheSpec.expireAfterWrite()),
      ImmutableSet.copyOf(cacheSpec.refreshAfterWrite()),
      ImmutableSet.copyOf(cacheSpec.advanceOnPopulation()),
      ImmutableSet.copyOf(keys),
      ImmutableSet.copyOf(values),
      ImmutableSet.copyOf(cacheSpec.executor()),
      ImmutableSet.copyOf(cacheSpec.scheduler()),
      ImmutableSet.copyOf(cacheSpec.removalListener()),
      ImmutableSet.copyOf(cacheSpec.population()),
      ImmutableSet.of(true, isLoadingOnly),
      ImmutableSet.copyOf(asyncLoading),
      ImmutableSet.copyOf(computations),
      ImmutableSet.copyOf(cacheSpec.loader()),
      ImmutableSet.copyOf(cacheSpec.writer()),
      ImmutableSet.copyOf(implementations));
}
 
源代码19 项目: arctic-sea   文件: Activatables.java
public static <K, T> Set<K> activatedKeys(Map<K, T> map, ActivationProvider<? super K> provider) {
    return Sets.filter(map.keySet(), provider::isActive);
}
 
源代码20 项目: FreeBuilder   文件: RoundEnvironments.java
/**
 * Sanitizes the result of {@link RoundEnvironment#getElementsAnnotatedWith}, which otherwise
 * can contain elements annotated with annotations of ERROR type.
 *
 * <p>The canonical example is forgetting to import &#64;Nullable.
 */
public static Set<? extends Element> annotatedElementsIn(
    RoundEnvironment roundEnv, Class<? extends Annotation> a) {
  return Sets.filter(roundEnv.getElementsAnnotatedWith(a),
      element -> element.getAnnotation(a) != null);
}