com.google.common.collect.SortedMultiset源码实例Demo

类com.google.common.collect.SortedMultiset源码实例Demo

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

源代码1 项目: batfish   文件: VendorConfiguration.java
/**
 * Mark all references to a structure of the given type.
 *
 * <p>Do not use if {@code type} is used as an abstract structure type; instead use {@link
 * #markAbstractStructure(StructureType, StructureUsage, Collection)}.
 */
protected void markConcreteStructure(StructureType type) {
  Map<String, SortedMap<StructureUsage, SortedMultiset<Integer>>> references =
      _structureReferences.getOrDefault(type, Collections.emptySortedMap());
  Map<String, DefinedStructureInfo> definitions =
      _structureDefinitions.getOrDefault(type.getDescription(), Collections.emptySortedMap());
  references.forEach(
      (name, byUsage) -> {
        DefinedStructureInfo def = definitions.get(name);
        if (def == null) {
          byUsage.forEach(
              (usage, lines) -> lines.forEach(line -> undefined(type, name, usage, line)));
        } else {
          int count = byUsage.values().stream().mapToInt(Multiset::size).sum();
          def.setNumReferrers(def.getNumReferrers() + count);
        }
      });
}
 
源代码2 项目: presto   文件: Validator.java
private static boolean resultsMatch(QueryResult controlResult, QueryResult testResult, int precision)
{
    SortedMultiset<List<Object>> control = ImmutableSortedMultiset.copyOf(rowComparator(precision), controlResult.getResults());
    SortedMultiset<List<Object>> test = ImmutableSortedMultiset.copyOf(rowComparator(precision), testResult.getResults());
    try {
        return control.equals(test);
    }
    catch (TypesDoNotMatchException e) {
        return false;
    }
}
 
源代码3 项目: batfish   文件: VendorConfiguration.java
/**
 * Updates referrers and/or warns for undefined structures based on references to an abstract
 * {@link StructureType}: a reference type that may refer to one of a number of defined structure
 * types passed in {@code structureTypesToCheck}.
 *
 * <p>For example using Cisco devices, see {@code CiscoStructureType.ACCESS_LIST} and how it
 * expands to a list containing many types of IPv4 and IPv6 access lists.
 */
protected void markAbstractStructure(
    StructureType type,
    StructureUsage usage,
    Collection<? extends StructureType> structureTypesToCheck) {
  Map<String, SortedMap<StructureUsage, SortedMultiset<Integer>>> references =
      firstNonNull(_structureReferences.get(type), Collections.emptyMap());
  references.forEach(
      (name, byUsage) -> {
        Multiset<Integer> lines = firstNonNull(byUsage.get(usage), TreeMultiset.create());
        List<DefinedStructureInfo> matchingStructures =
            structureTypesToCheck.stream()
                .map(t -> _structureDefinitions.get(t.getDescription()))
                .filter(Objects::nonNull)
                .map(m -> m.get(name))
                .filter(Objects::nonNull)
                .collect(ImmutableList.toImmutableList());
        if (matchingStructures.isEmpty()) {
          for (int line : lines) {
            undefined(type, name, usage, line);
          }
        } else {
          matchingStructures.forEach(
              info -> info.setNumReferrers(info.getNumReferrers() + lines.size()));
        }
      });
}
 
源代码4 项目: batfish   文件: VendorConfiguration.java
public void referenceStructure(StructureType type, String name, StructureUsage usage, int line) {
  SortedMap<String, SortedMap<StructureUsage, SortedMultiset<Integer>>> byName =
      _structureReferences.computeIfAbsent(type, k -> new TreeMap<>());
  SortedMap<StructureUsage, SortedMultiset<Integer>> byUsage =
      byName.computeIfAbsent(name, k -> new TreeMap<>());
  SortedMultiset<Integer> lines = byUsage.computeIfAbsent(usage, k -> TreeMultiset.create());
  lines.add(line);
}
 
源代码5 项目: batfish   文件: PaloAltoConfiguration.java
private void markAbstractStructureFromUnknownNamespace(
    PaloAltoStructureType type,
    Collection<PaloAltoStructureType> structureTypesToCheck,
    boolean ignoreUndefined,
    PaloAltoStructureUsage... usages) {
  Map<String, SortedMap<StructureUsage, SortedMultiset<Integer>>> references =
      firstNonNull(_structureReferences.get(type), Collections.emptyMap());
  for (PaloAltoStructureUsage usage : usages) {
    references.forEach(
        (nameWithNamespace, byUsage) -> {
          String name = extractObjectName(nameWithNamespace);
          Multiset<Integer> lines = firstNonNull(byUsage.get(usage), TreeMultiset.create());
          // Check this namespace first
          DefinedStructureInfo info =
              findDefinedStructure(nameWithNamespace, structureTypesToCheck);
          // Check shared namespace if there was no match
          if (info == null) {
            info =
                findDefinedStructure(
                    computeObjectName(SHARED_VSYS_NAME, name), structureTypesToCheck);
          }

          // Now update reference count if applicable
          if (info != null) {
            info.setNumReferrers(info.getNumReferrers() + lines.size());
          } else if (!ignoreUndefined) {
            for (int line : lines) {
              undefined(type, name, usage, line);
            }
          }
        });
  }
}
 
源代码6 项目: log-synth   文件: SchemaSamplerTest.java
@Test
public void testSkewedInteger() throws IOException {
    // will give fields x, y, z, q with different skewness
    //noinspection UnstableApiUsage
    SchemaSampler s = new SchemaSampler(Resources.asCharSource(Resources.getResource("schema007.json"), Charsets.UTF_8).read());

    SortedMultiset<Integer> x = TreeMultiset.create();
    SortedMultiset<Integer> y = TreeMultiset.create();
    SortedMultiset<Integer> z = TreeMultiset.create();
    SortedMultiset<Integer> q = TreeMultiset.create();
    for (int i = 0; i < 10000; i++) {
        JsonNode record = s.sample();
        x.add(record.get("x").asInt());
        y.add(record.get("y").asInt());
        z.add(record.get("z").asInt());
        q.add(record.get("q").asInt());
    }

    for (int i = 10; i < 20; i++) {
        assertEquals(1000, x.count(i), 100);
        assertEquals(1900 - (i - 10) * 200, y.count(i), 120);
        assertEquals(100 + (i - 10) * 200, z.count(i), 120);
        // these magic numbers are a fit to the empirical distribution of q as computed by R
        double kq = 122623.551282 - 27404.139083 * i + 2296.601107 * i * i - 85.510684 * i * i * i + 1.193182 * i * i * i * i;
        // accuracy should get better for smaller numbers
        assertEquals(kq, q.count(i), (25.0 - i) / 10 * 120);
    }
}
 
源代码7 项目: Rails   文件: PortfolioModel.java
/**
 * @return a sorted Multiset<Integer> of shareNumbers of the certificates
 * Remark: excludes the presdident share if not of a different size as the standard share...
 */
// FIXME: Integers could be replaced later by CerficateTypes
public SortedMultiset<Integer> getCertificateTypeCounts(PublicCompany company) {
    return certificates.getCertificateTypeCounts(company);
}
 
源代码8 项目: c5-replicator   文件: QuorumConfiguration.java
private static long getGreatestIndexCommittedByMajority(Set<Long> peers, Map<Long, Long> peersLastAckedIndex) {
  SortedMultiset<Long> committedIndexes = TreeMultiset.create();
  committedIndexes.addAll(peers.stream().map(peerId
      -> peersLastAckedIndex.getOrDefault(peerId, 0L)).collect(Collectors.toList()));
  return Iterables.get(committedIndexes.descendingMultiset(), calculateNumericalMajority(peers.size()) - 1);
}
 
@Override
protected SortedMultiset<T> newCollection() {
    return TreeMultiset.create();
}
 
源代码10 项目: gwt-jackson   文件: GuavaConfiguration.java
@Override
protected void configure() {
    type( Optional.class ).serializer( OptionalJsonSerializer.class ).deserializer( OptionalJsonDeserializer.class );
    type( FluentIterable.class ).serializer( IterableJsonSerializer.class );

    // Immutable Collections
    type( ImmutableCollection.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( ImmutableCollectionJsonDeserializer.class );
    type( ImmutableList.class ).serializer( CollectionJsonSerializer.class ).deserializer( ImmutableListJsonDeserializer.class );
    type( ImmutableSet.class ).serializer( CollectionJsonSerializer.class ).deserializer( ImmutableSetJsonDeserializer.class );
    type( ImmutableSortedSet.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( ImmutableSortedSetJsonDeserializer.class );

    // Immutable Map
    type( ImmutableMap.class ).serializer( MapJsonSerializer.class ).deserializer( ImmutableMapJsonDeserializer.class );
    type( ImmutableSortedMap.class ).serializer( MapJsonSerializer.class ).deserializer( ImmutableSortedMapJsonDeserializer.class );

    // BiMap
    type( BiMap.class ).serializer( MapJsonSerializer.class ).deserializer( BiMapJsonDeserializer.class );
    type( ImmutableBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( ImmutableBiMapJsonDeserializer.class );
    type( HashBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( HashBiMapJsonDeserializer.class );
    type( EnumBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( EnumBiMapJsonDeserializer.class );
    type( EnumHashBiMap.class ).serializer( MapJsonSerializer.class ).deserializer( EnumHashBiMapJsonDeserializer.class );

    // Multiset
    type( Multiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( MultisetJsonDeserializer.class );
    type( HashMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( HashMultisetJsonDeserializer.class );
    type( LinkedHashMultiset.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( LinkedHashMultisetJsonDeserializer.class );
    type( SortedMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( SortedMultisetJsonDeserializer.class );
    type( TreeMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( TreeMultisetJsonDeserializer.class );
    type( ImmutableMultiset.class ).serializer( CollectionJsonSerializer.class )
            .deserializer( ImmutableMultisetJsonDeserializer.class );
    type( EnumMultiset.class ).serializer( CollectionJsonSerializer.class ).deserializer( EnumMultisetJsonDeserializer.class );

    // Multimap
    type( Multimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( MultimapJsonDeserializer.class );

    type( ImmutableMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( ImmutableMultimapJsonDeserializer.class );
    type( ImmutableSetMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( ImmutableSetMultimapJsonDeserializer.class );
    type( ImmutableListMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( ImmutableListMultimapJsonDeserializer.class );

    type( SetMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( SetMultimapJsonDeserializer.class );
    type( HashMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( HashMultimapJsonDeserializer.class );
    type( LinkedHashMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( LinkedHashMultimapJsonDeserializer.class );
    type( SortedSetMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( SortedSetMultimapJsonDeserializer.class );
    type( TreeMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( TreeMultimapJsonDeserializer.class );

    type( ListMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( ListMultimapJsonDeserializer.class );
    type( ArrayListMultimap.class ).serializer( MultimapJsonSerializer.class ).deserializer( ArrayListMultimapJsonDeserializer.class );
    type( LinkedListMultimap.class ).serializer( MultimapJsonSerializer.class )
            .deserializer( LinkedListMultimapJsonDeserializer.class );
}
 
源代码11 项目: immutables   文件: OrderAttributeValue.java
@Value.NaturalOrder
public abstract SortedMultiset<Integer> naturalMultiset();
 
源代码12 项目: immutables   文件: OrderAttributeValue.java
@Value.ReverseOrder
public abstract SortedMultiset<String> reverseMultiset();
 
源代码评论
动弹
沙发等你来抢
 类方法
 同包方法