com.google.common.collect.ImmutableMultiset Java Examples

The following examples show how to use com.google.common.collect.ImmutableMultiset. 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: SlotMachineSimulation.java    From levelup-java-exercises with Apache License 2.0 8 votes vote down vote up
/**
 * Method should return the number of times an occurrence of a reel
 * 
 * @param reels
 * @return
 */
static int determinePayOutPercentage(List<String> reels) {

	Multiset<String> reelCount = HashMultiset.create();
	reelCount.addAll(reels);

	// order the number of elements by the higest
	ImmutableMultiset<String> highestCountFirst = Multisets.copyHighestCountFirst(reelCount);

	int count = 0;
	for (Entry<String> entry : highestCountFirst.entrySet()) {
		count = entry.getCount();
		break;
	}
	return count;
}
 
Example #2
Source File: MultisetPropertyTest.java    From FreeBuilder with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmutableSetProperty() {
  behaviorTester
      .with(new Processor(features))
      .with(SourceBuilder.forTesting()
          .addLine("package com.example;")
          .addLine("@%s", FreeBuilder.class)
          .addLine("public interface DataType {")
          .addLine("  %s<%s> %s;",
              ImmutableMultiset.class, element.type(), convention.get("items"))
          .addLine("")
          .addLine("  class Builder extends DataType_Builder {}")
          .addLine("}"))
      .with(testBuilder()
          .addLine("DataType value = new DataType.Builder()")
          .addLine("    .addItems(%s)", element.example(0))
          .addLine("    .addItems(%s)", element.example(1))
          .addLine("    .build();")
          .addLine("assertThat(value.%s).iteratesAs(%s);",
              convention.get("items"), element.examples(0, 1))
          .build())
      .runTest();
}
 
Example #3
Source File: FilterTableAnswererTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void filterRows() {
  Filter filter = new Filter("col >= 42");
  Rows rows = new Rows();
  rows.add(Row.builder().put("col", null).build());
  rows.add(Row.builder().put("col", 41).build());
  rows.add(Row.builder().put("col", 42).build());
  rows.add(Row.builder().put("col", 43).build());
  Multiset<Row> filteredRows = FilterTableAnswerer.filterRows(filter, rows.getData());

  // we should have the two rows with values >= 42
  assertThat(
      filteredRows,
      equalTo(
          new ImmutableMultiset.Builder<Row>()
              .add(Row.builder().put("col", 42).build())
              .add(Row.builder().put("col", 43).build())
              .build()));
}
 
Example #4
Source File: QueryAssertions.java    From presto with Apache License 2.0 6 votes vote down vote up
public static void assertEqualsIgnoreOrder(Iterable<?> actual, Iterable<?> expected, String message)
{
    assertNotNull(actual, "actual is null");
    assertNotNull(expected, "expected is null");

    ImmutableMultiset<?> actualSet = ImmutableMultiset.copyOf(actual);
    ImmutableMultiset<?> expectedSet = ImmutableMultiset.copyOf(expected);
    if (!actualSet.equals(expectedSet)) {
        Multiset<?> unexpectedRows = Multisets.difference(actualSet, expectedSet);
        Multiset<?> missingRows = Multisets.difference(expectedSet, actualSet);
        int limit = 100;
        fail(format(
                "%snot equal\n" +
                        "Actual rows (up to %s of %s extra rows shown, %s rows in total):\n    %s\n" +
                        "Expected rows (up to %s of %s missing rows shown, %s rows in total):\n    %s\n",
                message == null ? "" : (message + "\n"),
                limit,
                unexpectedRows.size(),
                actualSet.size(),
                Joiner.on("\n    ").join(Iterables.limit(unexpectedRows, limit)),
                limit,
                missingRows.size(),
                expectedSet.size(),
                Joiner.on("\n    ").join(Iterables.limit(missingRows, limit))));
    }
}
 
Example #5
Source File: SpecifiersAnswererTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveIpSpaceTest() {
  String prefix = "3.3.3.3/24";

  SpecifiersQuestion questionWithIp = new SpecifiersQuestion(QueryType.LOCATION);
  questionWithIp.setIpSpaceSpecifierInput(prefix);

  // both interface locations should be mapped to 3.3.3.3/24
  assertThat(
      resolveIpSpace(questionWithIp, _context).getRows().getData(),
      equalTo(
          ImmutableMultiset.of(
              Row.of(
                  COL_IP_SPACE,
                  SpecifierFactories.ACTIVE_VERSION == Version.V1
                      ? IpWildcardSetIpSpace.builder()
                          .including(IpWildcard.parse(prefix))
                          .build()
                          .toString()
                      : Prefix.parse(prefix).toIpSpace().toString()))));
}
 
Example #6
Source File: SpecifiersAnswererTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveInterfaceTest() {
  SpecifiersQuestion question = new SpecifiersQuestion(QueryType.INTERFACE);
  question.setInterfaceSpecifierInput(_iface1.getName());

  // only iface1 should be present (with a node specifier all nodes are included)
  assertThat(
      resolveInterface(question, _context).getRows().getData(),
      equalTo(
          ImmutableMultiset.of(
              Row.of(
                  COL_INTERFACE, NodeInterfacePair.of(_c1.getHostname(), _iface1.getName())))));

  // nothing should match since the node specifier does not match anything
  question.setNodeSpecifierInput("foofoo");
  assertThat(
      resolveInterface(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of()));
}
 
Example #7
Source File: TestCompiler.java    From guava-beta-checker with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that the given diagnostics contain errors with a message containing "[CheckerName]"
 * on the given lines of the given file. If there should be multiple errors on a line, the line
 * number must appear multiple times. There may not be any errors in any other file.
 */
public void assertErrorsOnLines(String file,
    List<Diagnostic<? extends JavaFileObject>> diagnostics, long... lines) {
  ListMultimap<String, Long> actualErrors = ArrayListMultimap.create();
  for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
    String message = diagnostic.getMessage(Locale.US);

    // The source may be null, e.g. for diagnostics about command-line flags
    assertNotNull(message, diagnostic.getSource());
    String sourceName = diagnostic.getSource().getName();

    assertEquals(
        "unexpected error in source file " + sourceName + ": " + message,
        file, sourceName);

    actualErrors.put(diagnostic.getSource().getName(), diagnostic.getLineNumber());

    // any errors from the compiler that are not related to this checker should fail
    assertThat(message).contains("[" + checker.getAnnotation(BugPattern.class).name() + "]");
  }

  assertEquals(
      ImmutableMultiset.copyOf(Longs.asList(lines)),
      ImmutableMultiset.copyOf(actualErrors.get(file)));
}
 
Example #8
Source File: FibonacciQueueTest.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testLotsOfRandomInserts() {
    int lots = 50000;
    final FibonacciQueue<Integer> queue = FibonacciQueue.create();
    // Insert lots of random numbers.
    final ImmutableMultiset.Builder<Integer> insertedBuilder = ImmutableMultiset.builder();
    for (int i = 0; i < lots; i++) {
        int r = random.nextInt();
        insertedBuilder.add(r);
        queue.add(r);
    }
    final Multiset<Integer> inserted = insertedBuilder.build();
    assertEquals(lots, queue.size());
    // Ensure it contains the same multiset of values that we put in
    assertEquals(inserted, ImmutableMultiset.copyOf(queue));
    // Ensure the numbers come out in increasing order.
    final List<Integer> polled = Lists.newLinkedList();
    while (!queue.isEmpty()) {
        polled.add(queue.poll());
    }
    assertTrue(Ordering.<Integer>natural().isOrdered(polled));
    // Ensure the same multiset of values came out that we put in
    assertEquals(inserted, ImmutableMultiset.copyOf(polled));
    assertEquals(0, queue.size());
}
 
Example #9
Source File: SpecifiersAnswererTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveIpSpaceOfLocationTestDefault() {
  SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE);

  assertThat(
      resolveIpSpaceOfLocation(question, _context).getRows().getData(),
      equalTo(
          ImmutableMultiset.of(
              Row.of(
                  COL_LOCATIONS,
                  ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName()))
                      .toString(),
                  COL_IP_SPACE,
                  _iface1.getConcreteAddress().getIp().toIpSpace().toString()),
              Row.of(
                  COL_LOCATIONS,
                  ImmutableSet.of(new InterfaceLocation(_c2.getHostname(), _iface2.getName()))
                      .toString(),
                  COL_IP_SPACE,
                  _iface2.getConcreteAddress().getIp().toIpSpace().toString()))));
}
 
Example #10
Source File: SpecifiersAnswererTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveIpSpaceOfLocationTest() {
  SpecifiersQuestion questionWithLocation =
      new SpecifiersQuestion(QueryType.IP_SPACE_OF_LOCATION);
  questionWithLocation.setLocationSpecifierInput(_c1.getHostname());

  // only c1:iface1 should be present
  assertThat(
      resolveIpSpaceOfLocation(questionWithLocation, _context).getRows().getData(),
      equalTo(
          ImmutableMultiset.of(
              Row.of(
                  COL_LOCATIONS,
                  ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName()))
                      .toString(),
                  COL_IP_SPACE,
                  _iface1.getConcreteAddress().getIp().toIpSpace().toString()))));
}
 
Example #11
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toMentionTypeCounts(
    final ImmutableSet<TypeRoleFillerRealis> targetEquivClasses,
    final ImmutableMultimap<TypeRoleFillerRealis, AssessedResponse> equivClassToAssessedResponse) {
  final ImmutableMultiset.Builder<Symbol> mentionTypes = ImmutableMultiset.builder();

  for(final TypeRoleFillerRealis equivClass : targetEquivClasses) {
    final AssessedResponse assessedResponse = Collections.max(equivClassToAssessedResponse.get(equivClass), Old2014ID);

    if(assessedResponse.response().role() == TIME) {
      mentionTypes.add(TIME);
    }
    else {
      final Optional<FillerMentionType> mentionType =
          assessedResponse.assessment().mentionTypeOfCAS();
      if (mentionType.isPresent()) {
        mentionTypes.add(Symbol.from(mentionType.get().name()));
      }
    }
  }

  return Multisets.copyHighestCountFirst(mentionTypes.build());
}
 
Example #12
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toNumberOfDocsPerEventType(
    final ImmutableSet<TypeRoleFillerRealis> equivClasses) {

  // for each docid, a set of event types
  final ImmutableMap<Symbol, ImmutableSet<Symbol>> eventTypesInEachDoc = getEventTypesInEachDoc(equivClasses);

  final ImmutableMultiset.Builder<Symbol> ret = ImmutableMultiset.builder();

  for(final Map.Entry<Symbol, ImmutableSet<Symbol>> entry : eventTypesInEachDoc.entrySet()) {
    for(final Symbol et : entry.getValue()) {
      ret.add(et);
    }
  }

  return Multisets.copyHighestCountFirst(ret.build());
}
 
Example #13
Source File: CorpusAnalysis.java    From tac-kbp-eal with MIT License 6 votes vote down vote up
public static ImmutableMultiset<Symbol> toRealisCounts(
    final ImmutableSet<TypeRoleFillerRealis> equivClasses) {
  return Multisets.copyHighestCountFirst(
      ImmutableMultiset.copyOf(Iterables.transform(equivClasses, Functions.compose(RealisSymbol, Realis))));
  /*
  final ImmutableMultimap<KBPRealis, TypeRoleFillerRealis> realisToEquivClass = Multimaps.index(equivClasses, TypeRoleFillerRealis.realisFunction());

  final List<ElementWithCount> elements = Lists.newArrayList();
  for(final Map.Entry<KBPRealis, Collection<TypeRoleFillerRealis>> entry : realisToEquivClass.asMap().entrySet()) {
    elements.add( ElementWithCount.from(entry.getKey(), entry.getValue().size()) );
  }

  Collections.sort(elements, ElementCount);
  return ImmutableList.copyOf(elements);
  */
}
 
Example #14
Source File: MultisetGwtTest.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
public void testDeserialization() {
    String input = "{" +
            "\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"hashMultiset\":[\"abc\",\"abc\"]," +
            "\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
            "\"sortedMultiset\":[\"foo\",\"abc\",\"bar\",\"abc\",null]," +
            "\"treeMultiset\":[\"bar\",\"abc\",\"abc\",\"foo\",null]," +
            "\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\",null]," +
            "\"enumMultiset\":[\"B\",\"A\",\"A\",\"D\",null]" +
            "}";

    BeanWithMultisetTypes result = BeanWithMultisetTypesMapper.INSTANCE.read( input );
    assertNotNull( result );

    List<String> expectedList = Arrays.asList( "foo", "abc", null, "abc" );
    List<String> expectedListWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );

    assertEquals( LinkedHashMultiset.create( expectedList ), result.multiset );
    assertEquals( HashMultiset.create( Arrays.asList( "abc", "abc" ) ), result.hashMultiset );
    assertEquals( LinkedHashMultiset.create( expectedList ), result.linkedHashMultiset );
    assertEquals( TreeMultiset.create( expectedListWithNonNull ), result.sortedMultiset );
    assertEquals( TreeMultiset.create( expectedListWithNonNull ), result.treeMultiset );
    assertEquals( ImmutableMultiset.copyOf( expectedListWithNonNull ), result.immutableMultiset );
    assertEquals( EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) ), result.enumMultiset );
}
 
Example #15
Source File: Word2VecTrainer.java    From Word2VecJava with MIT License 6 votes vote down vote up
/** @return Tokens with their count, sorted by frequency decreasing, then lexicographically ascending */
private ImmutableMultiset<String> filterAndSort(final Multiset<String> counts) {
	// This isn't terribly efficient, but it is deterministic
	// Unfortunately, Guava's multiset doesn't give us a clean way to order both by count and element
	return Multisets.copyHighestCountFirst(
			ImmutableSortedMultiset.copyOf(
					Multisets.filter(
							counts,
							new Predicate<String>() {
								@Override
								public boolean apply(String s) {
									return counts.count(s) >= minFrequency;
								}
							}
					)
			)
	);
	
}
 
Example #16
Source File: SpecifiersAnswererTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveFilterTest() {
  SpecifiersQuestion question = new SpecifiersQuestion(QueryType.FILTER);
  question.setFilterSpecifierInput(_filter1.getName());

  // only filter1 should be present (with a node specifier all nodes are included)
  assertThat(
      resolveFilter(question, _context).getRows().getData(),
      equalTo(
          ImmutableMultiset.of(
              Row.of(
                  COL_NODE, new Node(_c1.getHostname()), COL_FILTER_NAME, _filter1.getName()))));

  // nothing should match since the node specifier does not match anything
  question.setNodeSpecifierInput("foofoo");
  assertThat(
      resolveFilter(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of()));
}
 
Example #17
Source File: DerivedQuerySelector2016.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private ImmutableSetMultimap<RoleAndID, DocAndHopper> indexArgsToEventHopper(final Symbol docID,
    final EREDocument ereDoc, final ImmutableMultiset.Builder<String> allEREEventTypes) {
  final ImmutableSetMultimap.Builder<RoleAndID, DocAndHopper> argsToDocEventsB =
      ImmutableSetMultimap.builder();

  for (final EREEvent ereEvent : ereDoc.getEvents()) {
    boolean loggedType = false;

    for (final EREEventMention ereEventMention : ereEvent.getEventMentions()) {
      for (final EREArgument ereEventArg : ereEventMention.getArguments()) {
        if (ereEventArg instanceof EREEntityArgument) {
          final Optional<EREEntity> entityFiller = ((EREEntityArgument) ereEventArg).ereEntity();
          if (entityFiller.isPresent()) {
            final Optional<Symbol> mappedEventType =
                ScoringUtils.mapERETypesToDotSeparated(ontologyMapper, ereEventMention);
            final Optional<Symbol> mappedEventRole =
                ontologyMapper.eventRole(Symbol.from(ereEventArg.getRole()));

            if (mappedEventType.isPresent() && mappedEventRole.isPresent()) {
              if (!loggedType) {
                // we only want to log events which meet the criteria above, but we only
                // want to count each document event once
                allEREEventTypes.add(mappedEventType.get().asString());
                loggedType = true;
              }
              argsToDocEventsB.put(
                  RoleAndID.of(
                      mappedEventType.get().asString(),
                      mappedEventRole.get().asString(), entityFiller.get().getID()),
                  DocAndHopper.of(docID.asString(), ereEvent.getID(),
                      mappedEventType.get().asString()));
            }
          }
        }
      }
    }
  }

  return argsToDocEventsB.build();
}
 
Example #18
Source File: TestDatasetRepositories.java    From kite with Apache License 2.0 5 votes vote down vote up
@Test
public void testListDatasets() {
  Assert.assertEquals(ImmutableMultiset.<String>of(),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));

  repo.create(NAMESPACE, "test1", testDescriptor);
  Assert.assertEquals(ImmutableMultiset.of("test1"),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));

  repo.create(NAMESPACE, "test2", testDescriptor);
  Assert.assertEquals(ImmutableMultiset.of("test1", "test2"),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));

  repo.create(NAMESPACE, "test3", testDescriptor);
  Assert.assertEquals(ImmutableMultiset.of("test1", "test2", "test3"),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));

  repo.delete(NAMESPACE, "test2");
  Assert.assertEquals(ImmutableMultiset.of("test1", "test3"),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));

  repo.delete(NAMESPACE, "test3");
  Assert.assertEquals(ImmutableMultiset.of("test1"),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));

  repo.delete(NAMESPACE, "test1");
  Assert.assertEquals(ImmutableMultiset.<String>of(),
      ImmutableMultiset.copyOf(repo.datasets(NAMESPACE)));
}
 
Example #19
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableMultiset construct(int entries) {
  ImmutableMultiset.Builder builder = ImmutableMultiset.builder();
  Object key = newEntry();
  for (int i = 0; i < entries; i++) {
    builder.add(key);
  }
  return builder.build();
}
 
Example #20
Source File: ChartsAboutData.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private void generateChartEventHopperCounts(final ImmutableSet<EventArgumentLinking> linkings,
    final File outputDir) throws IOException {
  // num# event hoppers for each event type
  final ImmutableMultiset<Symbol> eventHopperPerEventTypeCounts = CorpusAnalysis.toEventHopperCounts(
      linkings);

  writeToFile(eventHopperPerEventTypeCounts,
      new File(outputDir, "eventHopperPerEventTypeCount.txt"));

  writeToChart(eventHopperPerEventTypeCounts,
      new File(outputDir, "eventHopperPerEventTypeCount.png"),
      renderer, "Event Hopper Counts", "Event Types", "num# event hoppers", Optional.<Integer>absent());
}
 
Example #21
Source File: ChartsAboutData.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private void generateChartNumberOfDocsPerEventType(final ImmutableSet<TypeRoleFillerRealis> equivClasses,
    final File outputDir) throws IOException {
  // num# documents containing each event type
  final ImmutableMultiset<Symbol> numberOfDocsPerEventTypeCounts = CorpusAnalysis.toNumberOfDocsPerEventType(
      equivClasses);

  writeToFile(numberOfDocsPerEventTypeCounts, new File(outputDir, "numberOfDocsPerEventTypeCount.txt"));

  writeToChart(numberOfDocsPerEventTypeCounts,
      new File(outputDir, "numberOfDocsPerEventTypeCount.png"),
      renderer, "Number of documents per event type", "Event Types", "num# documents", Optional.<Integer>absent());
}
 
Example #22
Source File: ChartsAboutData.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private void generateChartMentionTypeCounts(final ImmutableSet<TypeRoleFillerRealis> equivClasses,
    final ImmutableMultimap<TypeRoleFillerRealis, AssessedResponse> equivClassToAssessedResponse,
    final File outputDir) throws IOException {
  // num# correct TRFRs for each mention type
  final ImmutableMultiset<Symbol> mentionTypeCounts = CorpusAnalysis.toMentionTypeCounts(
      equivClasses, equivClassToAssessedResponse);

  writeToFile(mentionTypeCounts, new File(outputDir, "mentionTypeCount.txt"));

  writeToChart(mentionTypeCounts, new File(outputDir, "mentionTypeCount.png"),
      renderer, "Mention Type Counts", "MentionTypes", "Counts", Optional.<Integer>absent());
}
 
Example #23
Source File: AttributeAggregateTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAttributes() {
  expectGetAttributes("hostA");

  control.replay();

  assertEquals(
      ImmutableMultiset.<Pair<String, String>>of(),
      aggregate(task("1", "hostA")).getAggregates());
}
 
Example #24
Source File: AttributeAggregate.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static AttributeAggregate create(Supplier<Iterable<IAttribute>> attributes) {
  Supplier<Multiset<Pair<String, String>>> aggregator = Suppliers.compose(
      attributes1 -> addAttributes(ImmutableMultiset.builder(), attributes1).build(),
      attributes);

  return new AttributeAggregate(aggregator);
}
 
Example #25
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableMultiset construct(int entries) {
  ImmutableMultiset.Builder builder = ImmutableMultiset.builder();
  for (int i = 0; i < entries; i++) {
    builder.add(newEntry());
  }
  return builder.build();
}
 
Example #26
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableMultiset construct(int entries) {
  ImmutableMultiset.Builder builder = ImmutableMultiset.builder();
  for (int i = 0; i < entries; i++) {
    builder.add(newEntry());
  }
  return builder.build();
}
 
Example #27
Source File: ObjectGraphMeasurer.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Footprint, by specifying the number of objects,
 * references, and primitives (represented as a {@link Multiset}).
 *
 * @param objects the number of objects
 * @param references the number of references
 * @param primitives the number of primitives (represented by the
 * respective primitive classes, e.g. {@code int.class} etc)
 */
public Footprint(int objects, int references, Multiset<Class<?>> primitives) {
  Preconditions.checkArgument(objects >= 0, "Negative number of objects");
  Preconditions.checkArgument(references >= 0, "Negative number of references");
  Preconditions.checkArgument(primitiveTypes.containsAll(primitives.elementSet()),
  "Unexpected primitive type");
  this.objects = objects;
  this.references = references;
  this.primitives = ImmutableMultiset.copyOf(primitives);
}
 
Example #28
Source File: ChaosConfig.java    From chaos-http-proxy with Apache License 2.0 5 votes vote down vote up
Properties getProperties() {
    Properties properties = new Properties();
    for (Multiset.Entry<Failure> entry :
            ImmutableMultiset.copyOf(failures).entrySet()) {
        properties.setProperty(entry.getElement().toPropertyName(),
                String.valueOf(entry.getCount()));
    }
    return properties;
}
 
Example #29
Source File: MultisetMutateMethodTest.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
@Test
public void mutateAndIterateFindsContainedElement() {
  behaviorTester
      .with(dataType)
      .with(testBuilder()
          .addLine("new DataType.Builder()")
          .addLine("    .addProperties(%s)", element.example(0))
          .addLine("    .mutateProperties(set -> {")
          .addLine("      assertThat(%s.copyOf(set.iterator())).containsExactly(%s);",
              ImmutableMultiset.class, element.example(0))
          .addLine("    });")
          .build())
      .runTest();
}
 
Example #30
Source File: ImmutableMultisetJsonDeserializer.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
@Override
protected ImmutableMultiset<T> doDeserialize( JsonReader reader, JsonDeserializationContext ctx, JsonDeserializerParameters params ) {
    try {
        currentBuilder = ImmutableMultiset.builder();
        buildCollection( reader, ctx, params );
        return currentBuilder.build();
    } finally {
        currentBuilder = null;
    }
}