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() 

Source Link

Document

Constructs a new, empty tree map, using the natural ordering of its keys.

Usage

From source file:org.apache.solr.kelvin.SingletonTestRegistry.java

public static void configure(JsonNode config) throws Exception {
    registry.configure(config);// ww w  . jav  a2  s .  c o  m
    //default built in conditions
    Map<String, Class<?>> defaults = new TreeMap<String, Class<?>>();
    //defaults.put(null, SimpleTestCase.class);
    defaults.put("", SimpleTestCase.class);
    defaults.put("default", SimpleTestCase.class);
    registry.addMappingsFromClasses(defaults);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.F1ScoreTableAggregator.java

public static void evaluatePredictionsFoldersFullCV(File masterFolder) throws Exception {
    SortedMap<String, List<String>> featureSetsResults = new TreeMap<>();

    File[] foldersFeatureSets = masterFolder.listFiles(EvalHelper.DIRECTORY_FILTER);

    for (File folderFeatureSet : foldersFeatureSets) {
        String[] split = folderFeatureSet.getName().split("_");
        String featureSet = split[0];
        String paramE = split[1];
        String paramT = split[2];

        if ("e0".equals(paramE) && "t1".equals(paramT)) {

            Map<String, File> foldersData = EvalHelper.listSubFoldersAndRemoveUUID(folderFeatureSet);
            for (Map.Entry<String, File> folderData : foldersData.entrySet()) {

                String data = folderData.getKey();

                if (data.contains("ArgumentSequenceLabelingCV")) {
                    File resultSummary = new File(folderData.getValue(), "resultSummary.txt");

                    List<String> values = extractValues(resultSummary);

                    featureSetsResults.put(featureSet, values);
                }/*  w  w  w  .  j  a v a  2 s .c o m*/
            }
        }
    }

    // print results
    int rows = featureSetsResults.values().iterator().next().size();
    for (String featureSet : featureSetsResults.keySet()) {
        System.out.printf("%s\t", featureSet);
    }
    System.out.println();
    for (int i = 0; i < rows; i++) {
        for (List<String> result : featureSetsResults.values()) {
            System.out.printf("%s\t", result.get(i));
        }
        System.out.println();
    }
}

From source file:Main.java

/**
 * //w  w  w .ja va  2s . co m
 * @param element
 * @param identifyingProperties
 * @return Map
 */
public static Map<String, String> getResult(final Element element,
        final Collection<String> identifyingProperties) {
    // for each identifying property get that property value for this
    // document
    final String SEPARATOR = "; "; //$NON-NLS-1$
    final Map<String, String> result = new TreeMap<>();

    for (Iterator<String> identifyingPropertiesIterator = identifyingProperties
            .iterator(); identifyingPropertiesIterator.hasNext();) {
        final String identifyingProperty = identifyingPropertiesIterator.next();
        final List<String> newValues = getDOMElementTextByTagName(element, identifyingProperty, ALL_VALUES);
        final String existingValue = result.get(identifyingProperty);

        if (existingValue != null) {
            newValues.add(existingValue);
        }

        final StringBuffer buffer = new StringBuffer();

        boolean needsSeperator = false;

        for (Iterator<String> newValuesIterator = newValues.iterator(); newValuesIterator.hasNext();) {
            if (needsSeperator) {
                buffer.append(SEPARATOR);
            }

            final String value = newValuesIterator.next();

            if (value != null) {
                buffer.append(value);
            }

            needsSeperator = true;
        }

        result.put(identifyingProperty, buffer.toString());
    }

    return result;
}

From source file:gov.nih.nci.calims2.taglib.form.SingleSelectHelper.java

/**
 * Interprets the properties String and returns a map of property name to expressions.
 * /*from w  w w. ja v  a  2 s  .  com*/
 * @param propertyString The string to interpret
 * @return The properties expression map
 */
static Map<String, Expression> getPropertyMap(String propertyString) {
    ExpressionParser expressionParser = new SpelExpressionParser();
    Map<String, Expression> map = new TreeMap<String, Expression>();
    if (propertyString != null) {
        for (String propertySpec : propertyString.split(",")) {
            String[] propertyElements = propertySpec.split(":");
            if (propertyElements == null || propertyElements.length != 2) {
                throw new IllegalArgumentException("Invalid property specification: " + propertySpec);
            }
            String name = StringUtils.stripToNull(propertyElements[0]);
            if (name == null) {
                throw new IllegalArgumentException("Invalid property name");
            }
            String value = StringUtils.stripToNull(propertyElements[1]);
            if (value == null) {
                throw new IllegalArgumentException("Invalid property value");
            }
            map.put(name, expressionParser.parseExpression(value));
        }

    }
    return map;
}

From source file:org.apache.solr.kelvin.SingletonConditionRegistry.java

public static void configure(JsonNode config) throws Exception {
    registry.configure(config);/*ww  w  .j a va 2s. com*/
    //default built in conditions
    Map<String, Class<?>> defaults = new TreeMap<String, Class<?>>();
    //defaults.put(null, SimpleCondition.class);
    defaults.put("", SimpleCondition.class);
    defaults.put("default", SimpleCondition.class);
    defaults.put("valueList", ValueListCondition.class);
    defaults.put("dateRange", DateRangeCondition.class);
    defaults.put("slug", ValueListCondition.class); //legacy
    registry.addMappingsFromClasses(defaults);
}

From source file:bigbluej.ReflectionUtils.java

public static SortedMap<String, Object> getFieldsAndValuesInSortedMap(Object object)
        throws IllegalAccessException {
    Validate.notNull(object);//from   w  ww.j  a  v a2  s.  c o m
    SortedMap<String, Object> fieldAndValues = new TreeMap<>();
    for (Field field : object.getClass().getDeclaredFields()) {
        field.setAccessible(true);
        String name = field.getName();
        Object value = field.get(object);
        if (!field.isSynthetic() && value != null) {
            fieldAndValues.put(name, value);
        }
    }
    return fieldAndValues;
}

From source file:Main.java

/**
 * Remove identical adjacent tags from {@code decorations}.
 * /* w w w.j  ava2  s.c o  m*/
 * @param decorations see {@link prettify.parser.Job#decorations}
 * @param source the source code
 * 
 * @return the {@code decorations} after treatment
 * 
 * @throws IllegalArgumentException the size of {@code decoration} is not
 * a multiple of 2
 */
public static List<Object> removeDuplicates(List<Object> decorations, String source) {
    if (decorations == null) {
        throw new NullPointerException("argument 'decorations' cannot be null");
    }
    if (source == null) {
        throw new NullPointerException("argument 'source' cannot be null");
    }
    if ((decorations.size() & 0x1) != 0) {
        throw new IllegalArgumentException("the size of argument 'decorations' should be a multiple of 2");
    }

    List<Object> returnList = new ArrayList<Object>();

    // use TreeMap to remove entrys with same pos
    Map<Integer, Object> orderedMap = new TreeMap<Integer, Object>();
    for (int i = 0, iEnd = decorations.size(); i < iEnd; i += 2) {
        orderedMap.put((Integer) decorations.get(i), decorations.get(i + 1));
    }

    // remove adjacent style
    String previousStyle = null;
    for (Integer pos : orderedMap.keySet()) {
        String style = (String) orderedMap.get(pos);
        if (previousStyle != null && previousStyle.equals(style)) {
            continue;
        }
        returnList.add(pos);
        returnList.add(style);
        previousStyle = style;
    }

    // remove last zero length tag
    int returnListSize = returnList.size();
    if (returnListSize >= 4 && returnList.get(returnListSize - 2).equals(source.length())) {
        returnList.remove(returnListSize - 2);
        returnList.remove(returnListSize - 2);
    }

    return returnList;
}

From source file:Main.java

/**
 * @param r//  ww  w . java 2  s. c  o  m
 *          the original rectangle
 * @param includeReservedInsets
 *          if taskbar and other windowing insets should be included in the
 *          returned area
 * @return iff there are multiple monitors the other monitor than the
 *         effective view of the monitor that the rectangle mostly coveres, or
 *         null if there is just one screen
 */
public static Rectangle getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    TreeMap<Integer, Rectangle> prioMap = new TreeMap<Integer, Rectangle>();
    for (GraphicsDevice dev : ge.getScreenDevices()) {
        Rectangle bounds;
        if ((!includeReservedInsets) && dev == ge.getDefaultScreenDevice()) {
            bounds = ge.getMaximumWindowBounds();
        } else {
            bounds = dev.getDefaultConfiguration().getBounds();
        }
        Rectangle intersection = bounds.intersection(r);
        prioMap.put(intersection.width * intersection.height, bounds);
    }
    if (prioMap.size() <= 1) {
        return null;
    } else {
        return prioMap.get(prioMap.firstKey());
    }
}

From source file:Main.java

public static <K, V> Map<K, V> createTreeMapIfNull(Map<K, V> map) {
    if (map == null) {
        map = new TreeMap<K, V>();
    }//from   www. jav a 2  s .co m
    return map;
}

From source file:api.Status.java

public static Result getStatus() {
    ObjectNode metrics = Json.newObject();

    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    TreeMap<String, Object> values = new TreeMap<String, Object>();
    for (Method method : os.getClass().getDeclaredMethods()) {
        method.setAccessible(true);/*from   ww  w.  j a  v  a 2  s.  c om*/
        if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
            Object value;
            try {
                value = method.invoke(os);
                values.put(method.getName(), value);
            } catch (Exception e) {
                Logger.warn("Error when invoking " + os.getClass().getName()
                        + " (OperatingSystemMXBean) method " + method.getName() + ": " + e);
            } // try
        } // if
    } // for

    metrics.put("jvmLoad", (Double) values.get("getProcessCpuLoad"));
    metrics.put("cpuLoad", (Double) values.get("getSystemCpuLoad"));
    metrics.put("openFD", (Long) values.get("getOpenFileDescriptorCount"));
    metrics.put("maxFD", (Long) values.get("getMaxFileDescriptorCount"));
    metrics.put("freeMemory", (Long) values.get("getFreePhysicalMemorySize"));
    metrics.put("totalMemory", (Long) values.get("getTotalPhysicalMemorySize"));

    return ok(metrics.toString());
}