Example usage for java.util SortedMap get

List of usage examples for java.util SortedMap get

Introduction

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

Prototype

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:ListCharsets.java

static public void main(String args[]) throws Exception {
    SortedMap charsets = Charset.availableCharsets();
    Set names = charsets.keySet();
    for (Iterator e = names.iterator(); e.hasNext();) {
        String name = (String) e.next();
        Charset charset = (Charset) charsets.get(name);
        System.out.println(charset);
        Set aliases = charset.aliases();
        for (Iterator ee = aliases.iterator(); ee.hasNext();) {
            System.out.println("    " + ee.next());
        }// ww w. j  a v  a 2 s .c  o  m
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5bAgreementMeasures.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    String inputDir = args[0];/*from  w  w w .  j a  v  a 2  s  .c o  m*/

    // all annotations
    List<AnnotatedArgumentPair> allArgumentPairs = new ArrayList<>();

    Collection<File> files = IOHelper.listXmlFiles(new File(inputDir));

    for (File file : files) {
        allArgumentPairs.addAll((List<AnnotatedArgumentPair>) XStreamTools.getXStream().fromXML(file));
    }

    // for collecting the rank of n-th best worker per HIT
    SortedMap<Integer, DescriptiveStatistics> nThWorkerOnHITRank = new TreeMap<>();
    // confusion matrix wrt. gold data for each n-th best worker on HIT
    SortedMap<Integer, ConfusionMatrix> nThWorkerOnHITConfusionMatrix = new TreeMap<>();

    // initialize maps
    for (int i = 0; i < TOP_K_VOTES; i++) {
        nThWorkerOnHITRank.put(i, new DescriptiveStatistics());
        nThWorkerOnHITConfusionMatrix.put(i, new ConfusionMatrix());
    }

    for (AnnotatedArgumentPair argumentPair : allArgumentPairs) {
        // sort turker rank and their vote
        SortedMap<Integer, String> rankAndVote = new TreeMap<>();

        System.out.println(argumentPair.mTurkAssignments.size());

        for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) {
            rankAndVote.put(assignment.getTurkRank(), assignment.getValue());
        }

        String goldLabel = argumentPair.getGoldLabel();

        System.out.println(rankAndVote);

        // top K workers for the HIT
        List<String> topKVotes = new ArrayList<>(rankAndVote.values()).subList(0, TOP_K_VOTES);

        // rank of top K workers
        List<Integer> topKRanks = new ArrayList<>(rankAndVote.keySet()).subList(0, TOP_K_VOTES);

        System.out.println("Top K votes: " + topKVotes);
        System.out.println("Top K ranks: " + topKRanks);

        // extract only category (a1, a2, or equal)
        List<String> topKVotesOnlyCategory = new ArrayList<>();
        for (String vote : topKVotes) {
            String category = vote.split("_")[2];
            topKVotesOnlyCategory.add(category);
        }

        System.out.println("Top " + TOP_K_VOTES + " workers' decisions: " + topKVotesOnlyCategory);

        if (goldLabel == null) {
            System.out.println("No gold label estimate for " + argumentPair.getId());
        } else {
            // update statistics
            for (int i = 0; i < TOP_K_VOTES; i++) {
                nThWorkerOnHITConfusionMatrix.get(i).increaseValue(goldLabel, topKVotesOnlyCategory.get(i));

                // rank is +1 (we don't start ranking from zero)
                nThWorkerOnHITRank.get(i).addValue(topKRanks.get(i) + 1);
            }
        }
    }

    for (int i = 0; i < TOP_K_VOTES; i++) {
        System.out.println("n-th worker : " + (i + 1) + " -----------");
        System.out.println(nThWorkerOnHITConfusionMatrix.get(i).printNiceResults());
        System.out.println(nThWorkerOnHITConfusionMatrix.get(i));
        System.out.println("Average rank: " + nThWorkerOnHITRank.get(i).getMean() + ", stddev "
                + nThWorkerOnHITRank.get(i).getStandardDeviation());
    }

}

From source file:playground.sergioo.facilitiesGenerator2012.WorkFacilitiesGeneration.java

public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException,
        ClassNotFoundException, SQLException, NoConnectionException, BadStopException {
    ActivityFacilitiesImpl facilities;/*w ww  .j  a v  a 2s  . c  o m*/
    /*try {
       ScenarioImpl scenario = (ScenarioImpl) ScenarioUtils.createScenario(ConfigUtils.createConfig());
       new FacilitiesReaderMatsimV1(scenario).readFile(WORK_FACILITIES_FILEO);
       facilities = scenario.getActivityFacilities();
    } catch (Exception e) {*/
    if (args.length == 2) {
        SIZE = Integer.parseInt(args[0]);
        NUM_ITERATIONS = Integer.parseInt(args[1]);
    }
    SortedMap<Id<ActivityFacility>, ActivityFacility> mPAreas = new TreeMap<Id<ActivityFacility>, ActivityFacility>();
    Map<Id<ActivityFacility>, MPAreaData> dataMPAreas = new HashMap<Id<ActivityFacility>, MPAreaData>();
    Tuple<FittingCapacities, List<CentroidCluster<PointPerson>>> tuple = getFittingCapacitiesObject(mPAreas,
            dataMPAreas);
    FittingCapacities fittingCapacities = tuple.getFirst();
    List<CentroidCluster<PointPerson>> clusters = tuple.getSecond();
    MatrixND<Double> capacities = null;
    try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(CAPACITIES_FILE));
        capacities = (MatrixND<Double>) ois.readObject();
        ois.close();
    } catch (EOFException e2) {
        Runtime.getRuntime().gc();
        capacities = fittingCapacities.run(NUM_ITERATIONS);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(CAPACITIES_FILE));
        oos.writeObject(capacities);
        oos.close();
        System.out.println("Matrix written!");
    }
    Matrix3DImpl matrix = (Matrix3DImpl) capacities;
    for (int o = 0; o < matrix.getDimension(1); o++) {
        double[] center = new double[] { 0, 0 };
        for (PointPerson pointPerson : clusters.get(o).getPoints())
            for (int i = 0; i < 2; i++)
                center[i] += pointPerson.getElement(i);
        for (int i = 0; i < 2; i++)
            center[i] /= clusters.get(o).getPoints().size();
        int minStart = ((int) Math.round(((center[0] % 3600.0) / 60) / 15)) * 15;
        int minDuration = ((int) Math.round(((center[1] % 3600.0) / 60) / 15)) * 15;
        NumberFormat numberFormat = new DecimalFormat("00");
        String optionText = "w_" + numberFormat.format(Math.floor(center[0] / 3600))
                + numberFormat.format(minStart) + "_" + numberFormat.format(Math.floor(center[1] / 3600))
                + numberFormat.format(minDuration);
        OpeningTime openingTime = new OpeningTimeImpl(Math.round(center[0] / 900) * 900,
                Math.round((center[0] + center[1]) / 900) * 900);
        Iterator<ActivityFacility> mPAreaI = mPAreas.values().iterator();
        for (int f = 0; f < matrix.getDimension(0); f++) {
            ActivityFacilityImpl mPArea = (ActivityFacilityImpl) mPAreaI.next();
            MPAreaData mPAreaData = dataMPAreas.get(mPArea.getId());
            double pTCapacityFO = 0;
            for (int s = 0; s < matrix.getDimension(2); s++)
                pTCapacityFO += matrix.getElement(f, o, s);
            if (pTCapacityFO > 0) {
                ActivityOptionImpl activityOption = new ActivityOptionImpl(optionText);
                activityOption.setFacility(mPArea);
                activityOption.setCapacity(pTCapacityFO / mPAreaData.getModeShare());
                activityOption.addOpeningTime(openingTime);
                mPArea.getActivityOptions().put(activityOption.getType(), activityOption);
            }
        }
    }
    /*PrintWriter printWriter = new PrintWriter(MATRIX_AREAS_FILE);
    Iterator<MPAreaData> mPIterator = dataMPAreas.values().iterator();
    int i = 0;
    while(mPIterator.hasNext())
    printWriter.println(i+++" "+mPIterator.next().getId());
    printWriter.close();*/
    DataBaseAdmin dataBaseAux = new DataBaseAdmin(new File("./data/facilities/DataBaseAuxiliar.properties"));
    ResultSet buildingsR = dataBaseAux.executeQuery(
            "SELECT id, area_perc, no_ AS id_building, xcoord AS xcoord_bldg, ycoord AS ycoord_bldg FROM work_facilities_aux.buildings LEFT JOIN work_facilities_aux.building_perc ON FID_master = id WHERE use_for_generation = 1");
    CoordinateTransformation coordinateTransformation = TransformationFactory
            .getCoordinateTransformation(TransformationFactory.WGS84, TransformationFactory.WGS84_UTM48N);
    facilities = (ActivityFacilitiesImpl) FacilitiesUtils.createActivityFacilities();
    while (buildingsR.next()) {
        Id<ActivityFacility> areaId = Id.create(buildingsR.getString(1), ActivityFacility.class);
        ActivityFacilityImpl mPArea = (ActivityFacilityImpl) mPAreas.get(areaId);
        MPAreaData mPAreaData = dataMPAreas.get(areaId);
        ActivityFacilityImpl building = facilities.createAndAddFacility(
                Id.create(buildingsR.getString(3), ActivityFacility.class), coordinateTransformation
                        .transform(new CoordImpl(buildingsR.getDouble(4), buildingsR.getDouble(5))));
        building.setDesc(mPAreaData.getType());
        double proportion = buildingsR.getDouble(2);
        for (ActivityOption activityOptionArea : mPArea.getActivityOptions().values()) {
            double capacity = activityOptionArea.getCapacity() * proportion;
            if (capacity > 0) {
                ActivityOptionImpl activityOption = new ActivityOptionImpl(activityOptionArea.getType());
                activityOption.setFacility(building);
                activityOption.setCapacity(capacity);
                activityOption.addOpeningTime(activityOptionArea.getOpeningTimes().first());
                building.getActivityOptions().put(activityOption.getType(), activityOption);
            }
        }
    }
    //}
    for (ActivityFacility building : facilities.getFacilities().values()) {
        String minOption = "", maxOption = "";
        double minCapacity = Double.MAX_VALUE, maxCapacity = 0;
        double rawRest = 0;
        Set<String> zeroOptions = new HashSet<String>();
        for (ActivityOption activityOption : building.getActivityOptions().values()) {
            double rawCapacity = activityOption.getCapacity();
            double capacity = Math.round(rawCapacity);
            if (capacity == 0)
                zeroOptions.add(activityOption.getType());
            activityOption.setCapacity(capacity);
            if (rawCapacity < minCapacity) {
                minCapacity = rawCapacity;
                minOption = activityOption.getType();
            }
            if (rawCapacity > maxCapacity) {
                maxCapacity = rawCapacity;
                maxOption = activityOption.getType();
            }
            rawRest += rawCapacity - capacity;
        }
        double rest = Math.round(rawRest);
        if (rest > 0)
            building.getActivityOptions().get(maxOption).setCapacity(Math.round(maxCapacity) + rest);
        else
            while (rest < 0) {
                rest = Math.round(minCapacity) + rest;
                if (rest > 0)
                    building.getActivityOptions().get(minOption).setCapacity(rest);
                else {
                    building.getActivityOptions().remove(minOption);
                    if (rest < 0) {
                        minCapacity = Double.MAX_VALUE;
                        for (ActivityOption activityOption : building.getActivityOptions().values())
                            if (activityOption.getCapacity() < minCapacity) {
                                minCapacity = activityOption.getCapacity();
                                minOption = activityOption.getType();
                            }
                    }
                }
            }
        for (String zeroOption : zeroOptions)
            building.getActivityOptions().remove(zeroOption);
    }
    /*Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new MatsimNetworkReader(scenario).readFile(NETWORK_FILE);
    Network network = scenario.getNetwork();
    for(ActivityFacility building:facilities.getFacilities().values()) {
       Link nearestLink =null;
       double nearestDistance = Double.MAX_VALUE;
       for(Link link:network.getLinks().values())
    if(link.getAllowedModes().contains("car")) {
       double distance = CoordUtils.distancePointLinesegment(link.getFromNode().getCoord(), link.getToNode().getCoord(), building.getCoord());
       if(distance<nearestDistance) {
          nearestDistance = distance;
          nearestLink = link;
       }
    }
       ((ActivityFacilityImpl)building).setLinkId(nearestLink.getId());
    }*/
    new FacilitiesWriter(facilities).write(WORK_FACILITIES_FILE);
    /*createTripsTables();
    writeHierachicalClustersFile(clusterWorkActivities(getWorkActivityTimes()));
    MatrixND<Double> weights = new MatrixNDImpl<Double>(new int[]{5,4}, 0.5);
    MatrixND<Double> quantities = new MatrixNDImpl<Double>(new int[]{3,4}, 20.0);
    MatrixND<Double> proportions = new MatrixNDImpl<Double>(new int[]{5,3}, 0.3333);
    MatrixND<Double> maxs = new MatrixNDImpl<Double>(new int[]{5}, 60.0);
    new FittingCapacities(new int[]{5,3,4}, weights, quantities, proportions, maxs).run(20);*/
}

From source file:Main.java

public static <T extends Comparable, U> U getObjectSortedMap(SortedMap<T, U> map, T key) {
    if (map == null) {
        return null;
    }/*from  w w w .  jav a  2  s  .c  o  m*/
    return map.get(key);
}

From source file:Main.java

public static <T, U> U firstElement(SortedMap<T, U> m) {
    if (m == null || m.isEmpty()) {
        return null;
    }//from  www . j  a v  a2  s  . c  o m
    return m.get(m.firstKey());
}

From source file:edu.cmu.sv.modelinference.eventtool.PredictionModel.java

private static DataPointCollection computeThreshold(SortedMap<Integer, Double> threshold) {
    DataPointCollection dp = new DataPointCollection();
    for (int key : threshold.keySet()) {
        dp.add(new DataPoint(key, threshold.get(key)));
    }//ww  w.  j  a  va  2s .  co m
    return dp;
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexMaintenanceUtils.java

public static Put createIndexUpdateMultTable(final IndexSpecification indexSpec, final byte[] row,
        final SortedMap<byte[], byte[]> columnValues, byte[] indexedColumn) {
    for (byte[] col : indexSpec.getIndexedColumns()) {
        if (columnValues.get(col) != null) {

        }/*from   w  ww .j  a va 2  s.  com*/
    }

    return null;
}

From source file:org.cbioportal.mutationhotspots.mutationhotspotsdetection.HotspotMain.java

private static Collection<MutatedResidue> mutatedResiduesOnAProtein(MutatedProtein mutatedProtein,
        Set<Hotspot> hotspots, double pvalueThreahold) {
    SortedMap<Integer, MutatedResidue> map = new TreeMap<>();
    for (Hotspot hs : hotspots) {
        Set<Integer> residues = hs.getResidues();
        for (Integer r : residues) {
            MutatedResidue mutatedResidue = map.get(r);
            if (mutatedResidue == null) {
                mutatedResidue = new MutatedResidueImpl(mutatedProtein, r, pvalueThreahold);
                map.put(r, mutatedResidue);
            }//from   w  w  w.ja va 2  s. c om
            mutatedResidue.addHotspot(hs);
        }
    }
    return map.values();
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.IndexMaintenanceUtils.java

public static Put addColumnValue(final IndexSpecification indexSpec,
        final SortedMap<byte[], byte[]> columnValues, Put put) {
    try {// w w  w . j a v a2  s  . com
        for (byte[] col : indexSpec.getAdditionalColumns()) {
            byte[] val = columnValues.get(col);
            if (val != null) {
                byte[][] colSeperated = HStoreKey.parseColumn(col);
                put.add(colSeperated[0], colSeperated[1], val);
            }
        }
    } catch (ColumnNameParseException e) {
        throw new RuntimeException(e);
    }
    return put;
}

From source file:com.ai.smart.bottom.helper.MacUtils.java

public static JSONObject sort(JSONObject json) {
    Set<String> iteratorKeys = json.keySet();
    SortedMap<String, Object> map = new TreeMap<String, Object>();
    for (String str : iteratorKeys) {
        map.put(str, json.get(str));/*from ww w  . j a v  a  2s  .c o  m*/
    }
    Set<String> mapkeys = map.keySet();
    JSONObject json2 = new JSONObject();
    for (String s : mapkeys) {
        json2.put(s, map.get(s));
    }
    return json2;
}