java类com.google.common.collect.HashMultiset的实例源码

SpinConstructRuleTest.java 文件源码 项目:incubator-rya 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void testGeneralConsequent() throws Exception {
    String text = "CONSTRUCT {\n"
            + "  ?x ?p2 ?y"
            + "} WHERE {\n"
            + "  ?x ?p1 ?y .\n"
            + "  ?p1 rdfs:subPropertyOf ?p2 .\n"
            + "}";
    ParsedGraphQuery query = (ParsedGraphQuery) PARSER.parseQuery(text, null);
    SpinConstructRule rule = new SpinConstructRule(OWL.THING, RL_PRP_SPO1, query);
    Multiset<StatementPattern> expectedAntecedents = HashMultiset.create(Arrays.asList(
            new StatementPattern(new Var("p1"), ac(RDFS.SUBPROPERTYOF), new Var("p2")),
            new StatementPattern(new Var("x"), new Var("p1"), new Var("y"))));
    Multiset<StatementPattern> expectedConsequents = HashMultiset.create(Arrays.asList(
            new StatementPattern(new Var("subject"), new Var("predicate"), new Var("object"))));
    Assert.assertEquals(expectedAntecedents, HashMultiset.create(rule.getAntecedentPatterns()));
    Assert.assertEquals(expectedConsequents, HashMultiset.create(rule.getConsequentPatterns()));
    Assert.assertFalse(rule.hasAnonymousConsequent());
    // Basic pattern matches
    Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("a"), new Var("b"), new Var("c"))));
    // Narrower patterns match (constants in place of variables)
    Assert.assertTrue(rule.canConclude(new StatementPattern(new Var("x"), c(RDFS.SUBPROPERTYOF), c(OWL.THING))));
    Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), new Var("prop"), c(OWL.THING))));
    Assert.assertTrue(rule.canConclude(new StatementPattern(c(FOAF.PERSON), c(RDFS.SUBCLASSOF), new Var("x"))));
    Assert.assertTrue(rule.canConclude(new StatementPattern(c(OWL.NOTHING), c(RDFS.SUBCLASSOF), c(FOAF.PERSON))));
}
TestTreeBoundedSynthesis.java 文件源码 项目:angelix 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void testUniqueMultiple() {
    Multiset<Node> components = HashMultiset.create();
    components.add(x, 2);
    components.add(Library.ADD, 1);
    components.add(Library.ITE);
    components.add(BoolConst.TRUE);

    ArrayList<TestCase> testSuite = new ArrayList<>();
    Map<ProgramVariable, Node> assignment1 = new HashMap<>();
    assignment1.put(x, IntConst.of(1));
    testSuite.add(TestCase.ofAssignment(assignment1, IntConst.of(2)));

    Map<Hole, Expression> args = new HashMap<>();
    args.put((Hole) Library.ADD.getLeft(), Expression.leaf(x));
    args.put((Hole) Library.ADD.getRight(), Expression.leaf(x));
    List<Expression> forbidden = new ArrayList<>();
    forbidden.add(Expression.app(Library.ADD, args));

    Synthesis synthesizerWithForbidden =
            new Synthesis(new BoundedShape(3, forbidden), new TreeBoundedEncoder());
    Optional<Pair<Expression, Map<Parameter, Constant>>> result = synthesizerWithForbidden.synthesize(testSuite, components);
    assertFalse(result.isPresent());
}
WeightFailoverTest.java 文件源码 项目:simple-failover-java 阅读 19 收藏 0 点赞 0 评论 0
@Test
void testCommon() {
    List<String> original = Arrays.asList("1", "2", "3");
    Failover<String> failover = WeightFailover.newBuilder() //
            .checker(this::check, 1) //
            .build(original);
    Multiset<String> result = HashMultiset.create();
    Multiset<Integer> getCount = HashMultiset.create();
    for (int i = 0; i < 500; i++) {
        List<String> available = failover.getAvailable(2);
        assertTrue(available.size() <= 2);
        getCount.add(available.size());
        available.forEach(obj -> {
            assertNotNull(obj);
            if (doSomething(obj, failover)) {
                result.add(obj);
            }
        });
        sleepUninterruptibly(10, MILLISECONDS);
    }
    System.out.println(getCount);
    System.out.println(result);
}
WeightFailoverTest.java 文件源码 项目:simple-failover-java 阅读 22 收藏 0 点赞 0 评论 0
@Test
void testDown() {
    List<String> original = Arrays.asList("1", "2", "3");
    Failover<String> failover = WeightFailover.<String> newGenericBuilder() //
            .checker(it -> false, 1) //
            .onMinWeight(i -> System.out.println("onMin:" + i)) //
            .build(original);
    Multiset<String> result = HashMultiset.create();
    Multiset<Integer> getCount = HashMultiset.create();
    failover.down("1");
    for (int i = 0; i < 500; i++) {
        String available = failover.getOneAvailable();
        assertNotEquals(available, "1");
        sleepUninterruptibly(10, MILLISECONDS);
    }
    System.out.println(getCount);
    System.out.println(result);
}
WeightFailoverTest.java 文件源码 项目:simple-failover-java 阅读 24 收藏 0 点赞 0 评论 0
@Test
void testLarge() {
    Map<String, Integer> map = new HashMap<>();
    for (int i = 0; i < 108; i++) {
        map.put("i" + i, 32518);
    }
    for (int i = 0; i < 331; i++) {
        map.put("j" + i, 2652);
    }
    WeightFailover<String> failover = WeightFailover.<String> newGenericBuilder() //
            .checker(it -> true, 1) //
            .build(map);
    Multiset<String> counter = HashMultiset.create();
    for (int i = 0; i < 100000; i++) {
        String oneAvailable = failover.getOneAvailable();
        counter.add(oneAvailable.substring(0, 1));
    }
    System.out.println(counter);
}
BeProductive.java 文件源码 项目:BeProductive 阅读 22 收藏 0 点赞 0 评论 0
private void update() {
    ArrayList<UUID> onlinePlayers = new ArrayList<UUID>();
    for (Object obj : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList()) {
        EntityPlayerMP player = (EntityPlayerMP) obj;
        UUID uuid = player.getUniqueID();

        onlinePlayers.add(uuid);
        timeOnCount.add(uuid);

        //Kick players who are on too long
        if ((maxTimeOn.containsKey(uuid) && timeOnCount.count(uuid) > maxTimeOn.get(uuid)) || (maxTimeOnGlobal != 0 && timeOnCount.count(uuid) > maxTimeOnGlobal)) {
            rejoinTime.put(uuid, System.currentTimeMillis() + (breakTime.containsKey(uuid) ? breakTime.get(uuid) * 50 : breakTimeGlobal * 50));
            kickPlayerForTime(player);
            timeOnCount.remove(uuid, timeOnCount.count(uuid));
        }
    }

    //Decrease timeOnCount time for players that aren't online
    HashMultiset<UUID> uuids = HashMultiset.create();
    for (UUID entry : timeOnCount.elementSet()) {
        if (!onlinePlayers.contains(entry)) {
            uuids.add(entry);
        }
    }
    Multisets.removeOccurrences(timeOnCount, uuids);
}
TagDict.java 文件源码 项目:EasySRL 阅读 18 收藏 0 点赞 0 评论 0
private static Map<String, Collection<Category>> makeDict(final Multiset<String> wordCounts,
        final Map<String, Multiset<Category>> wordToCatToCount) {
    // Now, save off a sorted list of categories
    final Multiset<Category> countsForOtherWords = HashMultiset.create();

    final Map<String, Collection<Category>> result = new HashMap<>();
    for (final Entry<String> wordAndCount : wordCounts.entrySet()) {
        final Multiset<Category> countForCategory = wordToCatToCount.get(wordAndCount.getElement());
        if (wordAndCount.getCount() > MIN_OCCURENCES_OF_WORD) {
            // Frequent word
            addEntryForWord(countForCategory, result, wordAndCount.getElement());
        } else {
            // Group stats for all rare words together.

            for (final Entry<Category> catToCount : countForCategory.entrySet()) {
                countsForOtherWords.add(catToCount.getElement(), catToCount.getCount());
            }
        }
    }
    addEntryForWord(countsForOtherWords, result, OTHER_WORDS);

    return ImmutableMap.copyOf(result);
}
TestTreeBoundedSynthesis.java 文件源码 项目:angelix 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void testForbiddenDoubleNegation() {
    Multiset<Node> components = HashMultiset.create();
    components.add(x);
    components.add(Library.MINUS, 2);
    components.add(Library.ADD);

    ArrayList<TestCase> testSuite = new ArrayList<>();
    Map<ProgramVariable, Node> assignment1 = new HashMap<>();
    assignment1.put(x, IntConst.of(2));
    testSuite.add(TestCase.ofAssignment(assignment1, IntConst.of(2)));

    List<Expression> forbidden = new ArrayList<>();
    forbidden.add(Expression.leaf(x));

    Map<Hole, Expression> args = new HashMap<>();
    args.put((Hole) Library.MINUS.getArg(), Expression.leaf(x));
    Map<Hole, Expression> args2 = new HashMap<>();
    args2.put((Hole) Library.MINUS.getArg(), Expression.app(Library.MINUS, args));
    forbidden.add(Expression.app(Library.MINUS, args2));

    Synthesis synthesizerWithForbidden =
            new Synthesis(new BoundedShape(3, forbidden), new TreeBoundedEncoder());
    Optional<Pair<Expression, Map<Parameter, Constant>>> result = synthesizerWithForbidden.synthesize(testSuite, components);
    assertFalse(result.isPresent());
}
SolverFormulaIOTest.java 文件源码 项目:java-smt 阅读 17 收藏 0 点赞 0 评论 0
private void checkThatFunOnlyDeclaredOnce(String formDump) {
  Multiset<String> funDeclares = HashMultiset.create();

  for (String line : Splitter.on('\n').split(formDump)) {
    if (line.startsWith("(declare-fun ")) {
      funDeclares.add(line.replaceAll("\\s+", ""));
    }
  }

  // remove non-duplicates
  Iterator<Multiset.Entry<String>> it = funDeclares.entrySet().iterator();
  while (it.hasNext()) {
    if (it.next().getCount() <= 1) {
      it.remove();
    }
  }
  assertThat(funDeclares).named("duplicate function declarations").isEmpty();
}
Root.java 文件源码 项目:knowledgestore 阅读 37 收藏 0 点赞 0 评论 0
private void uiReportMentionValueOccurrences(final Map<String, Object> model,
        final URI entityID, @Nullable final URI property) throws Throwable {

    // Do nothing in case the entity ID is missing
    if (entityID == null || property == null) {
        return;
    }

    // Compute the # of occurrences of all the values of the given property in entity mentions
    final Multiset<Value> propertyValues = HashMultiset.create();
    for (final Record mention : getEntityMentions(entityID, Integer.MAX_VALUE, null)) {
        propertyValues.addAll(mention.get(property, Value.class));
    }

    // Render the table
    final Escaper esc = UrlEscapers.urlFormParameterEscaper();
    final String linkTemplate = "ui?action=entity-mentions&entity="
            + esc.escape(entityID.stringValue()) + "&property="
            + esc.escape(Data.toString(property, Data.getNamespaceMap()))
            + "&value=${element}";
    model.put("valueOccurrencesTable", RenderUtils.renderMultisetTable(new StringBuilder(),
            propertyValues, "Property value", "# Mentions", linkTemplate));
}


问题


面经


文章

微信
公众号

扫码关注公众号