Example usage for java.util SortedMap keySet

List of usage examples for java.util SortedMap keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:org.alfresco.mobile.android.application.editors.text.EncodingDialogFragment.java

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AnalyticsHelper.reportScreen(getActivity(), AnalyticsManager.SCREEN_TEXT_EDITOR_ENCODING);

    if (getArguments() != null && getArguments().containsKey(ARGUMENT_DEFAULT_CHARSET)) {
        defaultCharset = getArguments().getString(ARGUMENT_DEFAULT_CHARSET, "UTF-8");
    }/*w  w w.j  a v  a2s . com*/

    SortedMap<String, Charset> map = Charset.availableCharsets();
    list = new ArrayList<String>(map.keySet());
    EncodingAdapter adapter = new EncodingAdapter(getActivity(), R.layout.row_single_line, list,
            defaultCharset);

    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity())
            .iconRes(R.drawable.ic_application_logo);
    if (list.isEmpty()) {
        builder.title(R.string.create_document_editor_not_available)
                .content(Html.fromHtml(getString(R.string.create_document_editor_not_available_description)));
        return builder.show();
    } else {
        builder.title(R.string.file_editor_encoding).adapter(adapter, new MaterialDialog.ListCallback() {
            @Override
            public void onSelection(MaterialDialog materialDialog, View view, int i,
                    CharSequence charSequence) {
                if (getActivity() instanceof TextEditorActivity) {
                    ((TextEditorActivity) getActivity()).reload(list.get(i));
                }
                materialDialog.dismiss();
            }
        });
    }
    return builder.show();
}

From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java

public void testSessionAttributesToMap() {
    session.setAttribute("jimmy", "james");
    session.setAttribute("johnny", "johnson");
    session.setAttribute("wnyx", 585);

    SortedMap<String, Object> map = WebTools.sessionAttributesToMap(session);

    Set<String> keys = map.keySet();
    assertContains(keys, "jimmy");
    assertContains(keys, "johnny");
    assertContains(keys, "wnyx");

    assertEquals(map.get("jimmy"), "james");
    assertEquals(map.get("johnny"), "johnson");
    assertEquals(map.get("wnyx"), 585);

    // test order
    Iterator<String> keysIt = keys.iterator();
    assertEquals("jimmy", keysIt.next());
    assertEquals("johnny", keysIt.next());
    assertEquals("wnyx", keysIt.next());
}

From source file:gov.nih.nci.cabig.ctms.web.WebToolsTest.java

public void testRequestAttributesToMap() {
    request.setAttribute("wnyx", 585);
    request.setAttribute("jimmy", "james");
    request.setAttribute("johnny", "johnson");

    SortedMap<String, Object> map = WebTools.requestAttributesToMap(request);

    Set<String> keys = map.keySet();
    assertContains(keys, "jimmy");
    assertContains(keys, "johnny");
    assertContains(keys, "wnyx");

    assertEquals(map.get("jimmy"), "james");
    assertEquals(map.get("johnny"), "johnson");
    assertEquals(map.get("wnyx"), 585);

    // test order
    Iterator<String> keysIt = keys.iterator();
    assertEquals("jimmy", keysIt.next());
    assertEquals("johnny", keysIt.next());
    assertEquals("wnyx", keysIt.next());
}

From source file:org.lmnl.AbstractTest.java

/**
 * Prints the given {@link OverlapIndexer range index} to the log.
 * // w ww .j  a  v  a2  s .  c  om
 * @param index
 *                the range index to output
 */
protected void printDebugMessage(SortedMap<Range, List<Annotation>> index) {
    if (LOG.isDebugEnabled()) {
        final StringBuilder str = new StringBuilder();
        for (Range segment : index.keySet()) {
            str.append("[" + segment + ": { ");
            boolean first = true;
            for (Annotation annotation : index.get(segment)) {
                if (first) {
                    first = false;
                } else {
                    str.append(", ");
                }
                str.append(annotation.toString());
            }
            str.append(" }]\n");
        }
        LOG.debug(str.toString());
    }
}

From source file:org.opennms.ng.dao.support.FilterWalker.java

/**
 * <p>walk</p>/* w  w  w .  jav a 2s  . co m*/
 */
public void walk() {
    SortedMap<Integer, String> map = getFilterDao().getNodeMap(m_filter);
    if (map != null) {
        for (final Integer nodeId : map.keySet()) {
            final OnmsNode node = getNodeDao().load(nodeId);
            m_visitor.visitNode(node);
        }
    }
}

From source file:com.act.biointerpretation.Utils.OrgMinimalPrefixGenerator.java

public OrgMinimalPrefixGenerator(Iterator<Organism> orgIterator) {
    Map<String, Long> orgMap = new HashMap<>();

    while (orgIterator.hasNext()) {
        Organism org = orgIterator.next();
        orgMap.put(org.getName(), 1L);// www  . ja  v  a2s .c  o m
    }

    PatriciaTrie orgPrefixTrie = new PatriciaTrie<>(orgMap);
    orgNameToMinimalPrefix = new HashMap<>();

    while (orgPrefixTrie.size() != 0) {
        String firstKey = (String) orgPrefixTrie.firstKey();
        orgNameToMinimalPrefix.put(firstKey, firstKey);
        orgPrefixTrie.remove(firstKey);

        SortedMap<String, Long> keyPrefixMap = orgPrefixTrie.prefixMap(firstKey);

        List<String> namesToRemove = new ArrayList<>();

        for (String orgWithPrefix : keyPrefixMap.keySet()) {
            orgNameToMinimalPrefix.put(orgWithPrefix, firstKey);
            namesToRemove.add(orgWithPrefix);
        }

        for (String nameToRemove : namesToRemove) {
            orgPrefixTrie.remove(nameToRemove);
        }
    }
}

From source file:org.openmrs.module.drughistory.api.impl.DrugSnapshotServiceImpl.java

/**
 * Plow through drug events and create snapshots from them
 * TODO find a way to batch or use a cursor
 *//* w  w w .  j  a va  2  s.co m*/
@Override
public void generateDrugSnapshots(Patient patient, Date sinceWhen) {
    // set up params for drug event query
    Properties params = new Properties();
    if (patient != null) {
        params.put("person", patient);
    }
    if (sinceWhen != null) {
        params.put("since", sinceWhen);
    }

    // get the drug events
    List<DrugEvent> events = Context.getService(DrugEventService.class).getDrugEvents(params);

    // order events by person and date
    Map<Person, SortedMap<Date, List<DrugEvent>>> byPersonAndDate = groupByPersonAndDate(events);

    // create snapshots and save after processing each person
    List<DrugSnapshot> snapshots = new ArrayList<DrugSnapshot>();
    for (Person p : byPersonAndDate.keySet()) {

        DrugSnapshot s = new DrugSnapshot();
        s.setPerson(p);

        // for each date, calculate the new set of relevant concepts
        SortedMap<Date, List<DrugEvent>> dateListMap = byPersonAndDate.get(p);

        for (Date d : dateListMap.keySet()) {
            s.setDateTaken(d);
            for (DrugEvent de : dateListMap.get(d)) {
                if (de.getEventType() == DrugEventType.START || de.getEventType() == DrugEventType.CONTINUE) {
                    s.addConcept(de.getConcept());
                } else if (de.getEventType() == DrugEventType.STOP) {
                    s.removeConcept(de.getConcept());
                }

                // the snapshot's encounter will be the one from the last-added observation
                s.setEncounter(de.getEncounter());
            }

            // add a copy to snapshots, since we want to reuse this one
            DrugSnapshot ds = s.copy();

            // ... and give it a UUID
            ds.setUuid(UUID.randomUUID().toString());

            snapshots.add(ds);
        }

        // save and clear snapshots
        saveSnapshots(snapshots);
        snapshots.clear();

        // flush the context so we don't run into memory issues
        Context.flushSession();
        Context.clearSession();
    }
}

From source file:org.libreplan.web.common.components.finders.ResourcesMultipleFiltersFinder.java

private List<FilterPair> fillWithFirstTenFiltersCriterions() {
    SortedMap<CriterionType, List<Criterion>> criterionsMap = getCriterionsMap();
    Iterator<CriterionType> iteratorCriterionType = criterionsMap.keySet().iterator();
    while (iteratorCriterionType.hasNext() && getListMatching().size() < 10) {
        CriterionType type = iteratorCriterionType.next();
        for (int i = 0; getListMatching().size() < 10 && i < criterionsMap.get(type).size(); i++) {
            Criterion criterion = criterionsMap.get(type).get(i);
            addCriterion(type, criterion);
        }//from w  ww.  ja  v  a  2 s.c  om
    }
    return getListMatching();
}

From source file:org.wso2.andes.server.util.AlreadyProcessedMessageTracker.java

private void startRemovingProcessedMessageIDS() {
    alreadyProcessedMessageIDsRemovingScheduler.scheduleAtFixedRate(new Runnable() {
        @Override/*from   w ww .  java 2  s .c o  m*/
        public void run() {
            while (!trackingMessagesRemovalTasks.isEmpty()) {
                long currentTime = System.nanoTime();
                SortedMap<Long, Long> timedOutContentList = trackingMessagesRemovalTasks
                        .headMap(currentTime - timeOutPerMessage);
                for (Long key : timedOutContentList.keySet()) {
                    long msgid = trackingMessagesRemovalTasks.get(key);
                    trackingMessageIDs.remove(msgid);
                    log.debug("cleared message from tracking message id " + msgid + "identifier=" + identifier);
                    trackingMessagesRemovalTasks.remove(key);
                }
            }
        }
    }, 5, trackingMessagesRemovalTaskIntervalInSec, TimeUnit.SECONDS);
}

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

private static Map<String, PointPerson> getWorkActivityTimes() throws IOException, InstantiationException,
        IllegalAccessException, ClassNotFoundException, SQLException, NoConnectionException {
    DataBaseAdmin dataBaseHits = new DataBaseAdmin(new File("./data/hits/DataBase.properties"));
    Map<String, PersonSchedule> times;
    ResultSet timesResult = dataBaseHits.executeQuery(
            "SELECT pax_idx,trip_id,t6_purpose,t3_starttime,t4_endtime,p6_occup,t5_placetype FROM hits.hitsshort");
    times = new HashMap<String, PersonSchedule>();
    while (timesResult.next()) {
        PersonSchedule timesPerson = times.get(timesResult.getString(1));
        if (timesPerson == null) {
            timesPerson = new PersonSchedule(timesResult.getString(1), timesResult.getString(6));
            times.put(timesResult.getString(1), timesPerson);
        }// ww w  . j  a v a  2s. c  o  m
        if (timesResult.getInt(2) != 0) {
            Iterator<Entry<Integer, Trip>> timesPersonI = timesPerson.getTrips().entrySet().iterator();
            Entry<Integer, Trip> last = null;
            while (timesPersonI.hasNext())
                last = timesPersonI.next();
            if (last == null || last.getKey() != timesResult.getInt(2)) {
                int startTime = (timesResult.getInt(4) % 100) * 60 + (timesResult.getInt(4) / 100) * 3600;
                int endTime = (timesResult.getInt(5) % 100) * 60 + (timesResult.getInt(5) / 100) * 3600;
                if (last != null && last.getKey() < timesResult.getInt(2)
                        && last.getValue().getEndTime() > startTime) {
                    startTime += 12 * 3600;
                    endTime += 12 * 3600;
                }
                if (last != null && last.getKey() < timesResult.getInt(2)
                        && last.getValue().getEndTime() > startTime) {
                    startTime += 12 * 3600;
                    endTime += 12 * 3600;
                }
                timesPerson.getTrips().put(timesResult.getInt(2),
                        new Trip(timesResult.getString(3), startTime, endTime, timesResult.getString(7)));
            }
        }
    }
    timesResult.close();
    Map<String, PointPerson> points = new HashMap<String, PointPerson>();
    for (PersonSchedule timesPerson : times.values()) {
        SortedMap<Integer, Trip> tripsPerson = timesPerson.getTrips();
        boolean startTimeSaved = false;
        double startTime = -1, endTime = -1;
        String placeType = null;
        if (tripsPerson.size() > 0) {
            for (int i = tripsPerson.keySet().iterator().next(); i <= tripsPerson.size(); i++) {
                if (!startTimeSaved && tripsPerson.get(i).getPurpose() != null
                        && tripsPerson.get(i).getPurpose().equals("work")) {
                    startTime = tripsPerson.get(i).getEndTime();
                    startTimeSaved = true;
                }
                if (i > tripsPerson.keySet().iterator().next()
                        && tripsPerson.get(i - 1).getPurpose().equals("work")) {
                    endTime = tripsPerson.get(i).getStartTime();
                    placeType = tripsPerson.get(i - 1).getPlaceType();
                }
            }
        }
        if (startTime != -1 && endTime != -1 && endTime - startTime >= 7 * 3600
                && endTime - startTime <= 16 * 3600)
            if (startTime > 24 * 3600)
                points.put(timesPerson.getId(),
                        new PointPerson(
                                timesPerson.getId(), timesPerson.getOccupation(), new Double[] {
                                        startTime - 24 * 3600, endTime - 24 * 3600 - (startTime - 24 * 3600) },
                                placeType));
            else
                points.put(timesPerson.getId(),
                        new PointPerson(timesPerson.getId(), timesPerson.getOccupation(),
                                new Double[] { startTime, endTime - startTime }, placeType));
    }
    Map<String, Double> weights;
    try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(WEIGHTS2_MAP_FILE));
        weights = (Map<String, Double>) ois.readObject();
        ois.close();
    } catch (EOFException e) {
        weights = new HashMap<String, Double>();
        ResultSet weightsR = dataBaseHits.executeQuery("SELECT pax_idx,hipf10  FROM hits.hitsshort_geo_hipf");
        while (weightsR.next())
            weights.put(weightsR.getString(1), weightsR.getDouble(2));
        for (PointPerson pointPerson : points.values()) {
            if (weights.get(pointPerson.getId()) != null)
                pointPerson.setWeight(weights.get(pointPerson.getId()));
            else
                pointPerson.setWeight(100);
        }
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(WEIGHTS2_MAP_FILE));
        oos.writeObject(weights);
        oos.close();
    }
    dataBaseHits.close();
    /*points.clear();
    double a=Math.PI/6;
    double dx=3;
    double dy=7;
    double sx=4;
    double sy=0.5;
    for(int i=0; i<1000; i++) {
       double x=Math.random();
       double y=Math.random();
       points.put(i+"", new PointPerson(i+"", "any", new Double[]{Math.cos(a)*sx*x-Math.sin(a)*sy*y+dx, Math.sin(a)*sx*x+Math.cos(a)*sy*y+dy}));
    }*/
    return points;
}