Refine search
private void checkAttributeNamesForDuplicates(ValueType type, Protoclass protoclass) { if (!type.attributes.isEmpty()) { Multiset<String> attributeNames = HashMultiset.create(type.attributes.size()); for (ValueAttribute attribute : type.attributes) { if (attribute.isGenerateLazy) { attributeNames.add(attribute.name() + "$lazy"); // making lazy compare in it's own scope } else { attributeNames.add(attribute.name()); } } List<String> duplicates = Lists.newArrayList(); for (Multiset.Entry<String> entry : attributeNames.entrySet()) { if (entry.getCount() > 1) { duplicates.add(entry.getElement().replace("$lazy", "")); } } if (!duplicates.isEmpty()) { protoclass.report() .error("Duplicate attribute names %s. You should check if correct @Value.Style applied", duplicates); } } }
/** * Creates a new, empty {@code HashMultiset} with the specified expected number of distinct * elements. * * @param distinctElements the expected number of distinct elements * @throws IllegalArgumentException if {@code distinctElements} is negative */ public static <E> HashMultiset<E> create(int distinctElements) { return new HashMultiset<E>(distinctElements); }
@GwtIncompatible // java.io.ObjectInputStream private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); int distinctElements = Serialization.readCount(stream); setBackingMap(Maps.<E, Count>newHashMap()); Serialization.populateMultiset(this, stream, distinctElements); }
@Test public void testSimpleIterator() { NodeLayout masterNodeLayout = new NodeLayout("large", "centos6", ImmutableSet.of("master1")); NodeLayout slaveLayout = new NodeLayout("medium", "centos6", ImmutableSet.of("slave1")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(masterNodeLayout); counts.add(slaveLayout); ClusterLayout layout = new ClusterLayout(constraints, counts); Iterator<ClusterLayoutChange> iter = new AddServiceChangeIterator(layout, "slave2"); // only possible change is to add slave2 to the slave node List<ClusterLayoutChange> expected = Lists.newArrayList(); Multiset<NodeLayout> expectedCounts = HashMultiset.create(); expectedCounts.add(slaveLayout); expected.add(new AddServicesChange(expectedCounts, "slave2")); assertIterator(expected, iter); }
private SegmentsToMerge() { this.timelineObjects = Lists.newArrayList(); this.segments = HashMultiset.create(); this.byteCount = 0; }
public void testHashFloat() { Multiset<Integer> violations = HashMultiset.create(); for (int k = 0; k < 1000; k++) { List<Float> original = Lists.newArrayList(); Random gen = RandomUtils.getRandom(); for (int i = 0; i < 10000; i++) { float x = (float) gen.nextDouble(); original.add(x); } violations.add(checkCounts(original) <= 12 ? 0 : 1); } // the hashes for floats don't really have 32 bits of entropy so the test // only succeeds at better than about 99% rate. assertTrue(violations.count(0) >= 985); }
private static void validateAnalyzerMessage(Map<IssueAttribute, String> attrs, AnalyzerMessage analyzerMessage) { Double effortToFix = analyzerMessage.getCost(); if (effortToFix != null) { assertEquals(Integer.toString(effortToFix.intValue()), attrs, IssueAttribute.EFFORT_TO_FIX); } AnalyzerMessage.TextSpan textSpan = analyzerMessage.primaryLocation(); assertEquals(normalizeColumn(textSpan.startCharacter), attrs, IssueAttribute.START_COLUMN); assertEquals(Integer.toString(textSpan.endLine), attrs, IssueAttribute.END_LINE); assertEquals(normalizeColumn(textSpan.endCharacter), attrs, IssueAttribute.END_COLUMN); if (attrs.containsKey(IssueAttribute.SECONDARY_LOCATIONS)) { List<AnalyzerMessage> secondaryLocations = analyzerMessage.flows.stream().map(l -> l.get(0)).collect(Collectors.toList()); Multiset<String> actualLines = HashMultiset.create(); for (AnalyzerMessage secondaryLocation : secondaryLocations) { actualLines.add(Integer.toString(secondaryLocation.getLine())); } List<String> expected = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().trimResults().split(attrs.get(IssueAttribute.SECONDARY_LOCATIONS))); List<String> unexpected = new ArrayList<>(); for (String actualLine : actualLines) { if (expected.contains(actualLine)) { expected.remove(actualLine); } else { unexpected.add(actualLine); } } if (!expected.isEmpty() || !unexpected.isEmpty()) { // Line is not covered by JaCoCo because of thrown exception but effectively covered in UT. Fail.fail(String.format("Secondary locations: expected: %s unexpected:%s. In %s:%d", expected, unexpected, normalizedFilePath(analyzerMessage), analyzerMessage.getLine())); } } }
@Test public void testInvalidNodeLayouts() { NodeLayout masterNodeLayout = new NodeLayout("large-mem", "centos6", ImmutableSet.of("namenode")); Multiset<NodeLayout> counts = HashMultiset.create(); counts.add(masterNodeLayout); NodeLayout badNodeLayout = new NodeLayout("large-mem", "ubuntu12", ImmutableSet.of("namenode")); Multiset<NodeLayout> badCounts = HashMultiset.create(); badCounts.add(badNodeLayout); ClusterLayout layout = new ClusterLayout(constraints, counts); AddServicesChange change = new AddServicesChange(badCounts, "resourcemanager"); Assert.assertFalse(change.canApplyChange(layout)); }
/** * Assert that each of the lines passed in has been written, but don't care about the order. */ public void expectWritten(Collection<String> lines) { TestCase.assertEquals("File: " + filename, lines.size(), written.size()); Multiset<String> counts = HashMultiset.create(lines); for (Multiset.Entry<String> entry : counts.entrySet()) { TestUtil.assertCount(written, entry.getElement(), entry.getCount()); } written = Lists.newArrayList(); }
Collection<InetAddress> contactPoints = newArrayList(); for (int i = 1; i <= hostCount; i++) { contactPoints.add(scassandras.address(i).getAddress()); final HashMultiset<InetAddress> occurrencesByHost = HashMultiset.create(hostCount); for (int i = 0; i < iterations; i++) { Cluster cluster = occurrencesByHost.add(cluster.manager.controlConnection.connectedHost().getAddress()); } finally { cluster.close(); Map<InetAddress, Integer> hostCounts = Maps.toMap( occurrencesByHost.elementSet(), new Function<InetAddress, Integer>() { @Override assertThat(occurrencesByHost.elementSet().size()) .as( "Not all hosts were used as contact points. There is a very small chance"
final Set<String> names = ImmutableSet.of("Marko", "Dan", "Stephen", "Daniel", "Josh", "Thad", "Pavel", "Matthias"); final int numG = 10; final long[] gids = new long[numG]; Multiset<Integer> partitions = HashMultiset.create(); partitions.add(partition); txx.commit(); assertTrue(partitions.elementSet().size() >= 3); // int numV = 0; while (parts.size() < numP) { int part = Iterables.get(partitions.elementSet(), random.nextInt(partitions.elementSet().size())); if (parts.add(part)) numV += partitions.count(part);
public List<StubMapping> process(Iterable<StubMapping> stubMappings) { final Multiset<RequestPattern> requestCounts = HashMultiset.create(); final List<StubMapping> processedStubMappings = new ArrayList<>(); for (StubMapping stubMapping: stubMappings) { requestCounts.add(stubMapping.getRequest()); // Skip duplicate requests if shouldRecordRepeatsAsScenarios is not enabled if ( requestCounts.count(stubMapping.getRequest()) > 1 && !shouldRecordRepeatsAsScenarios ) { continue; } if (bodyExtractMatcher != null && bodyExtractMatcher.match(stubMapping.getResponse()).isExactMatch()) { bodyExtractor.extractInPlace(stubMapping); } processedStubMappings.add(stubMapping); } if (shouldRecordRepeatsAsScenarios) { new ScenarioProcessor().putRepeatedRequestsInScenarios(processedStubMappings); } // Run any stub mapping transformer extensions return Lists.transform(processedStubMappings, transformerRunner); } }
for (NodeLayout nodeLayout : clusterLayout.getLayout().elementSet()) { expandedClusterServices.addAll(nodeLayout.getServiceNames()); this.expandableNodeLayouts = Lists.newArrayListWithCapacity(clusterLayout.getLayout().elementSet().size()); Multiset<NodeLayout> expandedCounts = HashMultiset.create(); for (NodeLayout originalNodeLayout : clusterLayout.getLayout().elementSet()) { NodeLayout expandedNodeLayout = NodeLayout.addServiceToNodeLayout(originalNodeLayout, service); if (expandedNodeLayout.satisfiesConstraints(clusterLayout.getConstraints(), expandedClusterServices)) {
@GwtIncompatible // SerializableTester public void testSerializationIndirectSelfReference() { Multiset<MultisetHolder> multiset = HashMultiset.create(); MultisetHolder holder = new MultisetHolder(multiset); multiset.add(holder, 2); Multiset<MultisetHolder> copy = SerializableTester.reserialize(multiset); assertEquals(2, copy.size()); assertSame(copy, copy.iterator().next().member); }