Example usage for java.util LinkedHashMap size

List of usage examples for java.util LinkedHashMap size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

Usage

From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java

@SuppressWarnings("unchecked")
public void testClone() {
    LinkedHashMap<String, String> srcMap = new LinkedHashMap<String, String>();
    checkEmptyLinkedHashMapAssumptions(srcMap);

    // Check empty clone behavior
    LinkedHashMap<String, String> dstMap = (LinkedHashMap<String, String>) srcMap.clone();
    assertNotNull(dstMap);//from   ww w .j  a v a2 s  .  c o  m
    assertEquals(dstMap.size(), srcMap.size());
    assertEquals(dstMap.keySet().toArray(), srcMap.keySet().toArray());
    assertEquals(dstMap.entrySet().toArray(), srcMap.entrySet().toArray());

    // Check non-empty clone behavior
    srcMap.put(KEY_1, VALUE_1);
    srcMap.put(KEY_2, VALUE_2);
    srcMap.put(KEY_3, VALUE_3);
    srcMap.put(KEY_4, VALUE_4);
    dstMap = (LinkedHashMap<String, String>) srcMap.clone();
    assertNotNull(dstMap);
    assertEquals(dstMap.size(), srcMap.size());
    assertEquals(dstMap.keySet().toArray(), srcMap.keySet().toArray());
    assertEquals(dstMap.entrySet().toArray(), srcMap.entrySet().toArray());
}

From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java

private Iterator<Map.Entry<Number, Object>> iterateThrough(final LinkedHashMap<Number, Object> expected) {
    Iterator<Map.Entry<Number, Object>> iter = expected.entrySet().iterator();
    for (int i = 0; i < expected.size(); i++) {
        iter.next();//from   ww w. ja  v a2  s.co m
    }
    return iter;
}

From source file:fingerprint.MyStructureFingerprint.java

public void computePercentageAndHistogram(MyChainIfc peptide, int splittedSequenceLength) {

    splittedPercentageOccupied = new ArrayList<>();
    splittedHistogramD2OccupiedSolidAngle = new ArrayList<>();

    // i want to compute the distribution according to peptide
    // but it is a list now for each and every segment of the used length in the DockingPeptide algo

    // it can be for the query which might be longer than splittedsequeceLength

    // it can be for the splitted peptide and then it is gonna be the same length

    System.out.println("solid angle peptide length = " + peptide.getMyMonomers().length);

    // if it is of the same size then I do the job
    // get the barycenter of the peptide

    if (peptide.getMyMonomers().length == splittedSequenceLength) {
        List<PointIfc> pointsPeptide = PointsTools.createListOfPointIfcFromPeptide(peptide);
        PointIfc barycenter = ShapeReductorTools.computeLigandBarycenter(pointsPeptide);

        LinkedHashMap<PhiThetaInterval, List<PointIfc>> groupedResidues = groupResiduesAccordingToSolidAngleAccordingToLocalStructureBarycenter(
                barycenter, myStructure);
        int countOccupied = 0;
        for (Entry<PhiThetaInterval, List<PointIfc>> entry : groupedResidues.entrySet()) {
            if (entry.getValue().size() > 0) {
                countOccupied += 1;/*from  w  w  w . j  ava  2 s . c om*/
            }
        }
        double percentageOccupied = (double) countOccupied / groupedResidues.size();
        List<Integer> histogramD2OccupiedSolidAngle = computeHistogramD2(groupedResidues);
        splittedPercentageOccupied.add(percentageOccupied);
        splittedHistogramD2OccupiedSolidAngle.add(histogramD2OccupiedSolidAngle);
    } else {

        // remember that the docking peptide class which is using this is docking the peptide chain bound to it already in the structure
        for (int i = 0; i < peptide.getMyMonomers().length; i++) {

            int startId = i;
            int endId = i + splittedSequenceLength;
            if (endId < peptide.getMyMonomers().length + 1) {

                // I need to schrink myStructure to the env of this subpeptide
                StructureLocalToBuildAnyShape structureLocalToBuildAnyShape = null;
                try {
                    structureLocalToBuildAnyShape = new StructureLocalToBuildAnyShape(myStructure,
                            peptide.getChainId(), startId, splittedSequenceLength, algoParameters);
                } catch (ShapeBuildingException e) {
                    continue;
                }
                MyStructureIfc myStructureLocal = structureLocalToBuildAnyShape.getMyStructureLocal();
                if (myStructureLocal == null) {
                    continue;
                }

                // makes the subPeptide barycenter
                MyChainIfc subPeptide = peptide.makeSubchain(startId, splittedSequenceLength);
                List<PointIfc> pointsPeptide = PointsTools.createListOfPointIfcFromPeptide(subPeptide);
                PointIfc barycenter = ShapeReductorTools.computeLigandBarycenter(pointsPeptide);

                LinkedHashMap<PhiThetaInterval, List<PointIfc>> groupedResidues = groupResiduesAccordingToSolidAngleAccordingToLocalStructureBarycenter(
                        barycenter, myStructureLocal);
                int countOccupied = 0;
                for (Entry<PhiThetaInterval, List<PointIfc>> entry : groupedResidues.entrySet()) {
                    if (entry.getValue().size() > 0) {
                        countOccupied += 1;
                    }
                }
                double percentageOccupied = (double) countOccupied / groupedResidues.size();
                List<Integer> histogramD2OccupiedSolidAngle = computeHistogramD2(groupedResidues);
                splittedPercentageOccupied.add(percentageOccupied);
                splittedHistogramD2OccupiedSolidAngle.add(histogramD2OccupiedSolidAngle);
            }
        }
    }
}

From source file:com.sillelien.dollar.api.types.DollarMap.java

@NotNull
@Override//from w w w. j  a  v a 2s . c o m
public var $plus(@NotNull var rhs) {
    var rhsFix = rhs._fixDeep();
    if (rhsFix.map()) {
        LinkedHashMap<var, var> copy = copyMap();
        copy.putAll(rhsFix.toVarMap().mutable());
        return DollarFactory.wrap(new DollarMap(errors(), copy));
    } else if (rhsFix.string()) {
        return DollarFactory.fromValue(toHumanString() + rhsFix.toHumanString(), errors(), rhsFix.errors());
    } else {
        LinkedHashMap<var, var> copy = copyMap();
        copy.put(DollarFactory.fromValue("_" + copy.size()), rhsFix);
        return DollarFactory.wrap(new DollarMap(errors(), copy));
    }
}

From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java

/**
 * Test method for 'java.util.LinkedHashMap.size()'.
 *//*from   w ww  .j ava2s.c om*/
public void testSize() {
    LinkedHashMap<String, String> hashMap = new LinkedHashMap<String, String>();
    checkEmptyLinkedHashMapAssumptions(hashMap);

    // Test size behavior on put
    assertEquals(hashMap.size(), SIZE_ZERO);
    hashMap.put(KEY_1, VALUE_1);
    assertEquals(hashMap.size(), SIZE_ONE);
    hashMap.put(KEY_2, VALUE_2);
    assertEquals(hashMap.size(), SIZE_TWO);
    hashMap.put(KEY_3, VALUE_3);
    assertEquals(hashMap.size(), SIZE_THREE);

    // Test size behavior on remove
    hashMap.remove(KEY_1);
    assertEquals(hashMap.size(), SIZE_TWO);
    hashMap.remove(KEY_2);
    assertEquals(hashMap.size(), SIZE_ONE);
    hashMap.remove(KEY_3);
    assertEquals(hashMap.size(), SIZE_ZERO);

    // Test size behavior on putAll
    hashMap.put(KEY_1, VALUE_1);
    hashMap.put(KEY_2, VALUE_2);
    hashMap.put(KEY_3, VALUE_3);
    LinkedHashMap<String, String> srcMap = cloneLinkedHashMap(hashMap);
    hashMap.putAll(srcMap);
    assertEquals(hashMap.size(), SIZE_THREE);

    // Test size behavior on clear
    hashMap.clear();
    assertEquals(hashMap.size(), SIZE_ZERO);
}

From source file:com.google.gwt.emultest.java.util.LinkedHashMapTest.java

public void testClear() {
    LinkedHashMap<String, String> hashMap = new LinkedHashMap<String, String>();
    checkEmptyLinkedHashMapAssumptions(hashMap);

    hashMap.put("Hello", "Bye");
    assertFalse(hashMap.isEmpty());//ww  w . jav a 2 s.  c o  m
    assertTrue(hashMap.size() == SIZE_ONE);

    hashMap.clear();
    assertTrue(hashMap.isEmpty());
    assertTrue(hashMap.size() == 0);
}

From source file:gov.llnl.lc.smt.command.link.SmtLink.java

/**
 * Describe the method here//from  w w w . ja v a  2s. c o m
 *
 * @see gov.llnl.lc.smt.command.SmtCommand#doCommand(gov.llnl.lc.smt.command.config.SmtConfig)
 *
 * @param config
 * @return
 * @throws Exception
 ***********************************************************/

@Override
public boolean doCommand(SmtConfig config) throws Exception {
    // this is a Link command, and it can take a subcommand and an argument
    String subCommand = null;
    Map<String, String> map = smtConfig.getConfigMap();

    int pNum = getPortNumber(config);
    IB_Guid g = getNodeGuid(config, pNum);

    if (config != null) {
        //      config.printConfig();
        map = config.getConfigMap();
        subCommand = map.get(SmtProperty.SMT_SUBCOMMAND.getName());
        if (subCommand != null)
            logger.info(subCommand);

        // check to see if the subCommand takes any arguments or values
        if (subCommand == null) {
            subCommand = SmtProperty.SMT_HELP.getName();
        }
    }

    // attempt to identify the port
    OSM_Fabric fabric = null;
    OSM_Port p = null;
    if ((OMService != null) && (g != null)) {
        fabric = OMService.getFabric();
        p = fabric.getOSM_Port(OSM_Port.getOSM_PortKey(g.getGuid(), (short) pNum));
    }
    if (OMService == null)
        logger.severe("The service is null");

    // this is the LINK command, and it can take a subcommand and an argument
    String subCommandArg = null;
    boolean onlyMissing = false;
    boolean includeMissing = true;

    subCommandArg = map.get(subCommand);

    String oMstring = map.get(SmtProperty.SMT_ONLY_MISSING.getName());
    if ((oMstring != null) && (oMstring.startsWith("t") || (oMstring.startsWith("T"))))
        onlyMissing = true;

    String iMstring = map.get(SmtProperty.SMT_INCLUDE_MISSING.getName());
    if ((iMstring != null) && (iMstring.startsWith("f") || (iMstring.startsWith("F"))))
        includeMissing = false;

    // there should only be one subcommand (use big if statement)
    if (subCommand.equalsIgnoreCase(SmtProperty.SMT_QUERY_TYPE.getName())) {
        LinkQuery qType = LinkQuery.getByName(map.get(SmtProperty.SMT_QUERY_TYPE.getName()));

        if (qType == null) {
            logger.severe("Invalid SmtLink query option");
            subCommand = SmtProperty.SMT_HELP.getName();
            return false;
        }

        OSM_FabricDelta fd = null;
        LinkedHashMap<String, IB_Link> links = null;
        if ((OMService != null) && (g != null)) {
            fd = getOSM_FabricDelta(false);
            if (fd == null) {
                // this should not happen, but if so, can't go further
                logger.severe("Could not produce FabricDelta's, suspect corrupt file.  Try -dump");
                System.out.println("Could not produce FabricDelta's, suspect corrupt file.  Try -dump");
                System.exit(0);
            }

            fabric = fd.getFabric2();
            links = fabric.getIB_Links(g);
        }
        switch (qType) {
        case LINK_LIST:
            System.out.println(LinkQuery.describeAllQueryTypes());
            break;

        case LINK_STATUS:
            IB_Link link = IB_Link.getIB_Link(getAllLinks(), p);
            if (link != null)
                System.out.println(SmtLink.getLinkSummary(OMService, link));
            else
                showStatus();
            break;

        case LINK_LEVELS:
            showLevels();
            break;

        case LINK_ALL:
            printStringMap(IB_LinkInfo.getLinkInfoRecords(OMService, fd, true, true));
            break;

        case LINK_ACTIVE:
            printStringMap(IB_LinkInfo.getLinkInfoRecords(OMService, fd, true, false));
            break;

        case LINK_DOWN:
            printStringMap(IB_LinkInfo.getLinkInfoRecords(OMService, fd, false, true));
            break;

        case LINK_ERROR:
            printStringMap(IB_LinkInfo.getErrorLinkInfoRecords(OMService, fd));
            break;

        case LINK_SWITCHES:
            printStringMap(IB_LinkInfo.getSWLinkInfoRecords(OMService, fd, !onlyMissing, includeMissing));
            break;

        case LINK_HOSTS:
            printStringMap(IB_LinkInfo.getCALinkInfoRecords(OMService, fd, !onlyMissing, includeMissing));
            break;

        case LINK_SPEED:
            OSM_LinkSpeed ls = getLinkSpeed(config);
            dumpAllLinks(ls);
            System.exit(0);
            break;

        default:
            System.out.println("That's not an option");
            break;
        }
        System.exit(0);
    } else if (subCommand.equalsIgnoreCase(SmtProperty.SMT_STATUS.getName())) {
        showStatus();
    } else if (subCommand.equalsIgnoreCase(SmtProperty.SMT_DUMP.getName())) {
        dumpAllLinks();
    } else if (subCommand.equalsIgnoreCase(SmtProperty.SMT_LIST.getName())) {
        System.err.println("List");
    } else if (subCommand.equals(SmtProperty.SMT_QUERY_LEVEL.getName()) && subCommandArg != null) {
        Integer level = new Integer(subCommandArg);
        LinkedHashMap<String, String> lmap = IB_LinkInfo.getLinkInfoRecordsByDepth(OMService,
                getOSM_FabricDelta(false), level.intValue());
        System.out.println("Link Level " + level.intValue() + ": " + lmap.size() + " links");
        printStringMap(lmap);
    } else if (subCommand.equals(SmtProperty.SMT_STATUS.getName())) {
        showStatus();
    } else if (g == null) {
        showStatus();
    }

    if ((g != null) || (p != null)) {
        if (pNum < 1)
            printStringMap(IB_LinkInfo.getLinkInfoRecordsByGuid(g, OMService, getOSM_FabricDelta(false),
                    !onlyMissing, includeMissing));
        else
            printStringMap(IB_LinkInfo.getLinkInfoRecordsByPort(p, OMService, getOSM_FabricDelta(false)));
    }
    return true;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRInputController.java

/**
 * Table model for bottom table: starts from analysis group.
 *
 * @param analysisGroup/*  w ww.  ja va2s.  co m*/
 * @return
 */
private NonEditableTableModel createTableModel(AreaDoseResponseAnalysisGroup analysisGroup) {
    LinkedHashMap<Double, String> concentrationsMap = analysisGroup.getConcentrationsMap()
            .get(analysisGroup.getTreatmentToAnalyse());
    LinkedHashMap<PlateCondition, List<Double>> velocitiesMap = analysisGroup.getVelocitiesMap();
    //when removing all conditions
    if (velocitiesMap.isEmpty()) {
        return new NonEditableTableModel();
    }

    int maxReplicates = 0;
    for (List<Double> value : velocitiesMap.values()) {
        int replicates = value.size();
        if (replicates > maxReplicates) {
            maxReplicates = replicates;
        }
    }

    Object[][] data = new Object[velocitiesMap.size()][maxReplicates + 2];
    int i = 0;
    int controlIndex = 100;
    int rowIndex = 0;

    for (Map.Entry<PlateCondition, List<Double>> entry : velocitiesMap.entrySet()) {
        //check if this platecondition is the control, save index for table
        for (Treatment treatment : entry.getKey().getTreatmentList()) {
            if (treatment.getTreatmentType().getName().contains("ontrol")) {
                controlIndex = i;
            }
        }
        i++;

        int columnIndex = 2;
        for (Double velocity : entry.getValue()) {

            if (velocity != null && !velocity.isNaN()) {
                // round to three decimals slopes and coefficients
                Double slope = AnalysisUtils.roundThreeDecimals(velocity);
                // show in table slope + (coefficient)
                data[rowIndex][columnIndex] = slope;
            } else if (velocity == null) {
                data[rowIndex][columnIndex] = "excluded";
            } else if (velocity.isNaN()) {
                data[rowIndex][columnIndex] = "NaN";
            }

            columnIndex++;
        }
        rowIndex++;
    }

    if (controlIndex != 100) {
        data[controlIndex][0] = 0.0;
        data[controlIndex][1] = "--";
    }
    rowIndex = 0;
    //if user only selects control, the concentrationsmap is null
    if (concentrationsMap != null) {
        for (Map.Entry<Double, String> entry : concentrationsMap.entrySet()) {
            if (rowIndex >= controlIndex) {
                data[rowIndex + 1][0] = entry.getKey();
                data[rowIndex + 1][1] = entry.getValue();
            } else {
                data[rowIndex][0] = entry.getKey();
                data[rowIndex][1] = entry.getValue();
            }

            rowIndex++;
        }
    }
    // array of column names for table model
    String[] columnNames = new String[data[0].length];
    columnNames[0] = "Conc of " + analysisGroup.getTreatmentToAnalyse();
    columnNames[1] = "Unit";
    for (int x = 2; x < columnNames.length; x++) {
        columnNames[x] = "Repl " + (x - 1);
    }

    NonEditableTableModel nonEditableTableModel = new NonEditableTableModel();
    nonEditableTableModel.setDataVector(data, columnNames);
    return nonEditableTableModel;

}

From source file:Simulator.PerformanceCalculation.java

private CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    LinkedHashSet no = new LinkedHashSet();
    LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>();

    for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) {
        TraceObject traceObject = entry.getValue();

        if (wait1.get(traceObject.getSurgeonId()) == null) {
            ArrayList details = new ArrayList();
            details.add(traceObject.getWaitTime1());
            details.add(traceObject.getWaitTime2());
            wait1.put(traceObject.getSurgeonId(), details);
        } else {//  w ww.j  av  a  2s.c o m
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1());
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2());
        }

        no.add(traceObject.getSurgeonId());
    }
    String[] column = new String[no.size()];

    String series1 = "Minimum Cost";
    String series2 = "Acceptable Cost";
    String series3 = "Actual Cost";

    for (int i = 0; i < no.size(); i++) {
        column[i] = "Surgeon " + (i + 1);
    }

    LinkedHashMap<Integer, Double> average = new LinkedHashMap<>();
    for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) {
        Integer integer = entry.getKey();
        ArrayList<Double> arrayList = entry.getValue();
        double total = 0;
        for (Double double1 : arrayList) {
            total += double1;
        }
        average.put(integer, total / 600);
    }

    for (int i = 1; i <= average.size(); i++) {
        int costMin = (Configuration.minimumSurgeryTime * (wait1.get(i).size() / 2)
                * Configuration.costOfPatientWaiting);
        int costAccept = (Configuration.acceptedSurgeryTime * (wait1.get(i).size() / 2)
                * Configuration.costOfPatientWaiting);
        int actualCost = (int) Math.round(average.get(i) * Configuration.costOfPatientWaiting);

        int x = actualCost - (costAccept + costMin);
        if (x > actualCost) {
            x = actualCost;
        }
        dataset.addValue(costMin, series1, column[i - 1]);
        dataset.addValue(costAccept - costMin, series2, column[i - 1]);
        dataset.addValue(x, series3, column[i - 1]);
    }

    return dataset;
}

From source file:Simulator.PerformanceCalculation.java

public JPanel waitTime1() {
    LinkedHashSet no = new LinkedHashSet();
    LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>();

    for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) {
        TraceObject traceObject = entry.getValue();

        if (wait1.get(traceObject.getSurgeonId()) == null) {
            ArrayList details = new ArrayList();
            details.add(traceObject.getWaitTime1());
            wait1.put(traceObject.getSurgeonId(), details);
        } else {//from ww w .jav  a 2  s .c o m
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1());
        }

        no.add(traceObject.getSurgeonId());
    }
    String[] column = new String[no.size()];

    String series1 = "Wait Time 1";
    for (int i = 0; i < no.size(); i++) {
        column[i] = "Surgeon " + (i + 1);
    }

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    LinkedHashMap<Integer, Double> average = new LinkedHashMap<>();
    for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) {
        Integer integer = entry.getKey();
        ArrayList<Double> arrayList = entry.getValue();
        double total = 0;
        for (Double double1 : arrayList) {
            total += double1;
        }
        average.put(integer, total / arrayList.size());
    }

    for (int i = 1; i <= average.size(); i++) {
        dataset.addValue(Math.round(average.get(i) / 600), series1, column[i - 1]);
    }
    JFreeChart chart = ChartFactory.createBarChart("Wait Time 1", // chart title
            "Surgeon ID", // domain axis label
            "Days", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    return new ChartPanel(chart);
}