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

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

源代码1 项目: pulsar   文件: PersistentTopic.java
public void startReplProducers() {
    // read repl-cluster from policies to avoid restart of replicator which are in process of disconnect and close
    try {
        Policies policies = brokerService.pulsar().getConfigurationCache().policiesCache()
                .get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace()))
                .orElseThrow(() -> new KeeperException.NoNodeException());
        if (policies.replication_clusters != null) {
            Set<String> configuredClusters = Sets.newTreeSet(policies.replication_clusters);
            replicators.forEach((region, replicator) -> {
                if (configuredClusters.contains(region)) {
                    replicator.startProducer();
                }
            });
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("[{}] Error getting policies while starting repl-producers {}", topic, e.getMessage());
        }
        replicators.forEach((region, replicator) -> replicator.startProducer());
    }
}
 
private List<ConsumerProvidedTaskSelector> buildRecursively(GradleProject project) {
    Multimap<String, String> aggregatedTasks = ArrayListMultimap.create();

    collectTasks(project, aggregatedTasks);

    List<ConsumerProvidedTaskSelector> selectors = Lists.newArrayList();
    for (String selectorName : aggregatedTasks.keySet()) {
        SortedSet<String> selectorTasks = Sets.newTreeSet(new TaskNameComparator());
        selectorTasks.addAll(aggregatedTasks.get(selectorName));
        selectors.add(new ConsumerProvidedTaskSelector().
                setName(selectorName).
                setTaskNames(selectorTasks).
                setDescription(project.getParent() != null
                        ? String.format("%s:%s task selector", project.getPath(), selectorName)
                        : String.format("%s task selector", selectorName)).
                setDisplayName(String.format("%s in %s and subprojects.", selectorName, project.getName())));
    }
    return selectors;
}
 
源代码3 项目: tajo   文件: QueryManager.java
@Deprecated
public Collection<QueryInfo> getFinishedQueries() {
  Set<QueryInfo> result = Sets.newTreeSet();

  synchronized (historyCache) {
    result.addAll(historyCache.values());
  }

  try {
    result.addAll(this.masterContext.getHistoryReader().getQueriesInHistory());
    return result;
  } catch (Throwable e) {
    LOG.error(e, e);
    return result;
  }
}
 
源代码4 项目: astor   文件: RuntimeTypeCheck.java
/**
 * Creates a function call to check that the given expression matches the
 * given type at runtime.
 *
 * <p>For example, if the type is {@code (string|Foo)}, the function call is
 * {@code checkType(expr, [valueChecker('string'), classChecker('Foo')])}.
 *
 * @return the function call node or {@code null} if the type is not checked
 */
private Node createCheckTypeCallNode(JSType type, Node expr) {
  Node arrayNode = IR.arraylit();
  Collection<JSType> alternates;
  if (type.isUnionType()) {
    alternates = Sets.newTreeSet(ALPHA);
    Iterables.addAll(alternates, type.toMaybeUnionType().getAlternates());
  } else {
    alternates = ImmutableList.of(type);
  }
  for (JSType alternate : alternates) {
    Node checkerNode = createCheckerNode(alternate);
    if (checkerNode == null) {
      return null;
    }
    arrayNode.addChildToBack(checkerNode);
  }
  return IR.call(jsCode("checkType"), expr, arrayNode);
}
 
源代码5 项目: havarunner   文件: AfterAllTest.java
@Test
public void HavaRunner_calls_the_After_methods_in_the_test_class_hierarchy() {
    run(new HavaRunner(WorldCreator.class));
    Collection<Long> expectedOrder = Lists.newArrayList(
        universeIsBuilt,
        worldIsBuilt,
        worldIsDestroyed,
        universeIsDestroyed
    );
    Collection<Long> actualOrder = Sets.newTreeSet(Sets.newHashSet(
        checkNotNull(universeIsBuilt),
        checkNotNull(worldIsBuilt),
        checkNotNull(worldIsDestroyed),
        checkNotNull(universeIsDestroyed)
    ));
    assertArrayEquals(expectedOrder.toArray(), actualOrder.toArray());
}
 
private TSentryPrivilegeMap toTSentryPrivilegeMap(Set<MSentryGMPrivilege> mPrivileges) {

    // Mapping of <Role, Set<Privilege>>.
    Map<String, Set<TSentryPrivilege>> tPrivilegeMap = Maps.newTreeMap();

    for (MSentryGMPrivilege mPrivilege : mPrivileges) {
      for (MSentryRole role : mPrivilege.getRoles()) {

        TSentryPrivilege tPrivilege = toTSentryPrivilege(mPrivilege);

        if (tPrivilegeMap.containsKey(role.getRoleName())) {
          tPrivilegeMap.get(role.getRoleName()).add(tPrivilege);
        } else {
          Set<TSentryPrivilege> tPrivilegeSet = Sets.newTreeSet();
          tPrivilegeSet.add(tPrivilege);
          tPrivilegeMap.put(role.getRoleName(), tPrivilegeSet);
        }
      }
    }

    return new TSentryPrivilegeMap(tPrivilegeMap);
  }
 
public synchronized Map<TSentryAuthorizable, TSentryPrivilegeMap> listPrivilegsbyAuthorizable(
    String requestorUserName,
    Set<List<? extends Authorizable>> authorizables, Set<String> groups,
    ActiveRoleSet roleSet) throws SentryUserException {
  Set<TSentryAuthorizable> authSet = Sets.newTreeSet();

  for (List<? extends Authorizable> authorizableHierarchy : authorizables) {
    authSet.add(setupSentryAuthorizable(authorizableHierarchy));
  }
  TListSentryPrivilegesByAuthRequest request = new TListSentryPrivilegesByAuthRequest(
      ThriftConstants.TSENTRY_SERVICE_VERSION_CURRENT, requestorUserName,
      authSet);
  if (groups != null) {
    request.setGroups(groups);
  }
  if (roleSet != null) {
    request.setRoleSet(new TSentryActiveRoleSet(roleSet.isAll(), roleSet.getRoles()));
  }

  try {
    TListSentryPrivilegesByAuthResponse response = client
        .list_sentry_privileges_by_authorizable(request);
    Status.throwIfNotOk(response.getStatus());
    return response.getPrivilegesMapByAuth();
  } catch (TException e) {
    throw new SentryUserException(THRIFT_EXCEPTION_MESSAGE, e);
  }
}
 
源代码8 项目: naturalize   文件: FormattingRenamingsEval.java
public FormattingRenamingsEval.WhitespacePrecisionRecall evaluateFormattingAccuracy(
		final File testFile) throws IOException {
	final char[] fileContent = FileUtils.readFileToString(testFile)
			.toCharArray();
	final List<String> tokens = renamer.tokenizeCode(fileContent);

	final FormattingRenamingsEval.WhitespacePrecisionRecall result = new FormattingRenamingsEval.WhitespacePrecisionRecall();

	for (int i = 0; i < tokens.size(); i++) {
		if (tokens.get(i).startsWith("WS_")) {
			// create all n-grams around i
			final Multiset<NGram<String>> ngrams = renamer.getNGramsAround(
					i, tokens);

			// find all renamings
			final Set<String> alternatives = Sets.newTreeSet(renamer
					.getNgramLM().getTrie().getVocabulary());
			alternatives.add(AbstractNGramLM.UNK_SYMBOL);

			// score accuracy of first suggestion
			final SortedSet<Renaming> suggestions = renamer
					.calculateScores(ngrams, alternatives, null);
			final String actual = tokens.get(i);
			result.addSuggestion(suggestions, actual);
		}
	}
	return result;
}
 
源代码9 项目: hadoop   文件: TestQJMWithFaults.java
/**
 * Run through the creation of a log without any faults injected,
 * and count how many RPCs are made to each node. This sets the
 * bounds for the other test cases, so they can exhaustively explore
 * the space of potential failures.
 */
private static long determineMaxIpcNumber() throws Exception {
  Configuration conf = new Configuration();
  MiniJournalCluster cluster = new MiniJournalCluster.Builder(conf).build();
  QuorumJournalManager qjm = null;
  long ret;
  try {
    qjm = createInjectableQJM(cluster);
    qjm.format(FAKE_NSINFO);
    doWorkload(cluster, qjm);
    
    SortedSet<Integer> ipcCounts = Sets.newTreeSet();
    for (AsyncLogger l : qjm.getLoggerSetForTests().getLoggersForTests()) {
      InvocationCountingChannel ch = (InvocationCountingChannel)l;
      ch.waitForAllPendingCalls();
      ipcCounts.add(ch.getRpcCount());
    }

    // All of the loggers should have sent the same number of RPCs, since there
    // were no failures.
    assertEquals(1, ipcCounts.size());
    
    ret = ipcCounts.first();
    LOG.info("Max IPC count = " + ret);
  } finally {
    IOUtils.closeStream(qjm);
    cluster.shutdown();
  }
  return ret;
}
 
源代码10 项目: newts   文件: CassandraSearcher.java
/**
 * Returns the set of resource ids that match the given
 * boolean query.
 *
 * Separate clauses are performed with separate database queries and their
 * results are joined in memory.
 */
private Set<String> searchForIds(Context context, BooleanQuery query, ConsistencyLevel readConsistency) {
    Set<String> ids = Sets.newTreeSet();

    for (BooleanClause clause : query.getClauses()) {
        Set<String> subQueryIds;

        Query subQuery = clause.getQuery();
        if (subQuery instanceof BooleanQuery) {
            subQueryIds = searchForIds(context, (BooleanQuery)subQuery, readConsistency);
        } else if (subQuery instanceof TermQuery) {
            subQueryIds = searchForIds(context, (TermQuery)subQuery, readConsistency);
        } else {
            throw new IllegalStateException("Unsupported query: " + subQuery);
        }

        switch (clause.getOperator()) {
            case AND: // Intersect
                ids.retainAll(subQueryIds);
                break;
            case OR: // Union
                ids.addAll(subQueryIds);
                break;
            default:
                throw new IllegalStateException("Unsupported operator: " + clause.getOperator());
        }
    }

    return ids;
}
 
源代码11 项目: qpid-broker-j   文件: TransferTest.java
@Test
@SpecificationTest(section = "2.6.12", description = "Transferring A Message.")
public void transferMultipleDeliveries() throws Exception
{
    final String[] contents = Utils.createTestMessageContents(3, getTestName());
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect())
    {
        final Interaction interaction = transport.newInteraction()
                                                 .negotiateOpen()
                                                 .begin().consumeResponse(Begin.class)
                                                 .attachRole(Role.SENDER)
                                                 .attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME)
                                                 .attach().consumeResponse(Attach.class)
                                                 .consumeResponse(Flow.class);
        Flow flow = interaction.getLatestResponse(Flow.class);
        assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(2)));

        interaction.transferDeliveryId(UnsignedInteger.ZERO)
                   .transferDeliveryTag(new Binary("A".getBytes(StandardCharsets.UTF_8)))
                   .transferPayloadData(contents[0])
                   .transfer()
                   .transferDeliveryId(UnsignedInteger.ONE)
                   .transferDeliveryTag(new Binary("B".getBytes(StandardCharsets.UTF_8)))
                   .transferPayloadData(contents[1])
                   .transfer()
                   .transferDeliveryId(UnsignedInteger.valueOf(2))
                   .transferDeliveryTag(new Binary("C".getBytes(StandardCharsets.UTF_8)))
                   .transferPayloadData(contents[2])
                   .transfer();

        TreeSet<UnsignedInteger> expectedDeliveryIds = Sets.newTreeSet(Arrays.asList(UnsignedInteger.ZERO,
                                                                                     UnsignedInteger.ONE,
                                                                                     UnsignedInteger.valueOf(2)));
        assertDeliveries(interaction, expectedDeliveryIds);

        // verify that no unexpected performative is received by closing
        interaction.doCloseConnection();
    }
    assertTestQueueMessages(contents);
}
 
源代码12 项目: quantumdb   文件: Catalog.java
public Catalog(String name) {
	checkArgument(!Strings.isNullOrEmpty(name), "You must specify a 'name'");

	this.name = name;
	this.tables = Sets.newTreeSet(Comparator.comparing(Table::getName));
	this.views = Sets.newTreeSet(Comparator.comparing(View::getName));
	this.sequences = Sets.newTreeSet(Comparator.comparing(Sequence::getName));
}
 
源代码13 项目: emodb   文件: PersistentSortedQueueTest.java
@Test
public void testMixedReadAndWriteWithSplitting() {
    // Reduce the splitting thresholds so that splitting occurs.
    QueueDAO dao = new InMemoryQueueDAO();
    SortedQueue q = new PersistentSortedQueue("queue", false, 1000, 100, dao, new MetricRegistry());
    TreeSet<ByteBuffer> expected = Sets.newTreeSet(ORDERING);

    // Write and read in batches.  Don't verify order since order isn't 100% deterministic when
    // splitting occurs, but do verify no data is lost and no phantom data appears.
    for (int[] constants : new int[][]{{300, 100}, {100, 300}}) {
        for (int i = 0; i < 500; i++) {
            int numWrite = 1 + RANDOM.nextInt(constants[0]);
            int numRead = 1 + RANDOM.nextInt(constants[1]);

            addBuffers(q, expected, numWrite, 100, randomBufferIter(2));

            assertDrain(q, expected, numRead);
        }
    }

    // Verify that scan returns the expected items in the same order.
    assertEquals(q.scan(null, Long.MAX_VALUE), expected.iterator());

    // Verify that drainTo returns the expected items in the same order.
    assertDrain(q, expected, Long.MAX_VALUE);

    assertFalse(q.scan(null, Long.MAX_VALUE).hasNext());
}
 
源代码14 项目: dremio-oss   文件: GlobalDictionaryBuilder.java
private static VectorContainer buildFloatGlobalDictionary(List<Dictionary> dictionaries, VectorContainer existingDict, ColumnDescriptor columnDescriptor, BufferAllocator bufferAllocator) {
  final Field field = new Field(SchemaPath.getCompoundPath(columnDescriptor.getPath()).getAsUnescapedPath(), true, new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), null);
  final VectorContainer input = new VectorContainer(bufferAllocator);
  final Float4Vector floatVector = input.addOrGet(field);
  floatVector.allocateNew();
  SortedSet<Float> values = Sets.newTreeSet();
  for (Dictionary dictionary : dictionaries) {
    for (int i = 0; i <= dictionary.getMaxId(); ++i) {
      values.add(dictionary.decodeToFloat(i));
    }
  }
  if (existingDict != null) {
    final Float4Vector existingDictValues = existingDict.getValueAccessorById(Float4Vector.class, 0).getValueVector();
    for (int i = 0; i < existingDict.getRecordCount(); ++i) {
      values.add(existingDictValues.get(i));
    }
  }
  final Iterator<Float> iter = values.iterator();
  int recordCount = 0;
  while (iter.hasNext()) {
    floatVector.setSafe(recordCount++, iter.next());
  }
  floatVector.setValueCount(recordCount);
  input.setRecordCount(recordCount);
  input.buildSchema(BatchSchema.SelectionVectorMode.NONE);
  return input;
}
 
源代码15 项目: estatio   文件: T_classify.java
public Collection<Taxonomy> choices0Classify() {
    SortedSet<Applicability> applicableToClassHierarchy = Sets.newTreeSet();

    // pull together all the 'Applicability's for this domain type and all its supertypes.
    String atPath = getAtPath();
    if (atPath == null) {
        return Collections.emptyList();
    }
    
    appendDirectApplicabilities(atPath, classified.getClass(), applicableToClassHierarchy);

    // the obtain the corresponding 'Taxonomy's of each of these
    Set<Taxonomy> taxonomies = Sets.newTreeSet();
    taxonomies.addAll(
            applicableToClassHierarchy.stream()
                    .map(Applicability::getTaxonomy)
                    .distinct()
                    .collect(Collectors.toSet())
    );

    // remove any taxonomies already selected
    T_classifications t_classifications = new T_classifications(classified) {
    };
    serviceRegistry.injectServicesInto(t_classifications);
    final List<Classification> classifications = t_classifications.$$();
    final Set<Taxonomy> existing = classifications.stream().map(Classification::getTaxonomy).collect(Collectors.toSet());
    taxonomies.removeAll(existing);

    return taxonomies;
}
 
/**
 * Returns a set of regions that are live but are not empty nor have a prune upper bound recorded. These regions
 * will stop the progress of pruning.
 * <p/>
 * Note that this can return false positives in the following case -
 * At time 't' empty regions were recorded, and time 't+1' prune iteration was invoked.
 * Since  a new set of regions was recorded at time 't+1', all regions recorded as empty before time 't + 1' will
 * now be reported as blocking the pruning, even though they are empty. This is because we cannot tell if those
 * regions got any new data between time 't' and 't + 1'.
 *
 * @param numRegions number of regions
 * @param time time in milliseconds or relative time, regions recorded before the given time are returned
 * @return {@link Set} of regions that needs to be compacted and flushed
 */
@Override
@SuppressWarnings("WeakerAccess")
public Set<String> getRegionsToBeCompacted(Integer numRegions, String time) throws IOException {
  // Fetch the live regions at the given time
  RegionsAtTime timeRegion = getRegionsOnOrBeforeTime(time);
  if (timeRegion.getRegions().isEmpty()) {
    return Collections.emptySet();
  }

  Long timestamp = timeRegion.getTime();
  SortedSet<String> regions = timeRegion.getRegions();

  // Get the live regions
  SortedSet<String> liveRegions = getRegionsOnOrBeforeTime(NOW).getRegions();
  // Retain only the live regions
  regions = Sets.newTreeSet(Sets.intersection(liveRegions, regions));

  SortedSet<byte[]> emptyRegions = dataJanitorState.getEmptyRegionsAfterTime(timestamp, null);
  SortedSet<String> emptyRegionNames = new TreeSet<>();
  Iterable<String> regionStrings = Iterables.transform(emptyRegions, TimeRegions.BYTE_ARR_TO_STRING_FN);
  for (String regionString : regionStrings) {
    emptyRegionNames.add(regionString);
  }

  Set<String> nonEmptyRegions = Sets.newHashSet(Sets.difference(regions, emptyRegionNames));

  // Get all pruned regions for the current time and remove them from the nonEmptyRegions,
  // resulting in a set of regions that are not empty and have not been registered prune upper bound
  List<RegionPruneInfo> prunedRegions = dataJanitorState.getPruneInfoForRegions(null);
  for (RegionPruneInfo prunedRegion : prunedRegions) {
    if (nonEmptyRegions.contains(prunedRegion.getRegionNameAsString())) {
      nonEmptyRegions.remove(prunedRegion.getRegionNameAsString());
    }
  }

  if ((numRegions < 0) || (numRegions >= nonEmptyRegions.size())) {
    return nonEmptyRegions;
  }

  Set<String> subsetRegions = new HashSet<>(numRegions);
  for (String regionName : nonEmptyRegions) {
    if (subsetRegions.size() == numRegions) {
      break;
    }
    subsetRegions.add(regionName);
  }
  return subsetRegions;
}
 
@Test
public void testIdleRegions() throws Exception {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  try (PrintWriter out = new PrintWriter(outputStream)) {
    // Get the list of regions that have the lowest prune upper bounds for the latest record time
    Long latestRecordTime = compactedRegions.asMap().lastKey();
    SortedSet<InvalidListPruningDebugTool.RegionPruneInfoPretty> latestExpected =
      ImmutableSortedSet.copyOf(pruneUpperBoundAndStringComparator(), compactedRegions.get(latestRecordTime));
    pruningDebug.execute(new String[]{"idle-regions", "-1"}, out);
    out.flush();
    assertEquals(latestExpected, readOutputStream(outputStream));

    // Same command with explicit time
    outputStream.reset();
    pruningDebug.execute(new String[]{"idle-regions", "-1", String.valueOf(latestRecordTime)}, out);
    out.flush();
    assertEquals(latestExpected, readOutputStream(outputStream));

    // Same command with relative time
    outputStream.reset();
    pruningDebug.execute(new String[]{"idle-regions", "-1", "now-2s"}, out);
    out.flush();
    assertEquals(latestExpected, readOutputStream(outputStream));

    // Same command with reduced number of regions
    outputStream.reset();
    int limit = 2;
    pruningDebug.execute(new String[]{"idle-regions", String.valueOf(limit), String.valueOf(latestRecordTime)}, out);
    out.flush();
    Assert.assertEquals(GSON.toJson(subset(latestExpected, 0, limit)), readOutputStream(outputStream));

    // For a different time, this time only live regions that are compacted are returned
    outputStream.reset();
    Long secondLastRecordTime = Iterables.get(compactedRegions.keySet(), 1);
    Set<String> compactedRegionsTime =
      Sets.newTreeSet(Iterables.transform(compactedRegions.get(secondLastRecordTime), PRUNE_INFO_TO_STRING));
    Set<String> compactedRegionsLatest =
      Sets.newTreeSet(Iterables.transform(compactedRegions.get(latestRecordTime), PRUNE_INFO_TO_STRING));
    Set<String> liveExpected = new TreeSet<>(Sets.intersection(compactedRegionsTime, compactedRegionsLatest));
    pruningDebug.execute(new String[]{"idle-regions", "-1", String.valueOf(latestRecordTime - 1)}, out);
    out.flush();
    List<RegionPruneInfo> actual = GSON.fromJson(readOutputStream(outputStream), PRUNE_INFO_LIST_TYPE);
    Assert.assertEquals(liveExpected, Sets.newTreeSet(Iterables.transform(actual, PRUNE_INFO_TO_STRING)));
  }
}
 
源代码18 项目: styx   文件: BigtableStorage.java
private static TreeSet<SequenceEvent> newSortedEventSet() {
  return Sets.newTreeSet(SequenceEvent.COUNTER_COMPARATOR);
}
 
源代码19 项目: log-synth   文件: CommuterTest.java
private void verifyFields(JsonNode jsonNode, Collection<String> expectedFields) {
    TreeSet<String> c = Sets.newTreeSet(Lists.newArrayList(jsonNode.fieldNames()));
    assertEquals(String.format("Expected fields %s but got %s", expectedFields.toString(), c.toString()),
            expectedFields.size(), Sets.intersection(c, Sets.newTreeSet(expectedFields)).size());
}
 
源代码20 项目: coming   文件: Cardumen_0019_s.java
@Override
String toStringHelper(boolean forAnnotations) {
  if (hasReferenceName()) {
    return getReferenceName();
  } else if (prettyPrint) {
    // Don't pretty print recursively.
    prettyPrint = false;

    // Use a tree set so that the properties are sorted.
    Set<String> propertyNames = Sets.newTreeSet();
    for (ObjectType current = this;
         current != null && !current.isNativeObjectType() &&
             propertyNames.size() <= MAX_PRETTY_PRINTED_PROPERTIES;
         current = current.getImplicitPrototype()) {
      propertyNames.addAll(current.getOwnPropertyNames());
    }

    StringBuilder sb = new StringBuilder();
    sb.append("{");

    int i = 0;
    for (String property : propertyNames) {
      if (i > 0) {
        sb.append(", ");
      }

      sb.append(property);
      sb.append(": ");
      sb.append(getPropertyType(property).toStringHelper(forAnnotations));

      ++i;
      if (!forAnnotations && i == MAX_PRETTY_PRINTED_PROPERTIES) {
        sb.append(", ...");
        break;
      }
    }

    sb.append("}");

    prettyPrint = true;
    return sb.toString();
  } else {
    return forAnnotations ? "?" : "{...}";
  }
}