Example usage for org.apache.commons.collections4.map HashedMap HashedMap

List of usage examples for org.apache.commons.collections4.map HashedMap HashedMap

Introduction

In this page you can find the example usage for org.apache.commons.collections4.map HashedMap HashedMap.

Prototype

public HashedMap() 

Source Link

Document

Constructs a new empty map with default size and load factor.

Usage

From source file:edu.odu.cs.cs350.yellow1.ui.cli.ClI.java

/**
 * Construct a new Instance of the commandline parser
 * @param args arguments user inputed/*from w  ww.j a v a  2s .  co m*/
 */
public ClI(String[] args) {
    this.args = args;
    recievedArgutments = new HashedMap<>();
    requiredArgs = new HashSet<>();
    this.options = getOptions();
    requiredArgs.add("src");
    requiredArgs.add("mutF");
    requiredArgs.add("testSte");
    requiredArgs.add("goldOut");
}

From source file:edu.cmu.tetrad.search.IndTestConditionalGaussianLRT.java

public IndTestConditionalGaussianLRT(DataSet data, double alpha) {
    this.data = data;
    this.likelihood = new ConditionalGaussianLikelihood(data);

    nodesHash = new HashedMap<>();

    List<Node> variables = data.getVariables();

    for (int i = 0; i < variables.size(); i++) {
        nodesHash.put(variables.get(i), i);
    }//  www. j a v a2s  .  c om

    this.alpha = alpha;
}

From source file:co.rsk.peg.BridgeState.java

public Map<String, Object> stateToMap() {
    Map<String, Object> result = new HashedMap<>();
    result.put("btcTxHashesAlreadyProcessed", this.formatedAlreadyProcessedHashes());
    result.put("rskTxsWaitingForBroadcasting", this.toStringList(rskTxsWaitingForBroadcasting.keySet()));
    result.put("rskTxsWaitingForConfirmations", this.toStringList(rskTxsWaitingForConfirmations.keySet()));
    result.put("rskTxsWaitingForSignatures", this.toStringList(rskTxsWaitingForSignatures.keySet()));
    result.put("btcBlockchainBestChainHeight", this.btcBlockchainBestChainHeight);
    return result;
}

From source file:edu.cmu.tetrad.sem.LargeScaleSimulation.java

private void setupModel(int size) {
    if (alreadySetUp)
        return;/*from   w  w  w.  ja v  a2s .c  o  m*/

    Map<Node, Integer> nodesHash = new HashedMap<>();

    for (int i = 0; i < variableNodes.size(); i++) {
        nodesHash.put(variableNodes.get(i), i);
    }

    this.parents = new int[size][];
    this.coefs = new double[size][];
    this.errorVars = new double[size];
    this.means = new double[size];

    for (int i = 0; i < size; i++) {
        this.parents[i] = new int[0];
        this.coefs[i] = new double[0];
    }

    Distribution edgeCoefDist = new Split(coefLow, coefHigh);
    Distribution errorCovarDist = new Uniform(varLow, varHigh);
    Distribution meanDist = new Uniform(-1.0, 1.0);

    for (Edge edge : graph.getEdges()) {
        Node tail = Edges.getDirectedEdgeTail(edge);
        Node head = Edges.getDirectedEdgeHead(edge);

        int _tail = nodesHash.get(tail);
        int _head = nodesHash.get(head);

        int[] parents = this.parents[_head];
        int[] newParents = new int[parents.length + 1];
        System.arraycopy(parents, 0, newParents, 0, parents.length);
        newParents[newParents.length - 1] = _tail;
        double[] coefs = this.coefs[_head];
        double[] newCoefs = new double[coefs.length + 1];

        System.arraycopy(coefs, 0, newCoefs, 0, coefs.length);

        newCoefs[newCoefs.length - 1] = edgeCoefDist.nextRandom();

        this.parents[_head] = newParents;
        this.coefs[_head] = newCoefs;
    }

    if (graph instanceof TimeLagGraph) {
        TimeLagGraph lagGraph = (TimeLagGraph) graph;
        IKnowledge knowledge = getKnowledge(lagGraph); //TimeSeriesUtils.getKnowledge(lagGraph);
        List<Node> lag0 = lagGraph.getLag0Nodes();

        for (Node y : lag0) {
            List<Node> _parents = lagGraph.getParents(y);

            for (Node x : _parents) {
                List<List<Node>> similar = returnSimilarPairs(x, y, knowledge);

                int _x = variableNodes.indexOf(x);
                int _y = variableNodes.indexOf(y);
                double first = Double.NaN;

                for (int i = 0; i < parents[_y].length; i++) {
                    if (_x == parents[_y][i]) {
                        first = coefs[_y][i];
                    }
                }

                for (int j = 0; j < similar.get(0).size(); j++) {
                    int _xx = variableNodes.indexOf(similar.get(0).get(j));
                    int _yy = variableNodes.indexOf(similar.get(1).get(j));

                    for (int i = 0; i < parents[_yy].length; i++) {
                        if (_xx == parents[_yy][i]) {
                            coefs[_yy][i] = first;
                        }
                    }
                }
            }
        }
    }

    for (int i = 0; i < size; i++) {
        this.errorVars[i] = errorCovarDist.nextRandom();
        this.means[i] = meanDist.nextRandom();
    }

    alreadySetUp = true;
}

From source file:com.ethercamp.harmony.service.ContractsService.java

public boolean importContractFromExplorer(String hexAddress) throws Exception {
    final byte[] address = Hex.decode(hexAddress);
    final String explorerHost = Optional.ofNullable(blockchain.getBlockByNumber(0l))
            .map(block -> Hex.toHexString(block.getHash()))
            .flatMap(hash -> BlockchainConsts.getNetworkInfo(env, hash).getSecond())
            .orElseThrow(() -> new RuntimeException("Can't import contract for this network"));

    final String url = String.format("%s/api/v1/accounts/%s/smart-storage/export", explorerHost, hexAddress);
    log.info("Importing contract:{} from:{}", hexAddress, url);
    final JsonNode result = Unirest.get(url).asJson().getBody();

    final JSONObject resultObject = result.getObject();
    final Map<String, String> map = new HashedMap<>();
    resultObject.keySet().stream().forEach(k -> map.put((String) k, resultObject.getString((String) k)));

    contractDataService.importDictionary(address, map);

    contractCreation.put(address, longToBytesNoLeadZeroes(-2L));
    contractCreation.flush();/*from ww  w.  j  a  va  2s . co m*/
    return true;
}

From source file:org.apache.metron.stellar.dsl.functions.StringFunctionsTest.java

@Test
public void testLeftRightFills() throws Exception {
    final Map<String, Object> variableMap = new HashMap<String, Object>() {
        {/*from  w w w.  ja  v  a 2s  . c o  m*/
            put("foo", null);
            put("bar", null);
            put("notInt", "oh my");
        }
    };

    //LEFT
    Object left = run("FILL_LEFT('123','X', 10)", new HashedMap());
    Assert.assertNotNull(left);
    Assert.assertEquals(10, ((String) left).length());
    Assert.assertEquals("XXXXXXX123", (String) left);

    //RIGHT
    Object right = run("FILL_RIGHT('123','X', 10)", new HashedMap());
    Assert.assertNotNull(right);
    Assert.assertEquals(10, ((String) right).length());
    Assert.assertEquals("123XXXXXXX", (String) right);

    //INPUT ALREADY LENGTH
    Object same = run("FILL_RIGHT('123','X', 3)", new HashedMap());
    Assert.assertEquals(3, ((String) same).length());
    Assert.assertEquals("123", (String) same);

    //INPUT BIGGER THAN LENGTH
    Object tooBig = run("FILL_RIGHT('1234567890','X', 3)", new HashedMap());
    Assert.assertEquals(10, ((String) tooBig).length());
    Assert.assertEquals("1234567890", (String) tooBig);

    //NULL VARIABLES
    boolean thrown = false;
    try {
        run("FILL_RIGHT('123',foo,bar)", variableMap);
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("are both required"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // NULL LENGTH
    try {
        run("FILL_RIGHT('123','X',bar)", variableMap);
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("are both required"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // NULL FILL
    try {
        run("FILL_RIGHT('123',foo, 7)", variableMap);
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("are both required"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // NON INTEGER LENGTH
    try {
        run("FILL_RIGHT('123','X', 'z' )", new HashedMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("not a valid Integer"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // EMPTY STRING PAD
    try {
        Object returnValue = run("FILL_RIGHT('123','', 10 )", new HashedMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("cannot be an empty"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    //MISSING LENGTH PARAMETER
    try {
        run("FILL_RIGHT('123',foo)", variableMap);
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("expects three"));
    }
    Assert.assertTrue(thrown);
}

From source file:org.apache.metron.stellar.dsl.functions.StringFunctionsTest.java

/**
 * CHOMP StringFunction/*from www. j av  a 2  s  . co  m*/
 *
 * @throws Exception
 */
@Test
public void testChomp() throws Exception {
    Assert.assertEquals("abc", run("CHOMP('abc')", new HashedMap()));
    Assert.assertEquals("abc", run("CHOMP(msg)", ImmutableMap.of("msg", "abc\r\n")));
    Assert.assertEquals("", run("CHOMP(msg)", ImmutableMap.of("msg", "\n")));
    Assert.assertEquals("", run("CHOMP('')", new HashedMap()));
    Assert.assertEquals(null, run("CHOMP(null)", new HashedMap()));

    // No input
    boolean thrown = false;
    try {
        run("CHOMP()", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("missing argument"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Variable missing
    try {
        run("CHOMP(msg)", new HashedMap());
    } catch (ParseException pe) {
        thrown = true;
    }
    thrown = false;

    // Integer input
    try {
        run("CHOMP(123)", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("cannot be cast"));
    }
    Assert.assertTrue(thrown);

}

From source file:org.apache.metron.stellar.dsl.functions.StringFunctionsTest.java

/**
 * CHOP StringFunction//from w w w  . j av  a2 s.  c o m
 *
 * @throws Exception
 */
@Test
public void testChop() throws Exception {
    Assert.assertEquals("ab", run("CHOP('abc')", new HashedMap()));
    Assert.assertEquals(null, run("CHOP(null)", new HashedMap()));
    Assert.assertEquals("abc", run("CHOP(msg)", ImmutableMap.of("msg", "abc\r\n")));
    Assert.assertEquals("", run("CHOP(msg)", ImmutableMap.of("msg", "")));
    Assert.assertEquals("", run("CHOP(msg)", ImmutableMap.of("msg", "\n")));
    Assert.assertEquals("", run("CHOP('')", new HashedMap()));

    // No input
    boolean thrown = false;
    try {
        run("CHOP()", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("missing argument"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Variable missing
    try {
        run("CHOMP(msg)", new HashedMap());
    } catch (ParseException pe) {
        thrown = true;
    }
    thrown = false;

    // Integer input
    try {
        run("CHOP(123)", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("cannot be cast"));
    }
    Assert.assertTrue(thrown);

}

From source file:org.apache.metron.stellar.dsl.functions.StringFunctionsTest.java

/**
 * PREPEND_IF_MISSING StringFunction//  w  w  w. j  a  v a 2s . com
 */
@Test
public void testPrependIfMissing() throws Exception {
    Assert.assertEquals("xyzabc", run("PREPEND_IF_MISSING('abc', 'xyz')", new HashedMap()));
    Assert.assertEquals("xyzXYZabc", run("PREPEND_IF_MISSING('XYZabc', 'xyz', 'mno')", new HashedMap()));
    Assert.assertEquals("mnoXYZabc", run("PREPEND_IF_MISSING('mnoXYZabc', 'xyz', 'mno')", new HashedMap()));
    Assert.assertEquals(null, run("PREPEND_IF_MISSING(null, null, null)", new HashedMap()));
    Assert.assertEquals("xyz", run("PREPEND_IF_MISSING('', 'xyz', null)", new HashedMap()));

    // No input
    boolean thrown = false;
    try {
        run("PREPEND_IF_MISSING()", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("incorrect arguments"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Incorrect number of arguments - 1
    try {
        run("PREPEND_IF_MISSING('abc')", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("incorrect arguments"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Incorrect number of arguments - 2
    try {
        run("PREPEND_IF_MISSING('abc', 'def', 'ghi', 'jkl')", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("incorrect arguments"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Integer input
    try {
        run("PREPEND_IF_MISSING(123, 'abc')", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("cannot be cast"));
    }
    Assert.assertTrue(thrown);

}

From source file:org.apache.metron.stellar.dsl.functions.StringFunctionsTest.java

/**
 * APPEND_IF_MISSING StringFunction/*from   ww w .j a va2s .c  o  m*/
 */
@Test
public void testAppendIfMissing() throws Exception {
    Assert.assertEquals("apachemetron", run("APPEND_IF_MISSING('apache', 'metron')", new HashedMap()));
    Assert.assertEquals("abcXYZxyz", run("APPEND_IF_MISSING('abcXYZ', 'xyz', 'mno')", new HashedMap()));
    Assert.assertEquals(null, run("APPEND_IF_MISSING(null, null, null)", new HashedMap()));
    Assert.assertEquals("xyz", run("APPEND_IF_MISSING('', 'xyz', null)", new HashedMap()));

    // No input
    boolean thrown = false;
    try {
        run("APPEND_IF_MISSING()", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("incorrect arguments"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Incorrect number of arguments - 1
    try {
        run("APPEND_IF_MISSING('abc')", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("incorrect arguments"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Incorrect number of arguments - 2
    try {
        run("APPEND_IF_MISSING('abc', 'def', 'ghi', 'jkl')", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("incorrect arguments"));
    }
    Assert.assertTrue(thrown);
    thrown = false;

    // Integer input
    try {
        run("APPEND_IF_MISSING(123, 'abc')", Collections.emptyMap());
    } catch (ParseException pe) {
        thrown = true;
        Assert.assertTrue(pe.getMessage().contains("cannot be cast"));
    }
    Assert.assertTrue(thrown);

}