Example usage for java.util TreeMap keySet

List of usage examples for java.util TreeMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

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

Usage

From source file:com.sfs.whichdoctor.beans.PersonBean.java

/**
 * Gets the accreditation total.//w w w. j  a  v a2s.  c  o m
 *
 * @param committee the committee
 * @param trainingTypes the training types
 *
 * @return the accreditation total
 */
public final String getAccreditationTotal(final String committee, final Collection<String> trainingTypes) {

    int totalCore = 0;
    int totalNonCore = 0;

    if (committee != null) {

        for (String type : trainingTypes) {

            TreeMap<String, AccreditationBean[]> accreds = this.getTrainingSummary(type);

            if (accreds != null) {
                for (String key : accreds.keySet()) {
                    AccreditationBean[] details = accreds.get(key);
                    AccreditationBean core = details[0];
                    AccreditationBean nonCore = details[0];

                    if (StringUtils.equalsIgnoreCase(committee, core.getSpecialtyType())) {
                        totalCore += core.getWeeksCertified();
                        totalNonCore += nonCore.getWeeksCertified();
                    }
                }
            }
        }
    }
    return Formatter.getWholeMonths(totalCore) + " (" + Formatter.getWholeMonths(totalNonCore) + ")";
}

From source file:com.sfs.whichdoctor.beans.BulkEmailBean.java

/**
 * Gets the ordered email recipients.//from w  ww  .j  a  va2  s.c o  m
 *
 * @return the ordered email recipients
 */
public final Collection<EmailRecipientBean> getOrderedEmailRecipients() {
    if (this.orderedEmailRecipients == null) {

        this.orderedEmailRecipients = new ArrayList<EmailRecipientBean>();

        TreeMap<String, EmailRecipientBean> orderMap = new TreeMap<String, EmailRecipientBean>();
        for (EmailRecipientBean recipient : getEmailRecipients()) {
            if (recipient != null) {
                if (StringUtils.isNotBlank(recipient.getOrder())) {
                    orderMap.put(recipient.getOrder(), recipient);
                }
            }
        }
        for (String key : orderMap.keySet()) {
            EmailRecipientBean recipient = orderMap.get(key);
            this.orderedEmailRecipients.add(recipient);
        }
    }
    return this.orderedEmailRecipients;
}

From source file:org.gvsig.framework.web.service.impl.OGCInfoServiceImpl.java

public ServiceMetadata getMetadataInfoFromWMS(String urlServer) {

    ServiceMetadata servMetadata = new ServiceMetadata();

    try {// ww  w  . j a  v a2  s . c  om
        WMSClient wms = new WMSClient(urlServer);
        wms.connect(null);

        // set server information
        WMSServiceInformation serviceInfo = wms.getServiceInformation();

        servMetadata.setAbstractStr(serviceInfo.abstr);
        servMetadata.setFees(serviceInfo.fees);
        servMetadata.setKeywords(serviceInfo.keywords);
        servMetadata.setName(serviceInfo.name);
        servMetadata.setTitle(serviceInfo.title);
        servMetadata.setUrl(urlServer);
        servMetadata.setVersion(serviceInfo.version);
        // I can't get from service the accessConstraints value
        //servMetadata.setAccessConstraints(accessConstraints);

        // get layers
        TreeMap layers = wms.getLayers();
        if (layers != null) {
            List<Layer> lstLayers = new ArrayList<Layer>();
            Set<String> keys = layers.keySet();
            for (String key : keys) {
                WMSLayer wmsLayer = (WMSLayer) layers.get(key);
                Layer layer = new Layer();
                layer.setName(wmsLayer.getName());
                layer.setTitle(wmsLayer.getTitle());
                lstLayers.add(layer);
            }
            servMetadata.setLayers(lstLayers);
        }

        // get operations
        Hashtable supportedOperations = serviceInfo.getSupportedOperationsByName();
        if (supportedOperations != null) {
            List<OperationsMetadata> lstOperations = new ArrayList<OperationsMetadata>();
            Set<String> keys = supportedOperations.keySet();
            for (String key : keys) {
                OperationsMetadata opMetadata = new OperationsMetadata();
                opMetadata.setName(key);
                opMetadata.setUrl((String) supportedOperations.get(key));
                lstOperations.add(opMetadata);
            }
            servMetadata.setOperations(lstOperations);
        }
        // get contact address
        ContactAddressMetadata contactAddress = null;
        if (StringUtils.isNotEmpty(serviceInfo.address) || StringUtils.isNotEmpty(serviceInfo.addresstype)
                || StringUtils.isNotEmpty(serviceInfo.place) || StringUtils.isNotEmpty(serviceInfo.country)
                || StringUtils.isNotEmpty(serviceInfo.postcode)
                || StringUtils.isNotEmpty(serviceInfo.province)) {
            contactAddress = new ContactAddressMetadata();
            contactAddress.setAddress(serviceInfo.address);
            contactAddress.setAddressType(serviceInfo.addresstype);
            contactAddress.setCity(serviceInfo.place);
            contactAddress.setCountry(serviceInfo.country);
            contactAddress.setPostCode(serviceInfo.postcode);
            contactAddress.setStateProvince(serviceInfo.province);
        }

        // get contact info
        ContactMetadata contactMetadata = null;
        if (contactAddress != null || StringUtils.isNotEmpty(serviceInfo.email)
                || StringUtils.isNotEmpty(serviceInfo.fax) || StringUtils.isNotEmpty(serviceInfo.organization)
                || StringUtils.isNotEmpty(serviceInfo.personname)
                || StringUtils.isNotEmpty(serviceInfo.function) || StringUtils.isNotEmpty(serviceInfo.phone)) {
            contactMetadata = new ContactMetadata();
            contactMetadata.setContactAddress(contactAddress);
            contactMetadata.setEmail(serviceInfo.email);
            contactMetadata.setFax(serviceInfo.fax);
            contactMetadata.setOrganization(serviceInfo.organization);
            contactMetadata.setPerson(serviceInfo.personname);
            contactMetadata.setPosition(serviceInfo.function);
            contactMetadata.setTelephone(serviceInfo.phone);
        }
        servMetadata.setContact(contactMetadata);

    } catch (Exception exc) {
        // Show exception in log
        logger.error("Exception on getMetadataInfoFromWMS", exc);
        throw new ServerGeoException();
    }

    return servMetadata;
}

From source file:org.mda.bcb.tcgagsdata.create.Metadata.java

public void writePatientDataFile(String theIdColumn, String theDataColumn, String theOutputFile,
        File[] theDiseaseSamplesFiles) throws IOException {
    // TODO: theDiseaseSampleFile - disease in first column, rest of row is SAMPLE barcode
    TcgaGSData.printWithFlag("Metadata::writePatientDataFile - start " + theOutputFile);
    TreeMap<String, String> patientDisease = new TreeMap<>();
    try (BufferedReader br = Files.newBufferedReader(Paths.get(mMetadataFile),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        // read header/write header
        int indexId = -1;
        int indexData = -1;
        {// w ww.  j  a v a  2s .  c  o  m
            String line = br.readLine();
            ArrayList<String> headerArray = new ArrayList<>();
            headerArray.addAll(Arrays.asList(line.split("\t", -1)));
            indexId = headerArray.indexOf(theIdColumn);
            indexData = headerArray.indexOf(theDataColumn);
        }
        //
        for (String line = br.readLine(); null != line; line = br.readLine()) {
            String[] splitted = line.split("\t", -1);
            patientDisease.put(trimToPatientId(splitted[indexId]), splitted[indexData]);
        }
        for (File file : theDiseaseSamplesFiles) {
            TreeSet<String> barcodes = getDiseaseSampleData(file, true);
            for (String barcode : barcodes) {
                String patientId = trimToPatientId(barcode);
                if (false == patientDisease.keySet().contains(patientId)) {
                    patientDisease.put(patientId, MetadataTcgaNames.M_UNKNOWN);
                }
            }
        }
    }
    try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(theOutputFile),
            Charset.availableCharsets().get("ISO-8859-1"))) {
        bw.write("ID\tDATA");
        bw.newLine();
        for (String key : patientDisease.keySet()) {
            bw.write(key + "\t" + patientDisease.get(key));
            bw.newLine();
        }
    }
    TcgaGSData.printWithFlag("Metadata::writePatientDataFile - finished " + theOutputFile);
}

From source file:com.vuze.android.remote.dialog.DialogFragmentFilterByTags.java

@NonNull
@Override/*  w ww . java2s  . c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    SessionInfo sessionInfo = getSessionInfo();
    List<Map<?, ?>> tags = sessionInfo == null ? null : sessionInfo.getTags();
    if (tags != null && tags.size() > 0) {
        TreeMap<String, Long> map = new TreeMap<>();
        for (Object o : tags) {
            if (o instanceof Map) {
                Map<?, ?> mapTag = (Map<?, ?>) o;
                long uid = MapUtils.getMapLong(mapTag, "uid", 0);
                String name = MapUtils.getMapString(mapTag, "name", "??");
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                if (type == 3) {
                    // type-name will be "Manual" :(
                    name = "Tag: " + name;
                } else {
                    String typeName = MapUtils.getMapString(mapTag, "type-name", null);
                    if (typeName != null) {
                        name = typeName + ": " + name;
                    }
                }
                map.put(name, uid);
            }
        }

        long[] vals = new long[map.size()];
        String[] strings = map.keySet().toArray(new String[map.keySet().size()]);
        for (int i = 0; i < vals.length; i++) {
            vals[i] = map.get(strings[i]);
        }

        filterByList = new ValueStringArray(vals, strings);
    }

    if (filterByList == null) {
        filterByList = AndroidUtils.getValueStringArray(getResources(), R.array.filterby_list);
    }

    AndroidUtils.AlertDialogBuilder alertDialogBuilder = AndroidUtils.createAlertDialogBuilder(getActivity(),
            R.layout.dialog_filter_by);

    View view = alertDialogBuilder.view;
    AlertDialog.Builder builder = alertDialogBuilder.builder;

    // get our tabHost from the xml
    TabHost tabHost = (TabHost) view.findViewById(R.id.filterby_tabhost);
    tabHost.setup();

    // create tab 1
    TabHost.TabSpec spec1 = tabHost.newTabSpec("tab1");
    spec1.setIndicator("States");
    spec1.setContent(R.id.filterby_sv_state);
    tabHost.addTab(spec1);
    //create tab2
    TabHost.TabSpec spec2 = tabHost.newTabSpec("tab2");
    spec2.setIndicator("Tags");
    spec2.setContent(R.id.filterby_tv_tags);
    tabHost.addTab(spec2);

    int height = AndroidUtilsUI.dpToPx(32);
    tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
    tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;

    TextView tvState = (TextView) view.findViewById(R.id.filterby_tv_state);
    tvState.setMovementMethod(LinkMovementMethod.getInstance());

    final TextView tvTags = (TextView) view.findViewById(R.id.filterby_tv_tags);
    tvTags.setMovementMethod(LinkMovementMethod.getInstance());

    // for API <= 10 (maybe 11?), otherwise tags will display on one line
    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (!tabId.equals("tab2")) {
                return;
            }
            tvTags.post(new Runnable() {
                @Override
                public void run() {
                    spanTags.updateTags();
                }
            });
        }
    });

    builder.setTitle(R.string.filterby_title);

    // Add action buttons
    builder.setPositiveButton(R.string.action_filterby, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (mapSelectedTag == null) {
                return;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            String name = MapUtils.getMapString(mapSelectedTag, "name", "??");

            mListener.filterBy(uidSelected, name, true);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DialogFragmentFilterByTags.this.getDialog().cancel();
        }
    });

    List<Map<?, ?>> manualTags = new ArrayList<>();
    List<Map<?, ?>> stateTags = new ArrayList<>();

    if (sessionInfo != null) {
        // Dialog never gets called wehn getTags has no tags
        List<Map<?, ?>> allTags = sessionInfo.getTags();
        if (allTags != null) {
            for (Map<?, ?> mapTag : allTags) {
                int type = MapUtils.getMapInt(mapTag, "type", 0);
                switch (type) {
                case 0:
                case 1:
                case 2:
                    stateTags.add(mapTag);
                    break;
                case 3: // manual
                    manualTags.add(mapTag);
                    break;
                }
            }
        }
    }

    SpanTagsListener l = new SpanTagsListener() {
        @Override
        public void tagClicked(Map mapTag, String name) {
            mapSelectedTag = mapTag;
            // todo: long click, don't exit
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            mListener.filterBy(uidSelected, name, true);
            DialogFragmentFilterByTags.this.getDialog().dismiss();
        }

        @Override
        public int getTagState(Map mapTag, String name) {
            if (mapSelectedTag == null) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidSelected = MapUtils.getMapLong(mapSelectedTag, "uid", -1);
            if (uidSelected == -1) {
                return SpanTags.TAG_STATE_UNSELECTED;
            }
            long uidQuery = MapUtils.getMapLong(mapTag, "uid", -1);
            return uidQuery == uidSelected ? SpanTags.TAG_STATE_SELECTED : SpanTags.TAG_STATE_UNSELECTED;
        }
    };
    spanTags = new SpanTags(getActivity(), sessionInfo, tvTags, l);
    spanTags.setTagMaps(manualTags);
    spanTags.setShowIcon(false);
    spanTags.updateTags();

    SpanTags spanState = new SpanTags(getActivity(), sessionInfo, tvState, l);
    spanState.setTagMaps(stateTags);
    spanState.setShowIcon(false);
    spanState.updateTags();

    return builder.create();
}

From source file:com.sfs.whichdoctor.dao.RelationshipDAOImpl.java

/**
 * Given list of prior rotations GUID and build a supervisor map.
 *
 * @param priorRotations the prior rotations
 *
 * @return the tree map< integer, relationship bean>
 *///ww  w  . j a  v a2  s. c  o m
private TreeMap<Integer, RelationshipBean> loadPriorSupervisorMap(
        final Collection<RotationBean> priorRotations) {
    TreeMap<Integer, RelationshipBean> supervisorMap = new TreeMap<Integer, RelationshipBean>();

    TreeMap<Long, RotationBean> orderedRotations = new TreeMap<Long, RotationBean>();

    for (RotationBean rotation : priorRotations) {
        long key = LARGE_LONG - rotation.getEndDate().getTime();
        orderedRotations.put(key, rotation);
    }

    for (Long key : orderedRotations.keySet()) {
        RotationBean rotation = orderedRotations.get(key);
        dataLogger.info("End date: " + rotation.getEndDate());
        if (supervisorMap.size() == 0) {
            supervisorMap = getSupervisorMap(rotation);
        }
    }
    return supervisorMap;
}

From source file:org.languagetool.gui.LanguageToolSupport.java

private void addDisabledRulesToMenu(List<Rule> disabledRules, JMenu menu) {
    if (disabledRules.size() <= MAX_RULES_NO_CATEGORY_MENU) {
        createRulesMenu(menu, disabledRules);
        return;//w ww . j  av  a  2  s. c om
    }

    TreeMap<String, ArrayList<Rule>> categories = new TreeMap<>();
    for (Rule rule : disabledRules) {
        if (!categories.containsKey(rule.getCategory().getName())) {
            categories.put(rule.getCategory().getName(), new ArrayList<>());
        }
        categories.get(rule.getCategory().getName()).add(rule);
    }

    JMenu parent = menu;
    int count = 0;
    for (String category : categories.keySet()) {
        count++;
        JMenu submenu = new JMenu(category);
        parent.add(submenu);
        createRulesMenu(submenu, categories.get(category));

        if (categories.keySet().size() <= MAX_CATEGORIES_PER_MENU) {
            continue;
        }

        //if menu contains MAX_CATEGORIES_PER_MENU-1, add a `more` menu
        //but only if the remain entries are more than one
        if ((count % (MAX_CATEGORIES_PER_MENU - 1) == 0) && (categories.keySet().size() - count > 1)) {
            JMenu more = new JMenu(messages.getString("guiActivateRuleMoreCategories"));
            parent.add(more);
            parent = more;
        }
    }
}

From source file:com.eucalyptus.ws.handlers.WalrusAuthenticationHandler.java

private String getCanonicalizedAmzHeaders(MappingHttpRequest httpRequest) {
    String result = "";
    Set<String> headerNames = httpRequest.getHeaderNames();

    TreeMap amzHeaders = new TreeMap<String, String>();
    for (String headerName : headerNames) {
        String headerNameString = headerName.toLowerCase().trim();
        if (headerNameString.startsWith("x-amz-")) {
            String value = httpRequest.getHeader(headerName).trim();
            String[] parts = value.split("\n");
            value = "";
            for (String part : parts) {
                part = part.trim();// w w w  . j a  v  a2  s . c  om
                value += part + " ";
            }
            value = value.trim();
            if (amzHeaders.containsKey(headerNameString)) {
                String oldValue = (String) amzHeaders.remove(headerNameString);
                oldValue += "," + value;
                amzHeaders.put(headerNameString, oldValue);
            } else {
                amzHeaders.put(headerNameString, value);
            }
        }
    }

    Iterator<String> iterator = amzHeaders.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        String value = (String) amzHeaders.get(key);
        result += key + ":" + value + "\n";
    }
    return result;
}

From source file:com.sfs.whichdoctor.dao.BulkContactDAOImpl.java

/**
 * Prepare the bulk contact bean.//from   www  .  j  ava2s  .  c om
 *
 * @param contactBean the bulk contact bean
 * @param groupGUID the group guid
 * @param user the user
 * @return the bulk contact bean
 */
public final BulkContactBean prepare(final BulkContactBean contactBean, final int groupGUID,
        final UserBean user) {

    GroupBean group = null;
    /** Try loading the group **/
    try {
        BuilderBean builderBean = new BuilderBean();
        builderBean.setParameter("ITEMS", true);

        group = groupDAO.loadGUID(groupGUID, builderBean);
    } catch (WhichDoctorDaoException wde) {
        dataLogger.error("Error loading group for bulk contact: " + wde.getMessage());
    }

    TreeMap<Integer, Integer> exportGUIDs = new TreeMap<Integer, Integer>();
    Collection<Object> guids = new ArrayList<Object>();

    if (group != null) {

        contactBean.addReferenceGUID(group.getGUID());

        dataLogger.debug("Group type: " + group.getObjectType());
        contactBean.setObjectType(group.getObjectType());

        if (group.getItems() != null) {

            for (String key : group.getItems().keySet()) {
                ItemBean item = group.getItems().get(key);
                if (item.display(contactBean.getStartDate(), contactBean.getEndDate())) {
                    exportGUIDs.put(item.getObject2GUID(), item.getObject2GUID());
                }
            }
            for (Integer guid : exportGUIDs.keySet()) {
                guids.add(guid);
            }
        }
    }

    BulkContactBean bulkContact = performSearch(contactBean, guids, user, false);

    return bulkContact;
}

From source file:org.openmicroscopy.shoola.agents.measurement.view.MeasurementViewerComponent.java

/** 
 * Implemented as specified by the {@link MeasurementViewer} interface.
 * @see MeasurementViewer#setActiveChannelsColor(Map)
 *///from ww w.ja v  a 2 s.  co m
public void setActiveChannelsColor(Map channels) {
    int state = model.getState();
    switch (model.getState()) {
    case DISCARDED:
    case LOADING_DATA:
        throw new IllegalStateException(
                "This method cannot be " + "invoked in the DISCARDED, LOADING_DATA " + "state: " + state);
    }
    model.setActiveChannels(channels);
    if (!view.inDataView() || !view.isVisible())
        return;
    Collection<ROIFigure> collection = getSelectedFigures();
    if (collection.size() != 1)
        return;

    ROIFigure figure = collection.iterator().next();
    ArrayList<ROIShape> shapeList = new ArrayList<ROIShape>();
    ROI roi = figure.getROI();
    TreeMap<Coord3D, ROIShape> shapeMap = roi.getShapes();
    Iterator<Coord3D> shapeIterator = shapeMap.keySet().iterator();
    while (shapeIterator.hasNext())
        shapeList.add(shapeMap.get(shapeIterator.next()));
    if (shapeList.size() != 0)
        analyseShapeList(shapeList);
}