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.alacoder.lion.common.utils.StringTools.java

public static String toQueryString(Map<String, String> ps) {
    StringBuilder buf = new StringBuilder();
    if (ps != null && ps.size() > 0) {
        for (Map.Entry<String, String> entry : new TreeMap<String, String>(ps).entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (key != null && key.length() > 0 && value != null && value.length() > 0) {
                if (buf.length() > 0) {
                    buf.append("&");
                }/*  w  w  w .  j a v a 2 s.  c  o m*/
                buf.append(key);
                buf.append("=");
                buf.append(value);
            }
        }
    }
    return buf.toString();
}

From source file:com.medvision360.medrecord.pv.PVReader.java

public SortedMap<String, String> toMap(InputStream is) throws IOException, ParseException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rootNode = mapper.readValue(is, JsonNode.class);

    Iterator<Map.Entry<String, JsonNode>> fields = rootNode.fields();
    SortedMap<String, String> pv = new TreeMap<>(new ExactPathComparator());
    while (fields.hasNext()) {
        Map.Entry<String, JsonNode> field = fields.next();
        String key = field.getKey();
        JsonNode node = field.getValue();
        JsonNodeType nodeType = node.getNodeType();
        String value;//from   w ww .  ja v a  2s .  c om
        switch (nodeType) {
        case NULL:
            value = null;
            break;
        case BOOLEAN:
        case NUMBER:
        case STRING:
            value = node.asText();
            break;
        case ARRAY:
        case BINARY:
        case OBJECT:
        case MISSING:
        case POJO:
        default:
            throw new ParseException(
                    String.format("Path %s value is of type %s, need a primitive", key, nodeType));
        }
        pv.put(key, value);
    }

    return pv;
}

From source file:kr.co.aim.nanoframe.orm.SQLLogUtil.java

public static String getLogFormatSqlStatement(String sql, Object args, Log log) {
    try {//from w  w w .  ja va2s .c  o  m
        if (args instanceof Map) {
            Map<String, Object> map = (Map<String, Object>) args;

            TreeMap<String, Object> treeMap = new TreeMap<String, Object>(stringComparator);
            treeMap.putAll(map);

            Iterator<Entry<String, Object>> iter = treeMap.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, Object> entry = iter.next();
                sql = sql.replace(":" + entry.getKey(), getLogFormatArgument(entry.getValue()));
            }
        } else if (args instanceof Object[]) {
            Object[] objs = (Object[]) args;

            for (Object obj : objs) {
                sql = StringUtils.replaceOnce(sql, "?", getLogFormatArgument(obj));
            }
        }
    } catch (Throwable t) {
        if (log.isDebugEnabled())
            log.error(t, t);
        else
            log.error(t);
    }

    return sql;
}

From source file:forge.download.GuiDownloadPicturesLQ.java

@Override
protected final Map<String, String> getNeededFiles() {
    final Map<String, String> downloads = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    for (final PaperCard c : FModel.getMagicDb().getCommonCards().getAllCards()) {
        addDLObject(c, downloads, false);
        if (ImageUtil.hasBackFacePicture(c)) {
            addDLObject(c, downloads, true);
        }//from  w w  w  . j a v  a2s .  c  om
    }

    for (final PaperCard c : FModel.getMagicDb().getVariantCards().getAllCards()) {
        addDLObject(c, downloads, false);
    }

    // Add missing tokens to the list of things to download.
    addMissingItems(downloads, ForgeConstants.IMAGE_LIST_TOKENS_FILE, ForgeConstants.CACHE_TOKEN_PICS_DIR);

    return downloads;
}

From source file:forge.download.GuiDownloadSetPicturesLQ.java

@Override
protected final Map<String, String> getNeededFiles() {
    final Map<String, String> downloads = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

    for (final PaperCard c : Iterables.concat(FModel.getMagicDb().getCommonCards().getAllCards(),
            FModel.getMagicDb().getVariantCards().getAllCards())) {
        final String setCode3 = c.getEdition();
        if (StringUtils.isBlank(setCode3) || CardEdition.UNKNOWN.getCode().equals(setCode3)) {
            // we don't want cards from unknown sets
            continue;
        }// w w w .  j av a  2 s  .  c  om
        addDLObject(ImageUtil.getDownloadUrl(c, false), ImageUtil.getImageKey(c, false, true), downloads);

        if (ImageUtil.hasBackFacePicture(c)) {
            addDLObject(ImageUtil.getDownloadUrl(c, true), ImageUtil.getImageKey(c, true, true), downloads);
        }
    }

    // Add missing tokens to the list of things to download.
    addMissingItems(downloads, ForgeConstants.IMAGE_LIST_TOKENS_FILE, ForgeConstants.CACHE_TOKEN_PICS_DIR);

    return downloads;
}

From source file:forge.util.FileSection.java

public static Map<String, String> parseToMap(final String line, final String kvSeparator,
        final String pairSeparator) {
    Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    if (!StringUtils.isEmpty(line)) {
        final String[] pairs = line.split(Pattern.quote(pairSeparator));
        final Pattern splitter = Pattern.compile(Pattern.quote(kvSeparator));

        for (final String dd : pairs) {
            final String[] v = splitter.split(dd, 2);
            result.put(v[0].trim(), v.length > 1 ? v[1].trim() : "");
        }//ww  w  .ja v a2s . c  om
    }
    return result;
}

From source file:org.psnively.scala.beans.ScalaBeanInfo.java

private static PropertyDescriptor[] initPropertyDescriptors(BeanInfo beanInfo) {
    Map<String, PropertyDescriptor> propertyDescriptors = new TreeMap<String, PropertyDescriptor>(
            new PropertyNameComparator());
    for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
        propertyDescriptors.put(pd.getName(), pd);
    }/*  www .j  av  a 2  s .  com*/

    for (MethodDescriptor md : beanInfo.getMethodDescriptors()) {
        Method method = md.getMethod();

        if (ReflectionUtils.isObjectMethod(method)) {
            continue;
        }
        if (isScalaSetter(method)) {
            addScalaSetter(propertyDescriptors, method);
        } else if (isScalaGetter(method)) {
            addScalaGetter(propertyDescriptors, method);
        }
    }
    return propertyDescriptors.values().toArray(new PropertyDescriptor[propertyDescriptors.size()]);
}

From source file:com.kpb.other.AcmeCorpPhysicalNamingStrategy.java

private static Map<String, String> buildAbbreviationMap() {
    TreeMap<String, String> abbreviationMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    abbreviationMap.put("account", "acct");
    abbreviationMap.put("number", "num");
    return abbreviationMap;
}

From source file:com.ebay.erl.mobius.core.mapred.MultiInputsHelpersRepository.java

/**
 * constructor//from  w  w w .  j a v  a 2s  .co  m
 */
private MultiInputsHelpersRepository(JobConf conf) {
    this.mapping = new TreeMap<Class<? extends InputFormat>, MultiInputsHelper>(new ClassComparator());

    this.register(FileInputFormat.class, FileInputFormatHelper.class);

    if (!conf.get("mobius.multi.inputs.helpers", "").isEmpty()) {
        // mobius.multi.inputs.helpers in the format of> InputFormatClassName:HelperClassName(,InputFormatClassName:HelperClassName)?
        String[] helpers = conf.getStrings("mobius.multi.inputs.helpers");
        for (String aHeler : helpers) {
            String[] data = aHeler.split(":");
            String inputFormatClassName = data[0];
            String helperClassName = data[1];

            Class<? extends InputFormat> inputFormat = (Class<? extends InputFormat>) Util
                    .getClass(inputFormatClassName);
            Class<? extends MultiInputsHelper> helperClass = (Class<? extends MultiInputsHelper>) Util
                    .getClass(helperClassName);

            this.register(inputFormat, helperClass);
        }
    }
}

From source file:eu.forgestore.ws.util.HeadersOutInterceptor.java

@Override
public void handleMessage(Message outMessage) throws Fault {

    Map<String, List<String>> headers = (Map<String, List<String>>) outMessage.get(Message.PROTOCOL_HEADERS);

    if (headers == null) {
        headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);

        List<String> vl = new ArrayList<String>();
        vl.add("1.0.0");
        headers.put("X-Baker-API-Version", vl);
        //         vl = new ArrayList<String>();
        //         vl.add("*");
        //         headers.put("Access-Control-Allow-Origin", vl);         
        outMessage.put(Message.PROTOCOL_HEADERS, headers);
    }/*from w  w w . j a  v a2  s .com*/

    // modify headers

}