Example usage for java.util HashMap size

List of usage examples for java.util HashMap size

Introduction

In this page you can find the example usage for java.util HashMap size.

Prototype

int size

To view the source code for java.util HashMap size.

Click Source Link

Document

The number of key-value mappings contained in this map.

Usage

From source file:com.hangum.tadpole.engine.sql.util.tables.SQLResultFilter.java

@SuppressWarnings("unchecked")
@Override//from  w w w . j  a  v  a  2  s .  c o m
public boolean select(Viewer viewer, Object parentElement, Object element) {
    HashMap<Integer, Object> model = (HashMap<Integer, Object>) element;

    if (filter.equals("*") || filter.equals("")) //$NON-NLS-1$//$NON-NLS-2$
        return true;

    if (filter.indexOf("=") == -1) { //  ? . //$NON-NLS-1$
        for (int i = 0; i < model.size(); i++) {
            String tmp = model.get(i) == null ? "" : model.get(i).toString();
            String key = (tmp).toLowerCase();

            if (!"".equals(key)) { //$NON-NLS-1$
                if (key.matches(".*" + filter.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                    return true;
            }
        }

    } else { //  ? or .
        String[] baseArray = filter.split(","); //$NON-NLS-1$
        for (String baseTmp : baseArray) {
            try {
                String[] searchFillText = baseTmp.split("="); //$NON-NLS-1$
                String columnName = ("" + searchFillText[0]).toLowerCase(); //$NON-NLS-1$
                String searchText = searchFillText.length == 2 ? (StringUtils.trimToEmpty(searchFillText[1]))
                        : ""; //$NON-NLS-1$ //$NON-NLS-2$
                if ("".equals(searchText)) //$NON-NLS-1$
                    return false;

                int index = tableToHeaderInfo.get(columnName);
                String key = (model.get(index) == null ? "" : model.get(index).toString()).toLowerCase();

                if (!"".equals(key)) { //$NON-NLS-1$
                    if (key.matches(".*" + searchText.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                        return true;
                }

            } catch (Exception e) {
                return false;
            }
        }
    }

    return false;
}

From source file:com.hangum.tadpole.util.tables.SQLResultFilter.java

@SuppressWarnings("unchecked")
@Override//  w  w w  . j  av  a  2s.c  o  m
public boolean select(Viewer viewer, Object parentElement, Object element) {
    HashMap<Integer, String> model = (HashMap<Integer, String>) element;

    if (filter.equals("*") || filter.equals("")) //$NON-NLS-1$//$NON-NLS-2$
        return true;

    if (filter.indexOf("=") == -1) { //  ? . //$NON-NLS-1$
        for (int i = 0; i < model.size(); i++) {
            String tmp = model.get(i) == null ? "" : model.get(i);
            String key = (tmp).toLowerCase();

            if (!"".equals(key)) { //$NON-NLS-1$
                if (key.matches(".*" + filter.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                    return true;
            }
        }

    } else { //  ? or .
        String[] baseArray = filter.split(","); //$NON-NLS-1$
        for (String baseTmp : baseArray) {
            try {
                String[] searchFillText = baseTmp.split("="); //$NON-NLS-1$
                String columnName = ("" + searchFillText[0]).toLowerCase(); //$NON-NLS-1$
                String searchText = searchFillText.length == 2 ? (StringUtils.trimToEmpty(searchFillText[1]))
                        : ""; //$NON-NLS-1$ //$NON-NLS-2$
                if ("".equals(searchText)) //$NON-NLS-1$
                    return false;

                int index = tableToHeaderInfo.get(columnName);
                String key = (model.get(index)).toLowerCase();

                if (!"".equals(key)) { //$NON-NLS-1$
                    if (key.matches(".*" + searchText.toLowerCase() + ".*")) //$NON-NLS-1$//$NON-NLS-2$
                        return true;
                }

            } catch (Exception e) {
                return false;
            }
        }
    }

    return false;
}

From source file:com.tacitknowledge.util.migration.DistributedJdbcMigrationLauncherFactoryTest.java

/**
 * Test the configuration of the launchers versus a known property file
 *///from www .  j a  v a 2  s.  c  o m
public void testDistributedLauncherConfiguration() {
    HashMap controlledSystems = ((DistributedMigrationProcess) launcher.getMigrationProcess())
            .getControlledSystems();
    assertEquals(3, controlledSystems.size());
}

From source file:com.bayesforecast.ingdat.vigsteps.vigmake.VigMakeStep.java

private void emitTree() {
    //VigMakeStepMeta meta = (VigMakeStepMeta) this.getStepMetaInterface(); 
    VigMakeStepData data = (VigMakeStepData) this.getStepDataInterface();

    Set<Date> processedDates = data.processedDates.keySet();
    HashMap<List<Object>, Item> items = data.items;

    logBasic("Fechas procesadas: " + processedDates.size());
    logBasic("Items procesados: " + items.size());

    for (Item item : items.values()) {
        data.stateInsertionAlgo.markAbsences(item, processedDates);
        data.stateInsertionAlgo.cleanStates(item);
        emitItem(data, item, true);/*from ww w . jav  a  2  s . c o  m*/
    }

}

From source file:controller.Parser.java

static LP parse(File f) throws FileNotFoundException {
    Scanner s = new Scanner(f);
    Pattern p = Pattern.compile(dvarreg);

    HashMap<String, Integer> x = new HashMap<String, Integer>();
    HashMap<Integer, String> xReverse = new HashMap<Integer, String>();
    int xcol = 0;

    /* Get input size and names of the decision variables. */
    int constraints = -1; // Take the objective function into account.
    while (s.hasNextLine()) {
        String line = s.nextLine();

        if (line.trim().equals(""))
            continue;

        /* /*from w  w w.j  a va2  s  . com*/
         * TODO: Beware, will now accept invalid
         * files with multiple objective functions.
         */
        /*            if (!validConstraint(line) && !validObj(line)) {
        String e = "Unsupported format in file " + f;
        throw new IllegalArgumentException(e);
                    } */

        Matcher m = p.matcher(line);

        while (m.find()) {
            String var = m.group(3);
            if (validVarName(var) && !x.containsKey(var)) {
                x.put(var, xcol);
                xReverse.put(xcol++, var);
            }
        }
        constraints++;
    }

    BigFraction[][] Ndata = new BigFraction[constraints][x.size()];
    for (int i = 0; i < Ndata.length; i++) {
        Arrays.fill(Ndata[i], BigFraction.ZERO);
    }
    BigFraction[] bdata = new BigFraction[constraints];
    BigFraction[] cdata = new BigFraction[x.size()];
    Arrays.fill(cdata, BigFraction.ZERO);

    s = new Scanner(f);

    String obj = s.nextLine();
    Matcher m = p.matcher(obj);

    while (m.find()) {
        String var = m.group(3);
        if (!x.containsKey(var))
            continue;

        String sign = m.group(1);
        if (sign == null)
            sign = "+";

        String coeffStr = m.group(2);
        BigFraction coeff;
        if (coeffStr == null) {
            coeff = BigFraction.ONE;
        } else {
            coeff = new BigFraction(Double.parseDouble(coeffStr));
        }
        if (sign.equals("-"))
            coeff = coeff.negate();

        cdata[x.get(var)] = coeff;
    }

    int row = 0;
    while (s.hasNextLine()) {
        String line = s.nextLine();
        String[] split = line.split("<=");
        if (line.trim().equals(""))
            continue;
        if (split.length != 2) {
            String e = "Unsupported format in file " + f;
            throw new IllegalArgumentException(e);
        }
        m = p.matcher(line);
        bdata[row] = new BigFraction(Double.parseDouble(split[1]));

        while (m.find()) {
            String var = m.group(3);
            if (!x.containsKey(var))
                continue;

            String sign = m.group(1);
            if (sign == null)
                sign = "+";

            String coeffStr = m.group(2);
            BigFraction coeff;
            if (coeffStr == null) {
                coeff = BigFraction.ONE;
            } else {
                coeff = new BigFraction(Double.parseDouble(coeffStr));
            }
            if (sign.equals("-"))
                coeff = coeff.negate();

            Ndata[row][x.get(var)] = coeff;
        }
        row++;
    }

    return new LP(new Array2DRowFieldMatrix<BigFraction>(Ndata), new ArrayFieldVector<BigFraction>(bdata),
            new ArrayFieldVector<BigFraction>(cdata), xReverse);
}

From source file:gwap.game.quiz.tools.QuizQuestionBean.java

@SuppressWarnings("unchecked")
public JSONObject generateJSONObject() {
    jsonObject = new JSONObject();
    jsonObject.put("Title", QuizGermanStemmer.stemText(artResource.getDefaultTitle()));

    jsonObject.put("Teaser", QuizGermanStemmer.stemText(getTeaser(artResource)));

    if (artResource.getLocation() != null) {
        jsonObject.put("Location", QuizGermanStemmer.stemText(artResource.getLocation()));
    } else {//w ww .  j a va2s.co  m
        jsonObject.put("Location", "");
    }

    if (artResource.getDateCreated() != null) {
        jsonObject.put("Datierung", artResource.getDateCreated());
    } else {
        jsonObject.put("Datierung", "");
    }

    if (artResource.getInstitution() != null) {
        jsonObject.put("Institution", QuizGermanStemmer.stemText(artResource.getInstitution()));
    } else {
        jsonObject.put("Institution", "");
    }

    HashMap<String, Integer> taggings = cleanUpAndGetTaggins(artResource.getTaggings());
    jsonObject.put("NumTags", taggings.size());

    int ii = 0;
    for (Entry<String, Integer> s : taggings.entrySet()) {
        if (s.getValue() > 1) {
            jsonObject.put("Tag" + ii, QuizGermanStemmer.stemText(s.getKey()));
            jsonObject.put("TagNum" + ii, s.getValue());
        }

        ii++;
    }

    jsonObject.put("A", QuizGermanStemmer.stem(answerA));
    jsonObject.put("B", QuizGermanStemmer.stem(answerB));
    jsonObject.put("C", QuizGermanStemmer.stem(answerC));
    jsonObject.put("D", QuizGermanStemmer.stem(answerD));
    jsonObject.put("CorrectAnswer", QuizGermanStemmer.stem(correctAnswer));

    if (answerA.getDeath() != null) {
        jsonObject.put("DA", answerA.getDeath().getYear() + 1900);
    } else {
        jsonObject.put("DA", Integer.parseInt(artResource.getDateCreated()) + 30);
    }
    if (answerB.getDeath() != null) {
        jsonObject.put("DB", answerB.getDeath().getYear() + 1900);
    } else {
        jsonObject.put("DB", Integer.parseInt(artResource.getDateCreated()) + 30);
    }
    if (answerC.getDeath() != null) {
        jsonObject.put("DC", answerC.getDeath().getYear() + 1900);
    } else {
        jsonObject.put("DC", Integer.parseInt(artResource.getDateCreated()) + 30);
    }
    if (answerD.getDeath() != null) {
        jsonObject.put("DD", answerD.getDeath().getYear() + 1900);
    } else {
        jsonObject.put("DD", Integer.parseInt(artResource.getDateCreated()) + 30);
    }

    jsonObject.put("URL", artResource.getUrl().split("image/")[1]);

    return this.jsonObject;
}

From source file:web.diva.server.unused.ProfilePlotGenerator.java

private XYLineAndShapeRenderer chartColorUpdate(XYLineAndShapeRenderer renderer, String[] colors,
        HashMap<String, Color> colorMap) {
    if (renderer == null) {
        renderer = new XYLineAndShapeRenderer();
    }//from w  ww . j  a va 2s.c  om
    renderer.setBaseShapesVisible(false);//setShapesVisible(false);
    if (colorMap.size() > 2) {
        for (int x = 0; x < colors.length; x++) {
            if (colors[x].equalsIgnoreCase("#000000")) {
                renderer.setSeriesPaint(x, Color.BLACK);
                continue;
            }
            renderer.setSeriesPaint(x, colorMap.get(colors[x]));
        }
    } else {
        renderer.setPaint(Color.BLACK);

    }
    return renderer;

}

From source file:com.georgeme.Act_Circle.java

private void setUpMap() {
    mMap.setOnMarkerDragListener(this);
    mMap.setOnMapLongClickListener(this);

    if (this.getIntent().getSerializableExtra("result") != null) {
        HashMap<Integer, User> result = (HashMap<Integer, User>) this.getIntent()
                .getSerializableExtra("result");
        if (result.size() == 0) {
            sampleData();/*from www.ja  v a  2s.  co m*/
        }
        for (User u : result.values()) {
            mUserLatLng.add(
                    new MapUser(new LatLng(Double.valueOf(u.getLantitude()), Double.valueOf(u.getLongitude())),
                            u.getName()));
        }
    } else {
        sampleData();
    }

    updateCenterLatLng();

    // Move the map so that it is centered on the initial circle
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mUserLatLng.get(0).marker.getPosition(), SCALE));
}

From source file:com.kenshoo.facts.FactsToJsonFileTest.java

@Test
public void writeFactsFileAndOverrideIt() throws Exception {
    HashMap<String, String> props = new HashMap<String, String>();
    props.put("Dog", "Labrador");
    props.put("Cat", "Lion");

    Set<String> obfuscateEntities = new HashSet<String>();
    obfuscateEntities.add("Fish");
    factsToJsonFile = prepareMock(props, obfuscateEntities);
    factsToJsonFile.toJsonFileFromMapFacts(props, FACTS_JSON_FILE_NAME, obfuscateEntities);

    props.clear();/*ww  w  .j  a va  2 s. c o  m*/
    props.put("Fish", "Jawless");
    props.put("Monkey", "Gorilla");
    props.put("Snake", "Mamba");

    File factsFile = factsToJsonFile.toJsonFileFromMapFacts(props, FACTS_JSON_FILE_NAME, obfuscateEntities);
    String jsonFacts = FileUtils.readFileToString(factsFile);
    HashMap<String, String> factsFromFile = new Gson().fromJson(jsonFacts, HashMap.class);

    Assert.assertEquals("Facts file is not same as expected", factsFile,
            new File(FACTS_LOCATION, FACTS_JSON_FILE_NAME + FactsToJsonFile.JSON_FILE_EXTENSION));
    Assert.assertEquals("Number of facts got from file is wrong", factsFromFile.size(), 3);
    Assert.assertEquals("Number of facts got from file is wrong", factsFromFile.size(), 3);
    Assert.assertEquals("Fact is different", factsFromFile.get("Monkey"), "Gorilla");
    Assert.assertEquals("Fact is different", factsFromFile.get("Fish"), FactsToJsonFile.OBFUSCATE_VALUE);
    Assert.assertEquals("Fact is different", factsFromFile.get("Snake"), "Mamba");
    verify(factsToJsonFile, times(2)).getExternalFactsFolder();
    verify(factsToJsonFile, times(2)).toJsonFileFromMapFacts(any(HashMap.class), same(FACTS_JSON_FILE_NAME),
            same(obfuscateEntities));
}

From source file:com.nridge.core.base.io.xml.DocumentXML.java

/**
 * Saves the previous assigned document (e.g. via constructor or set method)
 * to the print writer stream wrapped in a tag name specified in the parameter.
 *
 * @param aPW            PrintWriter stream instance.
 * @param aParentTag     Parent tag name.
 * @param aDocument      Document instance.
 * @param anIndentAmount Indentation count.
 *
 * @throws java.io.IOException I/O related exception.
 *//*from  w w w.j a  va2 s.c  o m*/
public void save(PrintWriter aPW, String aParentTag, Document aDocument, int anIndentAmount)
        throws IOException {
    RelationshipXML relationshipXML;
    String docType = StringUtils.remove(aDocument.getType(), StrUtl.CHAR_SPACE);
    String parentTag = StringUtils.remove(aParentTag, StrUtl.CHAR_SPACE);

    IOXML.indentLine(aPW, anIndentAmount);
    if (StringUtils.isNotEmpty(aParentTag))
        aPW.printf("<%s-%s", parentTag, docType);
    else
        aPW.printf("<%s", docType);
    if (!mIsSimple) {
        IOXML.writeAttrNameValue(aPW, "type", aDocument.getType());
        IOXML.writeAttrNameValue(aPW, "name", aDocument.getName());
        IOXML.writeAttrNameValue(aPW, "title", aDocument.getTitle());
        IOXML.writeAttrNameValue(aPW, "schemaVersion", aDocument.getSchemaVersion());
    }
    for (Map.Entry<String, String> featureEntry : aDocument.getFeatures().entrySet())
        IOXML.writeAttrNameValue(aPW, featureEntry.getKey(), featureEntry.getValue());
    aPW.printf(">%n");
    DataTableXML dataTableXML = new DataTableXML(aDocument.getTable());
    dataTableXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues);
    dataTableXML.save(aPW, IO.XML_TABLE_NODE_NAME, anIndentAmount + 1);
    if (aDocument.relationshipCount() > 0) {
        ArrayList<Relationship> docRelationships = aDocument.getRelationships();
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("<%s>%n", IO.XML_RELATED_NODE_NAME);
        for (Relationship relationship : docRelationships) {
            relationshipXML = new RelationshipXML(relationship);
            relationshipXML.setSaveFieldsWithoutValues(mSaveFieldsWithoutValues);
            relationshipXML.save(aPW, IO.XML_RELATIONSHIP_NODE_NAME, anIndentAmount + 2);
        }
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("</%s>%n", IO.XML_RELATED_NODE_NAME);
    }
    HashMap<String, String> docACL = aDocument.getACL();
    if (docACL.size() > 0) {
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("<%s>%n", IO.XML_ACL_NODE_NAME);
        for (Map.Entry<String, String> aclEntry : docACL.entrySet()) {
            IOXML.indentLine(aPW, anIndentAmount + 2);
            aPW.printf("<%s", IO.XML_ACE_NODE_NAME);
            IOXML.writeAttrNameValue(aPW, "name", aclEntry.getKey());
            aPW.printf(">%s</%s>%n", StringEscapeUtils.escapeXml10(aclEntry.getValue()), IO.XML_ACE_NODE_NAME);
        }
        IOXML.indentLine(aPW, anIndentAmount + 1);
        aPW.printf("</%s>%n", IO.XML_ACL_NODE_NAME);
    }
    IOXML.indentLine(aPW, anIndentAmount);
    if (StringUtils.isNotEmpty(aParentTag))
        aPW.printf("</%s-%s>%n", parentTag, docType);
    else
        aPW.printf("</%s>%n", docType);
}