Example usage for java.util TreeMap TreeMap

List of usage examples for java.util TreeMap TreeMap

Introduction

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

Prototype

public TreeMap(SortedMap<K, ? extends V> m) 

Source Link

Document

Constructs a new tree map containing the same mappings and using the same ordering as the specified sorted map.

Usage

From source file:com.gopivotal.cloudfoundry.test.core.RuntimeUtils.java

public Map<String, String> environmentVariables() {
    return new TreeMap<>(this.environment);
}

From source file:com.opengamma.financial.analytics.cashflow.FixedPaymentMatrix.java

public FixedPaymentMatrix add(final Map<LocalDate, MultipleCurrencyAmount> payments) {
    ArgumentChecker.notNull(payments, "payments");
    final Map<LocalDate, MultipleCurrencyAmount> values = new TreeMap<LocalDate, MultipleCurrencyAmount>(
            _values);/*from   w w w  .j  ava 2  s. co  m*/
    int count = getMaxCurrencyAmounts();
    for (final Map.Entry<LocalDate, MultipleCurrencyAmount> entry : payments.entrySet()) {
        final LocalDate date = entry.getKey();
        final MultipleCurrencyAmount mca = entry.getValue();
        if (mca.size() > count) {
            count = mca.size();
        }
        if (values.containsKey(date)) {
            values.put(date, values.get(date).plus(mca));
        } else {
            values.put(date, mca);
        }
    }
    return new FixedPaymentMatrix(values, count);
}

From source file:com.erudika.scoold.controllers.LanguagesController.java

@GetMapping
public String get(HttpServletRequest req, Model model) {
    model.addAttribute("path", "languages.vm");
    model.addAttribute("title", utils.getLang(req).get("translate.select"));
    model.addAttribute("allLocales", new TreeMap<String, Locale>(utils.getLangutils().getAllLocales()));
    model.addAttribute("langProgressMap", utils.getLangutils().getTranslationProgressMap());
    return "base";
}

From source file:org.openmrs.module.adminui.page.controller.metadata.ConfigureMetadataPageController.java

/**
 * Process requests to show the home page
 *
 * @param model// w  w w . j  a  v  a2s.  c  o  m
 * @param appFrameworkService
 */
public void get(PageModel model, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService,
        UiUtils ui) {
    //We need to keep the groups and links sorted by label
    //for consistent ordering every time the page gets loaded
    ExtensionByLabelComparator comparator = new ExtensionByLabelComparator(ui);
    Map<Extension, Set<Extension>> adminGroupAndLinksMap = new TreeMap<Extension, Set<Extension>>(comparator);
    List<Extension> adminGroups = appFrameworkService
            .getExtensionsForCurrentUser(CONFIGURE_METADATA_ADMIN_GROUPS_EXTENSION_POINT_ID);
    List<Extension> adminLinks = appFrameworkService
            .getExtensionsForCurrentUser(CONFIGURE_METADATA_ADMIN_LINKS_EXTENSION_POINT_ID);

    for (Extension adminLink : adminLinks) {
        String groupExtensionId = (String) adminLink.getExtensionParams().get("group");
        Extension group = null;
        for (Extension adminGroup : adminGroups) {
            if (adminGroup.getId().equals(groupExtensionId)) {
                group = adminGroup;
            }
        }

        if (group == null) {
            throw new ViewException("No admin group extension was found with id: " + groupExtensionId);
        }

        if (adminGroupAndLinksMap.get(group) == null) {
            adminGroupAndLinksMap.put(group, new TreeSet<Extension>(comparator));
        }
        adminGroupAndLinksMap.get(group).add(adminLink);
    }

    model.addAttribute("adminGroupAndLinksMap", adminGroupAndLinksMap);
}

From source file:com.mirth.connect.donkey.util.ActionTimer.java

public String getLog() {
    long totalTime = getTotalTime();

    StringBuilder log = new StringBuilder();
    LongComparator longComparator = new LongComparator(times);
    TreeMap<String, Long> sortedTimes = new TreeMap<String, Long>(longComparator);
    sortedTimes.putAll(times);//from   w  w w  .  ja va2 s  .  c o m

    for (Entry<String, Long> logEntry : sortedTimes.entrySet()) {
        String eventName = logEntry.getKey();
        Integer count = counts.get(eventName);
        Long time = logEntry.getValue();

        long pct = (totalTime > 0) ? ((time * 100) / totalTime) : 0;
        log.append(StringUtils.rightPad(eventName + ":", 40)
                + StringUtils.rightPad(count + " occurrence" + ((count != 1) ? "s" : ""), 20)
                + StringUtils.rightPad(time + "ms", 12) + pct + "%\n");
    }

    int totalCount = getTotalCount();
    log.append(StringUtils.rightPad("Totals:", 40)
            + StringUtils.rightPad(totalCount + " occurrence" + ((totalCount != 1) ? "s" : ""), 20) + totalTime
            + "ms\n");
    return log.toString();
}

From source file:com.opengamma.financial.analytics.cashflow.FloatingPaymentMatrix.java

public FloatingPaymentMatrix add(final Map<LocalDate, List<Pair<CurrencyAmount, String>>> resets) {
    ArgumentChecker.notNull(resets, "resets");
    final Map<LocalDate, List<Pair<CurrencyAmount, String>>> values = new TreeMap<LocalDate, List<Pair<CurrencyAmount, String>>>(
            _values);//from   w w  w  . ja  v  a 2  s  .c  om
    for (final Map.Entry<LocalDate, List<Pair<CurrencyAmount, String>>> entry : resets.entrySet()) {
        final LocalDate date = entry.getKey();
        final List<Pair<CurrencyAmount, String>> newList = entry.getValue();
        if (values.containsKey(date)) {
            final List<Pair<CurrencyAmount, String>> list = values.get(date);
            list.addAll(newList);
            values.put(date, list);
        } else {
            values.put(date, newList);
        }
    }
    return new FloatingPaymentMatrix(values);
}

From source file:com.fatwire.dta.sscrawler.util.SSUriHelper.java

public String toLink(final QueryString uri) {
    if (!uri.isOK()) {
        return null;
    }/*from  ww  w. j  a v  a2  s .  co m*/
    try {
        final Map<String, String> map = new TreeMap<String, String>(uri.getParameters());
        map.remove(HelperStrings.CACHECONTROL);
        map.remove(HelperStrings.RENDERMODE);
        final StringBuilder qs = new StringBuilder();
        qs.append(path);
        // qs.append("ContentServer");
        qs.append("?");

        for (final Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); i.hasNext();) {
            final Map.Entry<String, String> entry = i.next();
            if (log.isTraceEnabled())
                log.trace(entry.toString());
            qs.append(encode(entry.getKey()));
            qs.append("=");
            final String v = entry.getValue();
            if (v != null && v.startsWith(HelperStrings.SSURI_START)) {

                final Link inner = createLink(v);
                qs.append(encode(toLink(inner)));
            } else if (v != null) {
                qs.append(encode(v));
            }
            if (i.hasNext()) {
                qs.append("&");
            }
        }
        return qs.toString();
    } catch (final EncoderException e) {
        log.warn(e);
        return null;
    } catch (final RuntimeException e) {
        log.warn(e);
        return null;
    }

}

From source file:me.doshou.admin.monitor.web.controller.HibernateCacheMonitorController.java

/**
 * ?/* ww  w .  jav  a  2s  .c om*/
 * @return
 */
@RequestMapping("")
public String index(Model model) {
    setMemoryInfo(model);
    model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em));

    Map<String, Object> properties = new TreeMap<String, Object>(em.getEntityManagerFactory().getProperties());
    model.addAttribute("properties", properties);
    return viewName("index");
}

From source file:net.rim.ejde.internal.util.ComponentPackUtils.java

/**
 * Gets the component pack paths based on the CP extension point
 *
 * @return the component pack paths/*from   www . j  a  va  2s  . co  m*/
 */
public static Map<String, JDEInfo> getComponentPackPaths() {
    ComponentPackUtils.log.debug("Starting Search for CPs"); //$NON-NLS-1$
    IExtension[] extensions;
    final IExtensionRegistry registry = RegistryFactory.getRegistry();
    final IExtensionPoint point = registry.getExtensionPoint(IConstants.CP_EXTENSION_POINT_ID);
    final TreeMap<String, JDEInfo> packs = new TreeMap<String, JDEInfo>(new ComponentPackComparator());

    if ((null == point) || !point.isValid()) {
        ComponentPackUtils.log.debug("Extention Point Null or Invalid"); //$NON-NLS-1$
        return packs;
    }
    extensions = point.getExtensions();

    if ((null == extensions) || (0 == extensions.length)) {
        ComponentPackUtils.log.debug("Extentions Null or Non-Existant"); //$NON-NLS-1$
        return packs;
    }

    Bundle bundle;
    URL url;

    String name, version, path;
    File file;

    for (final IExtension extension : extensions) {
        try {
            bundle = Platform.getBundle(extension.getNamespaceIdentifier());
            final int bundleState = bundle.getState();

            if ((bundleState != Bundle.UNINSTALLED) && (bundleState != Bundle.STOPPING)) {

                url = FileLocator.resolve(FileLocator.find(bundle, Path.ROOT, null));

                name = bundle.getHeaders().get(Constants.BUNDLE_NAME);
                version = bundle.getHeaders().get(Constants.BUNDLE_VERSION);

                if (StringUtils.isBlank(name) || StringUtils.isBlank(version)) {
                    break;
                }

                file = new File(url.getFile());

                if (!file.exists()) {
                    break;
                }

                path = file.getAbsolutePath() + ComponentPackUtils.SUFFIX;

                ComponentPackUtils.log.debug("CP named " + name + " was found at " + path); //$NON-NLS-1$ //$NON-NLS-2$
                packs.put(name, new JDEInfo(name, path, version));
            }
        } catch (final Throwable e) {
            ComponentPackUtils.log.error(e.getMessage(), e);
        }
    }
    return packs;
}

From source file:com.eincs.athens.android.OlympusFeedActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed);

    mContext = this;
    mBtnWrite = (TextView) findViewById(R.id.btn_write);
    mData = new TreeMap<Integer, Post>(new Comparator<Integer>() {

        @Override//from w w  w .j a v  a 2s.  co  m
        public int compare(Integer object1, Integer object2) {
            return object2 - object1;
        }
    });
    mDataArray = new ArrayList<Post>();
    mAdapter = new PostAdapter(this, R.layout.item_post, mDataArray);
    setListAdapter(mAdapter);

    mBtnWrite.setOnClickListener(this);
    getTimeline(null, null);
}