Example usage for java.util Map toString

List of usage examples for java.util Map toString

Introduction

In this page you can find the example usage for java.util Map toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.deri.iris.queryrewriting.PositionDependenciesTest.java

@Test
public void testPositionDependenciesLinearCyclicMultiWay() throws Exception {

    ////from   w  w  w .  j a  v a  2s  . co  m
    // Theory:
    //
    // [R1] p(X) -> t(X,Y).
    // [R2] t(X,Y) -> s(X).
    // [R3] t(X,Y) -> t(Y,X).
    // [R4] t(X,Y) -> s(Y).
    //

    final IPredicate p = Factory.BASIC.createPredicate("p", 1);
    final IPredicate t = Factory.BASIC.createPredicate("t", 2);
    final IPredicate s = Factory.BASIC.createPredicate("s", 1);

    final ILiteral px = Factory.BASIC.createLiteral(true, p, tupleX);
    final ILiteral txy = Factory.BASIC.createLiteral(true, t, tupleXY);
    final ILiteral tyx = Factory.BASIC.createLiteral(true, t, tupleYX);
    final ILiteral sx = Factory.BASIC.createLiteral(true, s, tupleX);
    final ILiteral sy = Factory.BASIC.createLiteral(true, s, tupleY);

    // Input structure
    final List<ILiteral> h1 = new LinkedList<ILiteral>();
    final List<ILiteral> b1 = new LinkedList<ILiteral>();
    b1.add(px);
    h1.add(txy);

    final List<ILiteral> h2 = new LinkedList<ILiteral>();
    final List<ILiteral> b2 = new LinkedList<ILiteral>();
    b2.add(txy);
    h2.add(sx);

    final List<ILiteral> h3 = new LinkedList<ILiteral>();
    final List<ILiteral> b3 = new LinkedList<ILiteral>();
    b3.add(txy);
    h3.add(tyx);

    final List<ILiteral> h4 = new LinkedList<ILiteral>();
    final List<ILiteral> b4 = new LinkedList<ILiteral>();
    b4.add(txy);
    h4.add(sy);

    final IRule r1 = Factory.BASIC.createRule(h1, b1);
    final IRule r2 = Factory.BASIC.createRule(h2, b2);
    final IRule r3 = Factory.BASIC.createRule(h3, b3);
    final IRule r4 = Factory.BASIC.createRule(h4, b4);

    final List<IRule> in = ImmutableList.of(r1, r2, r3, r4);

    //
    // Comparison Structure:
    //
    // p[1] -> p[1] {<>}
    // t[1] -> t[1] {<>}
    // t[2] -> t[2] {<>}
    // s[1] -> s[1] {<>}
    //
    // p[1] -> t[1] {<R1>}
    // t[1] -> s[1] {<R2>}
    // p[1] -> m[1] {<R3>}
    // s[1] -> m[1] {<R4>}
    //
    // t[2] -> m[1] {<R2,R4>}
    //

    final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> cmp = new HashMap<Pair<IPosition, IPosition>, Set<List<IRule>>>();

    final IPosition p1 = new Position(p.getPredicateSymbol(), 1);
    final IPosition t1 = new Position(t.getPredicateSymbol(), 1);
    final IPosition t2 = new Position(t.getPredicateSymbol(), 2);
    final IPosition s1 = new Position(s.getPredicateSymbol(), 1);

    final List<IRule> lEmpty = ImmutableList.of();
    final Set<List<IRule>> slEmpty = Sets.newHashSet();
    slEmpty.add(lEmpty);
    cmp.put(Pair.of(p1, p1), slEmpty); // p[1] -> p[1] {<>}
    cmp.put(Pair.of(t1, t1), slEmpty); // t[1] -> t[1] {<>}
    cmp.put(Pair.of(t2, t2), slEmpty); // t[2] -> t[2] {<>}
    cmp.put(Pair.of(s1, s1), slEmpty); // s[1] -> s[1] {<>}

    // p[1] -> t[1] {<R1>}
    final List<IRule> lr1 = ImmutableList.of(r1);
    final Set<List<IRule>> slr1 = Sets.newHashSet();
    slr1.add(lr1);
    cmp.put(Pair.of(p1, t1), slr1);

    // t[1] -> s[1] {<R2>}
    final List<IRule> lr2 = ImmutableList.of(r2);
    final Set<List<IRule>> slr2 = Sets.newHashSet();
    slr1.add(lr2);
    cmp.put(Pair.of(t1, s1), slr2);

    // t[1] -> t[2] {<R3>}
    // t[2] -> t[1] {<R3>}
    final List<IRule> lr3 = ImmutableList.of(r3);
    final Set<List<IRule>> slr3 = Sets.newHashSet();
    slr3.add(lr3);
    cmp.put(Pair.of(t1, t2), slr3);
    cmp.put(Pair.of(t2, t1), slr3);

    // t[2] -> s[1] {<R4>}
    final List<IRule> lr4 = ImmutableList.of(r4);
    final Set<List<IRule>> slr4 = Sets.newHashSet();
    slr4.add(lr4);
    cmp.put(Pair.of(t2, s1), slr4);

    final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> depGraph = DepGraphUtils
            .computePositionDependencyGraph(in);

    LOGGER.debug(depGraph.toString());
    System.out.println("Actual:" + depGraph.toString());
    System.out.println("Expected:" + cmp.toString());
    assertEquals(true, depGraph.equals(cmp));

}

From source file:com.apptentive.android.sdk.Apptentive.java

/**
 * Allows you to pass in third party integration details. Each integration that is supported at the time this version
 * of the SDK is published is listed below.
 * <p/>//from  w w w.j a v a 2s. c om
 * <ul>
 * <li>
 * Urban Airship push notifications
 * </li>
 * </ul>
 *
 * @param context     The Context from which this method is called.
 * @param integration The name of the integration. Integrations known at the time this SDK was released are listed below.
 * @param config      A String to String Map of key/value pairs representing all necessary configuration data Apptentive needs
 *                    to use the specific third party integration.
 */
public static void addIntegration(Context context, String integration, Map<String, String> config) {
    if (integration == null || config == null) {
        return;
    }
    CustomData integrationConfig = DeviceManager.loadIntegrationConfig(context);
    try {
        JSONObject configJson = null;
        if (!integrationConfig.isNull(integration)) {
            configJson = integrationConfig.getJSONObject(integration);
        } else {
            configJson = new JSONObject();
            integrationConfig.put(integration, configJson);
        }
        for (String key : config.keySet()) {
            configJson.put(key, config.get(key));
        }
        Log.d("Adding integration config: %s", config.toString());
        DeviceManager.storeIntegrationConfig(context, integrationConfig);
        syncDevice(context);
    } catch (JSONException e) {
        Log.e("Error adding integration: %s, %s", e, integration, config.toString());
    }
}

From source file:de.ii.xtraplatform.ogc.csw.client.CSWOperation.java

public Map<String, String> toKvp(XMLNamespaceNormalizer nsStore, CSW.VERSION version)
        throws ParserConfigurationException {

    Map<String, String> parameters = new HashMap<>();

    //if (version == null)
    //    version = CSW.VERSION._2_0_0;

    parameters.put(CSW.getWord(version, CSW.VOCABULARY.SERVICE).toUpperCase(),
            CSW.getWord(version, CSW.VOCABULARY.CSW));
    parameters.put(CSW.getWord(version, CSW.VOCABULARY.REQUEST).toUpperCase(), getOperationName(version));

    if (version != null) {
        parameters.put(CSW.getWord(version, CSW.VOCABULARY.VERSION).toUpperCase(), version.toString());
    }/* w ww  .  j  a va2  s  .  c om*/

    parameters = toKvp(parameters, nsStore, version);

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(parameters.toString());
    }

    return parameters;
}

From source file:org.codelabor.system.file.web.servlet.FileUploadServlet.java

/**
 * ? .//from w  ww  . j av  a2 s.  co  m
 * 
 * @param paramMap
 *            ? Map
 * @throws Exception
 *             
 */
protected void processParameters(Map<String, Object> paramMap) throws Exception {
    logger.debug("paramMap: {}", paramMap.toString());
}

From source file:org.apache.maven.index.FullIndexNexusIndexerTest.java

public void testSearchGroupedClasses() throws Exception {
    {/*from w  w w .ja va2 s .  c o m*/
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "com/thoughtworks/qdox", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();

        assertEquals(r.toString(), 2, r.size()); // qdox and testng

        assertTrue(r.containsKey("qdox : qdox"));
        assertTrue(r.containsKey("org.testng : testng"));
        assertEquals("qdox : qdox", r.get("qdox : qdox").getGroupKey());
        assertEquals("org.testng : testng", r.get("org.testng : testng").getGroupKey());
    }

    {
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "com.thoughtworks.qdox", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size());

        assertTrue(r.containsKey("qdox : qdox"));
        assertTrue(r.containsKey("org.testng : testng"));
        assertEquals("qdox : qdox", r.get("qdox : qdox").getGroupKey());
        assertEquals("org.testng : testng", r.get("org.testng : testng").getGroupKey());
    }

    {
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "thoughtworks", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size());
        assertTrue(r.containsKey("qdox : qdox"));
        assertTrue(r.containsKey("org.testng : testng"));
        assertEquals("qdox : qdox", r.get("qdox : qdox").getGroupKey());
        assertEquals("org.testng : testng", r.get("org.testng : testng").getGroupKey());
    }

    {
        // an implicit class name wildcard
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "Logger", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);

        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertThat(r.toString(), r.size(), is(2));

        Iterator<ArtifactInfoGroup> it = r.values().iterator();

        ArtifactInfoGroup ig1 = it.next();
        assertEquals(r.toString(), "org.slf4j", ig1.getGroupKey());

        ArtifactInfoGroup ig2 = it.next();
        assertEquals(r.toString(), "org.testng", ig2.getGroupKey());
    }

    {
        // a lower case search
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "logger", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size());

        Iterator<ArtifactInfoGroup> it = r.values().iterator();

        ArtifactInfoGroup ig1 = it.next();
        assertEquals(r.toString(), "org.slf4j", ig1.getGroupKey());

        ArtifactInfoGroup ig2 = it.next();
        assertEquals(r.toString(), "org.testng", ig2.getGroupKey());
    }

    {
        // explicit class name wildcard without terminator
        // Since 4.0 query starting with * is illegal
        // Query q = nexusIndexer.constructQuery( MAVEN.CLASSNAMES, "*.Logger", SearchType.SCORED );
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, ".Logger", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size());
        Iterator<ArtifactInfoGroup> it = r.values().iterator();
        ArtifactInfoGroup ig1 = it.next();
        assertEquals(r.toString(), "org.slf4j", ig1.getGroupKey());
        ArtifactInfoGroup ig2 = it.next();
        assertEquals(r.toString(), "org.testng", ig2.getGroupKey());
    }

    {
        // explicit class name wildcard with terminator
        // Since 4.0 query starting with * is illegal
        // Query q = nexusIndexer.constructQuery( MAVEN.CLASSNAMES, "*.Logger ", SearchType.SCORED );
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, ".Logger ", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size());
        Iterator<ArtifactInfoGroup> it = r.values().iterator();
        ArtifactInfoGroup ig1 = it.next();
        assertEquals(r.toString(), "org.slf4j", ig1.getGroupKey());
        ArtifactInfoGroup ig2 = it.next();
        assertEquals(r.toString(), "org.testng", ig2.getGroupKey());
    }

    {
        // a class name wildcard
        // Since 4.0 query starting with * is illegal
        // Query q = nexusIndexer.constructQuery( MAVEN.CLASSNAMES, "*Logger", SearchType.SCORED );
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "Logger", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);
        Map<String, ArtifactInfoGroup> r = response.getResults();
        // Results are less, since no PREFIX searches anymore!
        // assertEquals( r.toString(), 3, r.size() );
        assertEquals(r.toString(), 2, r.size());

        Iterator<ArtifactInfoGroup> it = r.values().iterator();

        // Results are less, since no PREFIX searches anymore!
        // ArtifactInfoGroup ig1 = it.next();
        // assertEquals( r.toString(), "commons-logging", ig1.getGroupKey() ); // Jdk14Logger and LogKitLogger

        ArtifactInfoGroup ig2 = it.next();
        assertEquals(r.toString(), "org.slf4j", ig2.getGroupKey());

        ArtifactInfoGroup ig3 = it.next();
        assertEquals(r.toString(), "org.testng", ig3.getGroupKey());
    }

    {
        // exact class name
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES,
                "org/apache/commons/logging/LogConfigurationException", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);

        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size()); // jcl104-over-slf4j and commons-logging
    }

    {
        // implicit class name pattern
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES,
                "org.apache.commons.logging.LogConfigurationException", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);

        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size()); // jcl104-over-slf4j and commons-logging
    }

    {
        // exact class name
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES,
                "org.apache.commons.logging.LogConfigurationException", SearchType.EXACT);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);

        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size()); // jcl104-over-slf4j and commons-logging
    }

    {
        // package name prefix
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "org.apache.commons.logging",
                SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);

        Map<String, ArtifactInfoGroup> r = response.getResults();
        assertEquals(r.toString(), 2, r.size()); // jcl104-over-slf4j and commons-logging
    }

    {
        // Since 4.0, queries cannot start with '*'
        // Query q = nexusIndexer.constructQuery( MAVEN.CLASSNAMES, "*slf4j*Logg*", SearchType.SCORED );
        Query q = nexusIndexer.constructQuery(MAVEN.CLASSNAMES, "slf4j.Logg*", SearchType.SCORED);
        GroupedSearchRequest request = new GroupedSearchRequest(q, new GAGrouping());
        GroupedSearchResponse response = nexusIndexer.searchGrouped(request);

        Map<String, ArtifactInfoGroup> r = response.getResults();
        // Error is fixed, see below
        assertEquals(r.toString(), 1, r.size());

        {
            ArtifactInfoGroup ig = r.values().iterator().next();
            ArrayList<ArtifactInfo> list1 = new ArrayList<ArtifactInfo>(ig.getArtifactInfos());
            assertEquals(r.toString(), 2, list1.size());

            ArtifactInfo ai1 = list1.get(0);
            assertEquals("org.slf4j", ai1.getGroupId());
            assertEquals("slf4j-api", ai1.getArtifactId());
            assertEquals("1.4.2", ai1.getVersion());
            ArtifactInfo ai2 = list1.get(1);
            assertEquals("org.slf4j", ai2.getGroupId());
            assertEquals("slf4j-api", ai2.getArtifactId());
            assertEquals("1.4.1", ai2.getVersion());
        }

        // this is fixed now, no more false hit
        // {
        // // This was error, since slf4j-log4j12 DOES NOT HAVE any class for this search!
        // ArtifactInfoGroup ig = r.get( "org.slf4j : slf4j-log4j12" );
        // ArrayList<ArtifactInfo> list = new ArrayList<ArtifactInfo>( ig.getArtifactInfos() );
        // assertEquals( list.toString(), 1, list.size() );
        //
        // ArtifactInfo ai = list.get( 0 );
        // assertEquals( "org.slf4j", ai.groupId );
        // assertEquals( "slf4j-log4j12", ai.artifactId );
        // assertEquals( "1.4.1", ai.version );
        // }
    }
}

From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java

@Test(dataProvider = "guardedMap")
public void toString_whenPopulated(Map<Integer, Integer> map) {
    warmUp(map, 0, 10);/*w w w  .j  a  v a2s. co m*/
    String toString = map.toString();
    for (Entry<Integer, Integer> entry : map.entrySet()) {
        assertThat(countMatches(toString, entry.toString()), is(equalTo(1)));
    }
}

From source file:org.deri.iris.queryrewriting.PositionDependenciesTest.java

@Test
public void testPositionDependenciesLinearAcyclicSingleWay() throws Exception {

    ////  w w  w.ja  v a 2s  . c  o  m
    // Theory:
    //
    // [R1] p(X) -> t(X,Y).
    // [R2] t(X,Y) -> s(Y).
    // [R3] p(X) -> m(X).
    // [R4] s(X) -> m(X).
    //

    final IPredicate p = Factory.BASIC.createPredicate("p", 1);
    final IPredicate t = Factory.BASIC.createPredicate("t", 2);
    final IPredicate s = Factory.BASIC.createPredicate("s", 1);
    final IPredicate m = Factory.BASIC.createPredicate("m", 1);
    final ILiteral px = Factory.BASIC.createLiteral(true, p, tupleX);
    final ILiteral txy = Factory.BASIC.createLiteral(true, t, tupleXY);
    final ILiteral sx = Factory.BASIC.createLiteral(true, s, tupleX);
    final ILiteral sy = Factory.BASIC.createLiteral(true, s, tupleY);
    final ILiteral mx = Factory.BASIC.createLiteral(true, m, tupleX);

    // Input structure
    final List<ILiteral> h1 = new LinkedList<ILiteral>();
    final List<ILiteral> b1 = new LinkedList<ILiteral>();
    h1.add(txy);
    b1.add(px);

    final List<ILiteral> h2 = new LinkedList<ILiteral>();
    final List<ILiteral> b2 = new LinkedList<ILiteral>();
    h2.add(sy);
    b2.add(txy);

    final List<ILiteral> h3 = new LinkedList<ILiteral>();
    final List<ILiteral> b3 = new LinkedList<ILiteral>();
    h3.add(mx);
    b3.add(px);

    final List<ILiteral> h4 = new LinkedList<ILiteral>();
    final List<ILiteral> b4 = new LinkedList<ILiteral>();
    h4.add(mx);
    b4.add(sx);

    final IRule r1 = Factory.BASIC.createRule(h1, b1);
    final IRule r2 = Factory.BASIC.createRule(h2, b2);
    final IRule r3 = Factory.BASIC.createRule(h3, b3);
    final IRule r4 = Factory.BASIC.createRule(h4, b4);

    final List<IRule> in = ImmutableList.of(r1, r2, r3, r4);

    //
    // Comparison Structure:
    //
    // p[1] -> p[1] {<>}
    // t[1] -> t[1] {<>}
    // t[2] -> t[2] {<>}
    // s[1] -> s[1] {<>}
    // m[1] -> m[1] {<>}
    //
    // p[1] -> t[1] {<R1>}
    // t[2] -> s[1] {<R2>}
    // p[1] -> m[1] {<R3>}
    // s[1] -> m[1] {<R4>}
    //
    // t[2] -> m[1] {<R2,R4>}
    //

    final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> cmp = new HashMap<Pair<IPosition, IPosition>, Set<List<IRule>>>();

    final IPosition p1 = new Position(p.getPredicateSymbol(), 1);
    final IPosition t1 = new Position(t.getPredicateSymbol(), 1);
    final IPosition t2 = new Position(t.getPredicateSymbol(), 2);
    final IPosition s1 = new Position(s.getPredicateSymbol(), 1);
    final IPosition m1 = new Position(m.getPredicateSymbol(), 1);

    final List<IRule> lEmpty = ImmutableList.of();
    final Set<List<IRule>> slEmpty = ImmutableSet.of(lEmpty);
    cmp.put(Pair.of(p1, p1), slEmpty); // p[1] -> p[1] {<>}
    cmp.put(Pair.of(t1, t1), slEmpty); // t[1] -> t[1] {<>}
    cmp.put(Pair.of(t2, t2), slEmpty); // t[2] -> t[2] {<>}
    cmp.put(Pair.of(s1, s1), slEmpty); // s[1] -> s[1] {<>}
    cmp.put(Pair.of(m1, m1), slEmpty); // m[1] -> m[1] {<>}

    final List<IRule> lr1 = ImmutableList.of(r1); // p[1] -> t[1] {<R1>}
    final Set<List<IRule>> slr1 = Sets.newHashSet();
    slr1.add(lr1);
    cmp.put(Pair.of(p1, t1), slr1);

    final List<IRule> lr2 = ImmutableList.of(r2); // t[2] -> s[1] {<R2>}
    final Set<List<IRule>> slr2 = Sets.newHashSet();
    slr2.add(lr2);
    cmp.put(Pair.of(t2, s1), slr2);

    final List<IRule> lr3 = ImmutableList.of(r3); // p[1] -> m[1] {<R3>}
    final Set<List<IRule>> slr3 = Sets.newHashSet();
    slr3.add(lr3);
    cmp.put(Pair.of(p1, m1), slr3);

    final List<IRule> lr4 = ImmutableList.of(r4); // s[1] -> m[1] {<R4>}
    final Set<List<IRule>> slr4 = Sets.newHashSet();
    slr4.add(lr4);
    cmp.put(Pair.of(s1, m1), slr4);

    final List<IRule> lr2r4 = ImmutableList.of(r2, r4); // t[2] -> m[1] {<R2,R4>}
    final Set<List<IRule>> slr2r4 = Sets.newHashSet();
    slr2r4.add(lr2r4);
    cmp.put(Pair.of(t2, m1), slr2r4);

    final Map<Pair<IPosition, IPosition>, Set<List<IRule>>> depGraph = DepGraphUtils
            .computePositionDependencyGraph(in);

    System.out.println("Actual:" + depGraph.toString());
    System.out.println("Expected:" + cmp.toString());
    LOGGER.debug(depGraph.toString());
    assertEquals(true, depGraph.equals(cmp));

}

From source file:org.ankus.mapreduce.algorithms.correlation.booleanset.CalculationBooleanSetReducer.java

@Override
protected void reduce(TextTwoWritableComparable key, Iterable<TextIntegerTwoPairsWritableComparable> values,
        Context context) throws IOException, InterruptedException {

    if (algorithmOption.equals(Constants.HAMMING_DISTACNE_FOR_BOOLEAN)) {
        int hammingDistance = 0;

        Map<String, Integer> itemID1Map = new HashMap<String, Integer>();
        Map<String, Integer> itemID2Map = new HashMap<String, Integer>();

        for (TextIntegerTwoPairsWritableComparable textIntegerPairsWritable : values) {
            itemID1Map.put(textIntegerPairsWritable.getText1().toString(),
                    textIntegerPairsWritable.getNumber1());
            itemID2Map.put(textIntegerPairsWritable.getText2().toString(),
                    textIntegerPairsWritable.getNumber2());
        }//from   w w  w  .  j  a v  a 2 s .  c o  m

        char[] item1CharArray = itemID1Map.toString().toCharArray();
        char[] item2CharArray = itemID2Map.toString().toCharArray();

        int item1CharArrayLength = item1CharArray.length;
        int item2CharArrayLength = item2CharArray.length;

        if (itemID1Map.containsValue(itemID2Map))
            hammingDistance = 0;
        if (item1CharArrayLength != item2CharArrayLength) {
            hammingDistance = -1;
        } else {
            for (int i = 0; i < item1CharArrayLength; ++i) {
                if (itemID1Map.toString().charAt(i) == itemID2Map.toString().charAt(i)) {
                    hammingDistance += 0;
                } else if (itemID1Map.toString().charAt(i) != itemID2Map.toString().charAt(i)) {
                    ++hammingDistance;
                }
            }
        }
        context.write(key, new DoubleWritable(hammingDistance));

    } else if (algorithmOption.equals(Constants.DICE_COEFFICIENT)) {
        double diceCoefficient = 0.0d;
        int size1 = 0;
        int size2 = 0;

        Map<String, Integer> itemID1Map = new HashMap<String, Integer>();
        Map<String, Integer> itemID2Map = new HashMap<String, Integer>();

        for (TextIntegerTwoPairsWritableComparable textIntegerPairsWritable : values) {
            itemID1Map.put(textIntegerPairsWritable.getText1().toString(),
                    textIntegerPairsWritable.getNumber1());
            itemID2Map.put(textIntegerPairsWritable.getText2().toString(),
                    textIntegerPairsWritable.getNumber2());

            size1 += textIntegerPairsWritable.getNumber1();
            size2 += textIntegerPairsWritable.getNumber2();
        }

        // Find the intersection, and get the number of elements in that set.
        Collection<String> intersection = CollectionUtils.intersection(itemID1Map.entrySet(),
                itemID2Map.entrySet());

        diceCoefficient = (2.0 * (float) intersection.size()) / ((float) (size1 + size2));
        context.write(key, new DoubleWritable(Double.parseDouble(String.format("%.3f%n", diceCoefficient))));

    } else if (algorithmOption.equals(Constants.JACCARD_COEFFICIENT)) {
        double jaccardCoefficient = 0.0d;
        int unionSize = 0;

        Map<String, Integer> itemID1Map = new HashMap<String, Integer>();
        Map<String, Integer> itemID2Map = new HashMap<String, Integer>();

        for (TextIntegerTwoPairsWritableComparable textIntegerPairsWritable : values) {
            itemID1Map.put(textIntegerPairsWritable.getText1().toString(),
                    textIntegerPairsWritable.getNumber1());
            itemID2Map.put(textIntegerPairsWritable.getText2().toString(),
                    textIntegerPairsWritable.getNumber2());

            if ((textIntegerPairsWritable.getNumber1() + textIntegerPairsWritable.getNumber2()) >= 1) {
                unionSize += 1;
            }
        }

        Collection<String> intersection = CollectionUtils.intersection(itemID1Map.entrySet(),
                itemID2Map.entrySet());

        jaccardCoefficient = (float) intersection.size() / (float) unionSize;
        context.write(key, new DoubleWritable(Double.parseDouble(String.format("%.3f%n", jaccardCoefficient))));
    }
}

From source file:com.github.totyumengr.minicubes.core.MiniCubeTest.java

@Test
public void test_5_2_DistinctCount_20140606() throws Throwable {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*w ww .j  av a2  s. c  o m*/
    Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
    filter.put("tradeId", Arrays.asList(
            new Integer[] { 3205, 3206, 3207, 3208, 3209, 3210, 3212, 3299, 3204, 3203, 3202, 3201, 3211 }));
    Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
    stopWatch.stop();

    Assert.assertEquals(13, distinct.size());
    Assert.assertEquals(277, distinct.get(3209).getCardinality());
    Assert.assertEquals(186, distinct.get(3211).getCardinality());
    Assert.assertEquals(464, distinct.get(3206).getCardinality());
    LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());

}

From source file:com.github.totyumengr.minicubes.core.MiniCubeTest.java

@Test
public void test_5_1_Distinct_20140606() throws Throwable {

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();/*from   w  w w  .  j  a  va  2  s  .c  o  m*/
    Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
    Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
    stopWatch.stop();

    Assert.assertEquals(210, distinct.size());
    Assert.assertEquals(3089, distinct.get(1601).getCardinality());
    Assert.assertEquals(1825, distinct.get(1702).getCardinality());
    Assert.assertEquals(2058, distinct.get(-2).getCardinality());

    LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());
}