当前位置: 首页>>代码示例>>Java>>正文


Java Sets.newHashSetWithExpectedSize方法代码示例

本文整理汇总了Java中com.google.common.collect.Sets.newHashSetWithExpectedSize方法的典型用法代码示例。如果您正苦于以下问题:Java Sets.newHashSetWithExpectedSize方法的具体用法?Java Sets.newHashSetWithExpectedSize怎么用?Java Sets.newHashSetWithExpectedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.collect.Sets的用法示例。


在下文中一共展示了Sets.newHashSetWithExpectedSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readTOC

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * Reads the list of components from the TOC component.
 * @return set of components found in the TOC
 */
protected static Set<Component> readTOC(Descriptor descriptor) throws IOException
{
    List<String> componentNames = readLines(descriptor.filenameFor(Component.TOC), descriptor.getConfiguration());
    Set<Component> components = Sets.newHashSetWithExpectedSize(componentNames.size());
    for (String componentName : componentNames)
    {
        logger.info("Checking for the existence of [" + componentName + "]");
        Component component = new Component(Component.Type.fromRepresentation(componentName), componentName);
        if (!HadoopFileUtils.exists(descriptor.filenameFor(component), descriptor.getConfiguration()))
            logger.error("Missing component: {}", descriptor.filenameFor(component));
        else
            components.add(component);
    }

    return components;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:21,代码来源:SSTable.java

示例2: testBulkGetReturnsSorted

import com.google.common.collect.Sets; //导入方法依赖的package包/类
public void testBulkGetReturnsSorted() {
  for (Striped<?> striped : allImplementations()) {
    Map<Object, Integer> indexByLock = Maps.newHashMap();
    for (int i = 0; i < striped.size(); i++) {
      indexByLock.put(striped.getAt(i), i);
    }

    // ensure that bulkGet returns locks in monotonically increasing order
    for (int objectsNum = 1; objectsNum <= striped.size() * 2; objectsNum++) {
      Set<Object> objects = Sets.newHashSetWithExpectedSize(objectsNum);
      for (int i = 0; i < objectsNum; i++) {
        objects.add(new Object());
      }

      Iterable<?> locks = striped.bulkGet(objects);
      assertTrue(Ordering.natural().onResultOf(Functions.forMap(indexByLock)).isOrdered(locks));

      // check idempotency
      Iterable<?> locks2 = striped.bulkGet(objects);
      assertEquals(Lists.newArrayList(locks), Lists.newArrayList(locks2));
    }
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:24,代码来源:StripedTest.java

示例3: getRecipes

import com.google.common.collect.Sets; //导入方法依赖的package包/类
protected List<Recipe> getRecipes(FeatureWrapper feature, Collection<Pickle> pickles) {
	int pickleCount = pickles.size();
	ArrayList<Recipe> recipes = Lists.newArrayListWithExpectedSize(pickleCount);
	Set<Integer> pickleLines = Sets.newHashSetWithExpectedSize(pickleCount);

	RangeMap<Integer, ScenarioDefinition> rangeMap = getRangeMap(feature);
	for (Pickle pickle : pickles) {
		List<PickleLocation> locations = pickle.getLocations();
		for (PickleLocation location : locations) {
			int line = location.getLine();
			if (!pickleLines.contains(line)) {
				pickleLines.add(line);
				Range<Integer> range = Range.singleton(line);
				RangeMap<Integer, ScenarioDefinition> subRangeMap = rangeMap.subRangeMap(range);
				Map<Range<Integer>, ScenarioDefinition> asMap = subRangeMap.asMapOfRanges();
				checkState(1 == asMap.size(), "no single range found encompassing PickleLocation %s", location);
				ScenarioDefinition definition = Iterables.getOnlyElement(asMap.values());
				Recipe recipe = new Recipe(feature, pickle, location, definition);
				recipes.add(recipe);
			}
		}
	}
	return recipes;
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:25,代码来源:DefaultMixology.java

示例4: getInitialVolumeFailureInfos

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * Gets initial volume failure information for all volumes that failed
 * immediately at startup.  The method works by determining the set difference
 * between all configured storage locations and the actual storage locations in
 * use after attempting to put all of them into service.
 *
 * @return each storage location that has failed
 */
private static List<VolumeFailureInfo> getInitialVolumeFailureInfos(
    Collection<StorageLocation> dataLocations, DataStorage storage) {
  Set<String> failedLocationSet = Sets.newHashSetWithExpectedSize(
      dataLocations.size());
  for (StorageLocation sl: dataLocations) {
    failedLocationSet.add(sl.getFile().getAbsolutePath());
  }
  for (Iterator<Storage.StorageDirectory> it = storage.dirIterator();
       it.hasNext(); ) {
    Storage.StorageDirectory sd = it.next();
    failedLocationSet.remove(sd.getRoot().getAbsolutePath());
  }
  List<VolumeFailureInfo> volumeFailureInfos = Lists.newArrayListWithCapacity(
      failedLocationSet.size());
  long failureDate = Time.now();
  for (String failedStorageLocation: failedLocationSet) {
    volumeFailureInfos.add(new VolumeFailureInfo(failedStorageLocation,
        failureDate));
  }
  return volumeFailureInfos;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:FsDatasetImpl.java

示例5: getDependencies

import com.google.common.collect.Sets; //导入方法依赖的package包/类
public Set<? extends Task> getDependencies(Task task) {
    Set<Task> tasks = Sets.newHashSetWithExpectedSize(taskDependencyNames.size());
    for (String dependedOnTaskName : taskDependencyNames) {
        Task dependency = task.getProject().getTasks().findByName(dependedOnTaskName);
        if (dependency == null) {
            throw new UnknownTaskException(String.format("Imported Ant target '%s' depends on target or task '%s' which does not exist", task.getName(), dependedOnTaskName));
        }
        tasks.add(dependency);
    }
    return tasks;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:12,代码来源:DefaultAntBuilder.java

示例6: checkExactMatches

import com.google.common.collect.Sets; //导入方法依赖的package包/类
static void checkExactMatches(CharMatcher m, char[] chars) {
  Set<Character> positive = Sets.newHashSetWithExpectedSize(chars.length);
  for (char c : chars) {
    positive.add(c);
  }
  for (int c = 0; c <= Character.MAX_VALUE; c++) {
    assertFalse(positive.contains(new Character((char) c)) ^ m.matches((char) c));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:CharMatcherTest.java

示例7: ensureNoDuplicateColumnNames

import com.google.common.collect.Sets; //导入方法依赖的package包/类
private static void ensureNoDuplicateColumnNames(List<String> fieldNames) throws ValidationException {
  final HashSet<String> fieldHashSet = Sets.newHashSetWithExpectedSize(fieldNames.size());
  for(String field : fieldNames) {
    if (fieldHashSet.contains(field.toLowerCase())) {
      throw new ValidationException(String.format("Duplicate column name [%s]", field));
    }
    fieldHashSet.add(field.toLowerCase());
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:10,代码来源:SqlHandlerUtil.java

示例8: CachedScopePatroon

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * Constructor.
 * @param scopePatroon een patroon
 */
CachedScopePatroon(final ScopePatroon scopePatroon) {
    this.scopePatroon = scopePatroon;

    elementAttribuutSet = Sets.newHashSetWithExpectedSize(scopePatroon.getScopePatroonElementSet().size());
    for (final ScopePatroonElement scopePatroonElement : scopePatroon.getScopePatroonElementSet()) {
        elementAttribuutSet.add(scopePatroonElement.getElementId());
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:13,代码来源:CachedScopePatroon.java

示例9: testMultipleGivenRegex

import com.google.common.collect.Sets; //导入方法依赖的package包/类
@Test
public void testMultipleGivenRegex() throws NoSuchMethodException {
	MultipleGivenBean source = new MultipleGivenBean();
	ClassPathXmlApplicationContext context = getContext(source);
	process(context, source);

	MultipleGivenBean steps = context.getBean(MultipleGivenBean.class);
	Class<?> wrapped = AopUtils.getTargetClass(steps);
	Method method = wrapped.getMethod("doSomething");

	Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
	Collection<StepImplementation> givens = givenBeanIndex.values();

	Set<String> matches = Sets.newHashSetWithExpectedSize(2);
	for (StepImplementation given : givens) {
		Method givenMethod = given.getMethod();
		if (givenMethod.equals(method)) {
			Pattern pattern = given.getPattern();
			String regex = pattern.pattern();
			matches.add(regex);
		}
	}

	int count = matches.size();
	assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()");

	Set<String> expected = Sets.newHashSet(
		"this is regular expression one", "this is regular expression two");
	assertEquals(matches, expected, "Steps contain wrong regex Pattern objects");
}
 
开发者ID:qas-guru,项目名称:martini-core,代码行数:31,代码来源:StepsAnnotationProcessorTest.java

示例10: assignMplsLabel

import com.google.common.collect.Sets; //导入方法依赖的package包/类
private Map<LinkKey, MplsLabel> assignMplsLabel(MplsPathIntent intent) {
    // TODO: do it better... Suggestions?
    Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(intent.path()
            .links().size() - 2);
    for (int i = 1; i <= intent.path().links().size() - 2; i++) {
        LinkKey link = linkKey(intent.path().links().get(i));
        linkRequest.add(link);
        // add the inverse link. I want that the label is reserved both for
        // the direct and inverse link
        linkRequest.add(linkKey(link.dst(), link.src()));
    }

    Map<LinkKey, MplsLabel> labels = findMplsLabels(linkRequest);
    if (labels.isEmpty()) {
        return Collections.emptyMap();
    }

    // for short term solution: same label is used for both directions
    // TODO: introduce the concept of Tx and Rx resources of a port
    Set<Resource> resources = labels.entrySet().stream()
            .flatMap(x -> Stream.of(
                    Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
                            .resource(),
                    Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
                            .resource()
            ))
            .collect(Collectors.toSet());
    List<ResourceAllocation> allocations =
            resourceService.allocate(intent.id(), ImmutableList.copyOf(resources));
    if (allocations.isEmpty()) {
        Collections.emptyMap();
    }

    return labels;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:MplsPathIntentCompiler.java

示例11: assignVlanId

import com.google.common.collect.Sets; //导入方法依赖的package包/类
private Map<LinkKey, VlanId> assignVlanId(PathCompilerCreateFlow creator, PathIntent intent) {
    Set<LinkKey> linkRequest =
            Sets.newHashSetWithExpectedSize(intent.path()
                    .links().size() - 2);
    for (int i = 1; i <= intent.path().links().size() - 2; i++) {
        LinkKey link = linkKey(intent.path().links().get(i));
        linkRequest.add(link);
        // add the inverse link. I want that the VLANID is reserved both for
        // the direct and inverse link
        linkRequest.add(linkKey(link.dst(), link.src()));
    }

    Map<LinkKey, VlanId> vlanIds = findVlanIds(creator, linkRequest);
    if (vlanIds.isEmpty()) {
        creator.log().warn("No VLAN IDs available");
        return Collections.emptyMap();
    }

    //same VLANID is used for both directions
    Set<Resource> resources = vlanIds.entrySet().stream()
            .flatMap(x -> Stream.of(
                    Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
                            .resource(),
                    Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
                            .resource()
            ))
            .collect(Collectors.toSet());
    List<ResourceAllocation> allocations =
            creator.resourceService().allocate(intent.id(), ImmutableList.copyOf(resources));
    if (allocations.isEmpty()) {
        return Collections.emptyMap();
    }

    return vlanIds;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:PathCompiler.java

示例12: assignMplsLabel

import com.google.common.collect.Sets; //导入方法依赖的package包/类
private Map<LinkKey, MplsLabel> assignMplsLabel(PathCompilerCreateFlow creator, PathIntent intent) {
            Set<LinkKey> linkRequest =
            Sets.newHashSetWithExpectedSize(intent.path()
                    .links().size() - 2);
    for (int i = 1; i <= intent.path().links().size() - 2; i++) {
        LinkKey link = linkKey(intent.path().links().get(i));
        linkRequest.add(link);
        // add the inverse link. I want that the VLANID is reserved both for
        // the direct and inverse link
        linkRequest.add(linkKey(link.dst(), link.src()));
    }

    Map<LinkKey, MplsLabel> labels = findMplsLabels(creator, linkRequest);
    if (labels.isEmpty()) {
        throw new IntentCompilationException("No available MPLS Label");
    }

    // for short term solution: same label is used for both directions
    // TODO: introduce the concept of Tx and Rx resources of a port
    Set<Resource> resources = labels.entrySet().stream()
            .flatMap(x -> Stream.of(
                    Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
                            .resource(),
                    Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
                            .resource()
            ))
            .collect(Collectors.toSet());
    List<ResourceAllocation> allocations =
            creator.resourceService().allocate(intent.id(), ImmutableList.copyOf(resources));
    if (allocations.isEmpty()) {
        return Collections.emptyMap();
    }

    return labels;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:PathCompiler.java

示例13: findAvailableTributarySlots

import com.google.common.collect.Sets; //导入方法依赖的package包/类
/**
 * Find available TributarySlots across path.
 *
 * @param intent
 * @param path path in OTU topology
 * @return Map of Linkey and Set of available TributarySlots on its ports
 */
private Map<LinkKey, Set<TributarySlot>> findAvailableTributarySlots(OpticalOduIntent intent, Path path) {
    Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(path.links().size());
    for (int i = 0; i < path.links().size(); i++) {
        LinkKey link = linkKey(path.links().get(i));
        linkRequest.add(link);
    }

    return findTributarySlots(intent, linkRequest);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:OpticalOduIntentCompiler.java

示例14: Undirected

import com.google.common.collect.Sets; //导入方法依赖的package包/类
private Undirected(BaseGraph<N> graph) {
  super(graph);
  this.visitedNodes = Sets.newHashSetWithExpectedSize(graph.nodes().size());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:5,代码来源:EndpointPairIterator.java

示例15: edgeToEdgePathsDisjoint

import com.google.common.collect.Sets; //导入方法依赖的package包/类
private Set<DisjointPath> edgeToEdgePathsDisjoint(EdgeLink srcLink, EdgeLink dstLink) {
    Set<DisjointPath> endToEndPaths = Sets.newHashSetWithExpectedSize(1);
    endToEndPaths.add(edgeToEdgePathD(srcLink, dstLink, null));
    return endToEndPaths;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:6,代码来源:PathManager.java


注:本文中的com.google.common.collect.Sets.newHashSetWithExpectedSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。