Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:playground.wrashid.parkingSearch.ppSim.jdepSim.searchStrategies.analysis.ComparisonGarageCounts.java

public static void logOutput(LinkedList<ParkingEventDetails> parkingEventDetails, String outputFileName) {
    init();/*from  w  w w .  j av a2s .  c o m*/

    // Output file
    log.info("starting log parking events");

    String iterationFilenamePng = outputFileName + ".png";
    String iterationFilenameTxt = outputFileName + ".txt";

    HashMap<Id, ParkingOccupancyBins> parkingOccupancyBins = new HashMap<Id, ParkingOccupancyBins>();

    for (ParkingEventDetails ped : parkingEventDetails) {
        ParkingActivityAttributes parkingActivityAttributes = ped.parkingActivityAttributes;
        Id facilityId = parkingActivityAttributes.getFacilityId();
        if (mappingOfParkingNameToParkingId.values().contains(facilityId.toString())) {
            if (!parkingOccupancyBins.containsKey(facilityId)) {
                parkingOccupancyBins.put(facilityId, new ParkingOccupancyBins());
            }
            ParkingOccupancyBins parkingOccupancyBin = parkingOccupancyBins.get(facilityId);
            parkingOccupancyBin.inrementParkingOccupancy(parkingActivityAttributes.getParkingArrivalTime(),
                    parkingActivityAttributes.getParkingArrivalTime()
                            + parkingActivityAttributes.getParkingDuration());
        }
    }

    int[] sumOfSelectedParkingSimulatedCounts = new int[96];
    for (ParkingOccupancyBins pob : parkingOccupancyBins.values()) {
        for (int i = 0; i < 96; i++) {
            sumOfSelectedParkingSimulatedCounts[i] += pob.getOccupancy()[i];
        }
    }

    int numberOfColumns = 2;
    double matrix[][] = new double[96][numberOfColumns];

    for (int i = 0; i < 96; i++) {
        matrix[i][0] = sumOfSelectedParkingSimulatedCounts[i];
        matrix[i][1] = sumOfOccupancyCountsOfSelectedParkings[i];
    }

    String title = "Parking Garage Counts Comparison";
    String xLabel = "time (15min-bin)";
    String yLabel = "# of occupied parkings";
    String[] seriesLabels = new String[2];
    seriesLabels[0] = "simulated counts";
    seriesLabels[1] = "real counts";
    double[] xValues = new double[96];

    for (int i = 0; i < 96; i++) {
        xValues[i] = i / (double) 4;
    }

    GeneralLib.writeGraphic(iterationFilenamePng, matrix, title, xLabel, yLabel, seriesLabels, xValues);

    String txtFileHeader = seriesLabels[0];

    for (int i = 1; i < numberOfColumns; i++) {
        txtFileHeader += "\t" + seriesLabels[i];
    }

    GeneralLib.writeMatrix(matrix, iterationFilenameTxt, txtFileHeader);

    log.info("finished log parking events");
}

From source file:org.hfoss.posit.android.web.Communicator.java

/**
 * cleanup the item key,value pairs so that we can receive and save to the
 * internal database//from   w ww  . java2  s. c om
 * 
 * @param rMap
 */
public static void cleanupOnReceive(HashMap<String, Object> rMap) {
    rMap.put(PositDbHelper.FINDS_SYNCED, PositDbHelper.FIND_IS_SYNCED);
    rMap.put(PositDbHelper.FINDS_GUID, rMap.get("guid"));
    // rMap.put(PositDbHelper.FINDS_GUID, rMap.get("guid"));

    rMap.put(PositDbHelper.FINDS_PROJECT_ID, projectId);
    if (rMap.containsKey("add_time")) {
        rMap.put(PositDbHelper.FINDS_TIME, rMap.get("add_time"));
        rMap.remove("add_time");
    }
    if (rMap.containsKey("images")) {
        if (Utils.debug)
            Log.d(TAG, "contains image key");
        rMap.put(PositDbHelper.PHOTOS_IMAGE_URI, rMap.get("images"));
        rMap.remove("images");
    }
}

From source file:AndroidUninstallStock.java

public static LinkedHashMap<String, String> getLibFromPatternGlobalExclude(
        LinkedHashMap<String, String> liblist, LinkedList<AusInfo> section, String sectionname)
        throws IOException {
    System.out.println();//w  w w  . j a  v a2s .  c  o  m
    System.out.println("Global Exclude libraries from section (" + sectionname + "):");
    for (AusInfo info : section) {
        for (HashMap<String, String> pattern : info.exclude) {
            if (!getBoolean(pattern.get("global"))) {
                continue;
            }
            for (Map.Entry<String, String> exc : _getListFromPattern(liblist, pattern, info, "exclude: ", true)
                    .entrySet()) {
                liblist.remove(exc.getKey());
            }
        }
    }
    return liblist;
}

From source file:eu.sisob.uma.crawler.MatrixResultBuilder.java

public static void writeResultsList(File file, HashMap<String, Integer> universities_axis,
        HashMap<String, Integer> dept_axis,
        HashMap<String, HashMap<String, Map.Entry<Integer, Integer>>> resultsMatrix) {
    Map.Entry<Integer, Integer>[][] matrix = (Map.Entry<Integer, Integer>[][]) new Map.Entry[universities_axis
            .size()][dept_axis.size()];/*ww w .j a v a2s.  c  om*/
    String[] cols = new String[universities_axis.size()];
    String[] rows = new String[dept_axis.size()];

    int total_researchers = 0;
    int success_researchers = 0;

    for (String j : resultsMatrix.keySet()) {
        cols[universities_axis.get(j)] = j;
        for (String k : resultsMatrix.get(j).keySet()) {
            rows[dept_axis.get(k)] = k;
        }
    }

    for (String j : resultsMatrix.keySet()) {
        for (String k : resultsMatrix.get(j).keySet()) {
            Map.Entry<Integer, Integer> r = resultsMatrix.get(j).get(k);

            int x = universities_axis.get(j);
            int y = dept_axis.get(k);

            matrix[x][y] = r;

            success_researchers += r.getKey();
            total_researchers += r.getValue();
        }
    }

    String s = "\"UNIVERSITY\"\t\"SUBJECT\"\t\"RESEARCHERS FOUND\"\t\"TOTAL RESEARCHERS\"";
    s += "\r\n";

    try {
        FileUtils.write(file, s, "UTF-8", false);
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error("Error writing results list");
    }

    s = "";

    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix[i].length; j++) {
            if (matrix[i][j] != null) {
                s += "\"" + cols[i] + "\"\t\"" + rows[j] + "\"\t" + matrix[i][j].getKey() + "\t"
                        + matrix[i][j].getValue();
                s += "\r\n";
            }
        }

        if (s.length() > 1000) {
            try {
                FileUtils.write(file, s, "UTF-8", true);
            } catch (IOException ex) {
                ProjectLogger.LOGGER.error("Error writing matrix results");
            }
            s = "";
        }
    }

    s += "\r\nRESEARCHERS FOUND\t" + success_researchers;
    s += "\r\nNUMBER OF RESEARCHERS\t" + total_researchers;

    if (!s.equals("")) {
        try {
            FileUtils.write(file, s, "UTF-8", true);
        } catch (IOException ex) {
            ProjectLogger.LOGGER.error("Error writing matrix results");
        }
    }
}

From source file:com.clustercontrol.repository.util.FacilityTreeCache.java

private static void createFacilityTreeItemMapRecursive(FacilityTreeItem treeItem,
        HashMap<String, ArrayList<FacilityTreeItem>> facilityTreeItemMap) {

    String facilityId = treeItem.getData().getFacilityId();
    ArrayList<FacilityTreeItem> facilityTreeItemList = facilityTreeItemMap.get(facilityId);
    if (facilityTreeItemList == null) {
        facilityTreeItemList = new ArrayList<FacilityTreeItem>();
    }/*from  w  w w . j  a  va  2s  . c o m*/

    facilityTreeItemList.add(treeItem);
    facilityTreeItemMap.put(facilityId, facilityTreeItemList);

    for (FacilityTreeItem childTreeItem : treeItem.getChildren()) {
        createFacilityTreeItemMapRecursive(childTreeItem, facilityTreeItemMap);
    }
}

From source file:br.gov.lexml.server.LexMLOAIHandler.java

public static String getResult(final HashMap attributes, final HttpServletRequest request,
        final HttpServletResponse response, final Transformer serverTransformer, final HashMap serverVerbs,
        final HashMap extensionVerbs, final String extensionPath) throws Throwable {
    try {/* www. jav  a  2  s  .  c  o  m*/
        boolean isExtensionVerb = extensionPath.equals(request.getPathInfo());
        String verb = request.getParameter("verb");
        if (debug) {
            log.debug("OAIHandler.getResult: verb=>" + verb + "<");
        }
        String result;
        Class verbClass = null;
        if (isExtensionVerb) {
            verbClass = (Class) extensionVerbs.get(verb);
        } else {
            verbClass = (Class) serverVerbs.get(verb);
        }
        if (verbClass == null) {
            verbClass = (Class) attributes.get("OAIHandler.missingVerbClass");
        }
        Method construct = verbClass.getMethod("construct", new Class[] { HashMap.class,
                HttpServletRequest.class, HttpServletResponse.class, Transformer.class });
        try {
            result = (String) construct.invoke(null,
                    new Object[] { attributes, request, response, serverTransformer });
        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
        if (debug) {
            log.debug(result);
        }
        return result;
    } catch (NoSuchMethodException e) {
        throw new OAIInternalServerError(e.getMessage());
    } catch (IllegalAccessException e) {
        throw new OAIInternalServerError(e.getMessage());
    }
}

From source file:org.grameenfoundation.consulteca.utils.HttpHelpers.java

/**
 * Gets a common headers url parameter string starting with ?
 *
 * @return the url parameter string with common headers.
 *///from   w w  w . j a va  2s  .  c  o  m
public static String getCommonParameters() {
    // Add common Headers to the parameter string
    HashMap<String, String> commonHeaders = HttpHelpers.getCommonHeaders();
    String commonParameters = "";
    Set<String> keys = commonHeaders.keySet();
    Boolean isFirst = true;
    for (String key : keys) {
        if (isFirst) {
            commonParameters += "?";
            isFirst = false;
        } else {
            commonParameters += "&";
        }
        commonParameters += key + "=" + URLEncoder.encode(commonHeaders.get(key));
    }

    return commonParameters;
}

From source file:eu.sisob.uma.crawler.MatrixResultBuilder.java

public static void writeResultsMatrix(File file, HashMap<String, Integer> universities_axis,
        HashMap<String, Integer> dept_axis,
        HashMap<String, HashMap<String, Map.Entry<Integer, Integer>>> resultsMatrix) {
    Map.Entry<Integer, Integer>[][] matrix = (Map.Entry<Integer, Integer>[][]) new Map.Entry[universities_axis
            .size()][dept_axis.size()];/*from ww  w  .  j av a2  s  .com*/
    String[] cols = new String[universities_axis.size()];
    String[] rows = new String[dept_axis.size()];

    int total_researchers = 0;
    int success_researchers = 0;

    for (String j : resultsMatrix.keySet()) {
        cols[universities_axis.get(j)] = j;
        for (String k : resultsMatrix.get(j).keySet()) {
            rows[dept_axis.get(k)] = k;
        }
    }

    for (String j : resultsMatrix.keySet()) {
        for (String k : resultsMatrix.get(j).keySet()) {
            Map.Entry<Integer, Integer> r = resultsMatrix.get(j).get(k);

            int x = universities_axis.get(j);
            int y = dept_axis.get(k);

            matrix[x][y] = r;

            success_researchers += r.getKey();
            total_researchers += r.getValue();
        }
    }

    try {
        FileUtils.write(file, "RESULTS TABLE\r\n", "UTF-8", false);
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error("Error writing results matrix");
    }

    String s = "#\t";
    for (int i = 0; i < rows.length; i++) {
        s += rows[i] + "\t";
    }
    s += "\r\n";
    for (int i = 0; i < matrix.length; i++) {
        s += cols[i] + "\t";
        for (int j = 0; j < matrix[i].length; j++) {
            if (matrix[i][j] != null)
                s += matrix[i][j].getKey() + "/" + matrix[i][j].getValue() + "\t";
            else
                s += "\t";
        }
        s += "\r\n";
        if (s.length() > 1000) {
            try {
                FileUtils.write(file, s, "UTF-8", true);
            } catch (IOException ex) {
                ProjectLogger.LOGGER.error("Error writing matrix results");
            }
            s = "";
        }
    }

    if (!s.equals("")) {
        try {
            FileUtils.write(file, s, "UTF-8", true);
        } catch (IOException ex) {
            ProjectLogger.LOGGER.error("Error writing matrix results");
        }
    }

    s = "\r\nTOTAL RESEARCHER = " + total_researchers + " - RESEARCHERS WITH RESULTS: " + success_researchers;
    try {
        FileUtils.write(file, s, "UTF-8", true);
    } catch (IOException ex) {
        ProjectLogger.LOGGER.error("Error writing matrix results");
    }
}

From source file:playground.wrashid.parkingSearch.ppSim.jdepSim.searchStrategies.analysis.ComparisonGarageCounts.java

public static void logRelativeError(LinkedList<ParkingEventDetails> parkingEventDetails,
        String outputFileName) {/* w ww .  j a  va  2s . com*/
    int startIndex = 28;
    int endIndex = 76;

    Double countsScalingFactor = ZHScenarioGlobal.loadDoubleParam("ComparisonGarageCounts.countsScalingFactor");

    HashMap<Id, ParkingOccupancyBins> parkingOccupancyBins = new HashMap<Id, ParkingOccupancyBins>();

    for (ParkingEventDetails ped : parkingEventDetails) {
        ParkingActivityAttributes parkingActivityAttributes = ped.parkingActivityAttributes;
        Id facilityId = parkingActivityAttributes.getFacilityId();
        if (mappingOfParkingNameToParkingId.values().contains(facilityId.toString())) {
            if (!parkingOccupancyBins.containsKey(facilityId)) {
                parkingOccupancyBins.put(facilityId, new ParkingOccupancyBins());
            }
            ParkingOccupancyBins parkingOccupancyBin = parkingOccupancyBins.get(facilityId);
            parkingOccupancyBin.inrementParkingOccupancy(parkingActivityAttributes.getParkingArrivalTime(),
                    parkingActivityAttributes.getParkingArrivalTime()
                            + parkingActivityAttributes.getParkingDuration());
        }
    }

    HashMap<String, Double[]> occupancyOfAllSelectedParkings = SingleDayGarageParkingsCount
            .getOccupancyOfAllSelectedParkings(countsMatrix);

    List<Double> relativeErrorList = new ArrayList<Double>();

    for (String parkingName : selectedParkings) {
        Double[] occupancyBins = occupancyOfAllSelectedParkings.get(parkingName);
        double measuredOccupancySum = 0;
        for (int i = startIndex; i < endIndex; i++) {
            measuredOccupancySum += countsScalingFactor * occupancyBins[i];
        }

        Id<PParking> parkingId = Id.create(mappingOfParkingNameToParkingId.get(parkingName), PParking.class);
        ParkingOccupancyBins pob = parkingOccupancyBins.get(parkingId);

        double simulatedOccupancySum = 0;

        if (pob != null) {
            for (int i = startIndex; i < endIndex; i++) {
                simulatedOccupancySum += pob.getOccupancy()[i];
            }
        }

        double relativeError = -1;
        if (measuredOccupancySum != 0) {
            relativeError = Math.abs(simulatedOccupancySum - measuredOccupancySum) / measuredOccupancySum;
        }

        //System.out.println(parkingId + ": " +  relativeError);
        relativeErrorCounts.put(parkingId, relativeError);

        relativeErrorList.add(new Double(relativeError));
    }
    boxPlotDataSet.add(relativeErrorList, "relativeError", ZHScenarioGlobal.iteration);

    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Rel. Error - Garage Parking Counts",
            "Iteration", "rel. Error", boxPlotDataSet, false);

    int width = 500;
    int height = 300;

    try {
        ChartUtilities.saveChartAsPNG(new File(outputFileName), chart, width, height);
    } catch (IOException e) {

    }

    // print median rel. error:
    Double[] numArray = relativeErrorList.toArray(new Double[0]);
    Arrays.sort(numArray);
    double median;
    if (numArray.length % 2 == 0)
        median = (numArray[numArray.length / 2] + numArray[numArray.length / 2 + 1]) / 2;
    else
        median = numArray[numArray.length / 2];
    log.info("median rel. error:" + median);
}

From source file:com.act.reachables.Network.java

public static JSONArray get(MongoDB db, Set<Node> nodes, Set<Edge> edges) throws JSONException {
    // init the json object with structure:
    // {/*from   w  ww.  j a  v  a 2s  .co m*/
    //   "nodeMapping":[
    //     { "name":"Myriel", "group":1 }, ...
    //   ],
    //   "links":[
    //     { "source":1, "target":0, "value":1 }, ...
    //   ]
    // }
    // nodeMapping.group specifies the node color
    // links.value specifies the edge weight
    JSONArray json = new JSONArray();

    HashMap<Long, Set<Node>> treenodes = new HashMap<Long, Set<Node>>();
    HashMap<Long, Set<Edge>> treeedges = new HashMap<Long, Set<Edge>>();
    for (Node n : nodes) {
        Long k = (Long) n.getAttribute("under_root");
        if (!treenodes.containsKey(k)) {
            treenodes.put(k, new HashSet<Node>());
            treeedges.put(k, new HashSet<Edge>());
        }
        treenodes.get(k).add(n);
    }

    for (Edge e : edges) {
        Long k = (Long) e.getAttribute("under_root");
        if (!treeedges.containsKey(k)) {
            throw new RuntimeException("Fatal: Edge found rooted under a tree (under_root) that has no node!");
        }
        treeedges.get(k).add(e);
    }

    for (Long root : treenodes.keySet()) {
        JSONObject tree = new JSONObject();
        HashMap<Node, Integer> nodeOrder = new HashMap<Node, Integer>();
        tree.put("nodeMapping", nodeListObj(db, treenodes.get(root), nodeOrder /*inits this ordering*/));
        tree.put("links", edgeListObj(treeedges.get(root), nodeOrder /* uses the ordering */));

        json.put(tree);
    }

    return json;

}