com.google.common.collect.SortedMultiset Java Examples
The following examples show how to use
com.google.common.collect.SortedMultiset.
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 File: VendorConfiguration.java From batfish with Apache License 2.0 | 6 votes |
/** * 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); } }); }
Example #2
Source File: Validator.java From presto with Apache License 2.0 | 5 votes |
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; } }
Example #3
Source File: VendorConfiguration.java From batfish with Apache License 2.0 | 5 votes |
/** * 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())); } }); }
Example #4
Source File: VendorConfiguration.java From batfish with Apache License 2.0 | 5 votes |
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); }
Example #5
Source File: PaloAltoConfiguration.java From batfish with Apache License 2.0 | 5 votes |
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); } } }); } }
Example #6
Source File: SchemaSamplerTest.java From log-synth with Apache License 2.0 | 5 votes |
@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); } }
Example #7
Source File: PortfolioModel.java From Rails with GNU General Public License v2.0 | 4 votes |
/** * @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); }
Example #8
Source File: QuorumConfiguration.java From c5-replicator with Apache License 2.0 | 4 votes |
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); }
Example #9
Source File: SortedMultisetJsonDeserializer.java From gwt-jackson with Apache License 2.0 | 4 votes |
@Override protected SortedMultiset<T> newCollection() { return TreeMultiset.create(); }
Example #10
Source File: GuavaConfiguration.java From gwt-jackson with Apache License 2.0 | 4 votes |
@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 ); }
Example #11
Source File: OrderAttributeValue.java From immutables with Apache License 2.0 | 4 votes |
@Value.NaturalOrder public abstract SortedMultiset<Integer> naturalMultiset();
Example #12
Source File: OrderAttributeValue.java From immutables with Apache License 2.0 | 4 votes |
@Value.ReverseOrder public abstract SortedMultiset<String> reverseMultiset();