Example usage for java.util SortedMap put

List of usage examples for java.util SortedMap put

Introduction

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

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.griddynamics.jagger.engine.e1.scenario.DefaultWorkloadSuggestionMaker.java

private static Integer findClosestPoint(BigDecimal desiredTps, Map<Integer, Pair<Long, BigDecimal>> stats) {
    final int MAX_POINTS_FOR_REGRESSION = 10;

    SortedMap<Long, Integer> map = Maps.newTreeMap(new Comparator<Long>() {
        @Override/*from   w w w. ja v  a 2  s .  co  m*/
        public int compare(Long first, Long second) {
            return second.compareTo(first);
        }
    });
    for (Map.Entry<Integer, Pair<Long, BigDecimal>> entry : stats.entrySet()) {
        map.put(entry.getValue().getFirst(), entry.getKey());
    }

    if (map.size() < 2) {
        throw new IllegalArgumentException("Not enough stats to calculate point");
    }

    // <time><number of threads> - sorted by time
    Iterator<Map.Entry<Long, Integer>> iterator = map.entrySet().iterator();

    SimpleRegression regression = new SimpleRegression();
    Integer tempIndex;
    double previousValue = -1.0;
    double value;
    double measuredTps;

    log.debug("Selecting next point for balancing");
    int indx = 0;
    while (iterator.hasNext()) {

        tempIndex = iterator.next().getValue();

        if (previousValue < 0.0) {
            previousValue = tempIndex.floatValue();
        }
        value = tempIndex.floatValue();
        measuredTps = stats.get(tempIndex).getSecond().floatValue();

        regression.addData(value, measuredTps);

        log.debug(String.format("   %7.2f    %7.2f", value, measuredTps));

        indx++;
        if (indx > MAX_POINTS_FOR_REGRESSION) {
            break;
        }
    }

    double intercept = regression.getIntercept();
    double slope = regression.getSlope();

    double approxPoint;

    // if no slope => use previous number of threads
    if (Math.abs(slope) > 1e-12) {
        approxPoint = (desiredTps.doubleValue() - intercept) / slope;
    } else {
        approxPoint = previousValue;
    }

    // if approximation point is negative - ignore it
    if (approxPoint < 0) {
        approxPoint = previousValue;
    }

    log.debug(String.format("Next point   %7d    (target tps: %7.2f)", (int) Math.round(approxPoint),
            desiredTps.doubleValue()));

    return (int) Math.round(approxPoint);
}

From source file:co.cask.cdap.data.tools.ReplicationStatusTool.java

private static SortedMap<String, String> getClusterChecksumMap() throws IOException {
    FileSystem fileSystem = FileSystem.get(hConf);
    List<String> fileList = addAllFiles(fileSystem);
    SortedMap<String, String> checksumMap = new TreeMap<String, String>();
    for (String file : fileList) {
        FileChecksum fileChecksum = fileSystem.getFileChecksum(new Path(file));
        checksumMap.put(normalizedFileName(file), fileChecksum.toString());
    }//from   w  w  w.j av a 2s  .c o m
    LOG.info("Added " + checksumMap.size() + " checksums for snapshot files.");
    return checksumMap;
}

From source file:co.rsk.peg.BridgeSerializationUtils.java

public static SortedMap<Sha3Hash, BtcTransaction> deserializeMap(byte[] data,
        NetworkParameters networkParameters) {
    SortedMap<Sha3Hash, BtcTransaction> map = new TreeMap<>();

    if (data == null || data.length == 0)
        return map;

    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);

    int ntxs = rlpList.size() / 2;

    for (int k = 0; k < ntxs; k++) {
        Sha3Hash hash = new Sha3Hash(rlpList.get(k * 2).getRLPData());
        BtcTransaction tx = new BtcTransaction(networkParameters, rlpList.get(k * 2 + 1).getRLPData());
        map.put(hash, tx);
    }//from   w w  w  .  java2 s.  co  m

    return map;
}

From source file:com.dell.asm.asmcore.asmmanager.util.razor.RazorUtil.java

public static SortedMap<String, RazorDevice> getRazorDevicesHelper() {
    ObjectMapper mapper = new ObjectMapper();
    WebClient client = WebClient.create(AsmManagerApp.razorApiUrl);
    client.accept("application/json");
    String json = client.path("collections/nodes").get(String.class);

    try {/*from   w  w w.jav a2 s  .  c  o m*/
        List<String> nodeNames = RazorUtil.parseNodeNamesJson(mapper, json);
        SortedMap<String, RazorDevice> ret = new TreeMap<>();
        for (String name : nodeNames) {
            String nodeJson = client.path(name).get(String.class);
            RazorDevice device = RazorUtil.parseNodeJson(mapper, nodeJson);
            if (StringUtils.isEmpty(device.getId())) {
                LOGGER.warn("Failed to get id for razor node: " + nodeJson);
            } else {
                ret.put(device.getId(), device);
            }
            client.back(false);
        }
        return ret;
    } catch (IOException e) {
        throw new AsmManagerRuntimeException(e);
    }
}

From source file:co.cask.cdap.logging.save.LogSaverPluginTest.java

private static Location getLatestFile(Location logBaseDir, String filePattern) throws Exception {
    String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    Location dir = logBaseDir.append(String.format(filePattern, date));

    if (!dir.exists()) {
        return null;
    }//from www.j  ava 2s  .  c  o m

    List<Location> files = dir.list();
    if (files.isEmpty()) {
        return null;
    }

    SortedMap<Long, Location> map = Maps.newTreeMap();
    for (Location file : files) {
        String filename = FilenameUtils.getBaseName(file.getName());
        map.put(Long.parseLong(filename), file);
    }
    return map.get(map.lastKey());
}

From source file:com.facebook.buck.util.unarchive.Unzip.java

/**
 * Get a listing of all files in a zip file
 *
 * @param zip The zip file to scan/*from  w  ww.  j av a  2 s. c  om*/
 * @param relativePath The relative path where the extraction will be rooted
 * @return The list of paths in {@code zip} sorted by path so dirs come before contents.
 */
private static SortedMap<Path, ZipArchiveEntry> getZipFilePaths(ZipFile zip, Path relativePath,
        PatternsMatcher entriesToExclude) {
    SortedMap<Path, ZipArchiveEntry> pathMap = new TreeMap<>();
    for (ZipArchiveEntry entry : Collections.list(zip.getEntries())) {
        String entryName = entry.getName();
        if (entriesToExclude.matchesAny(entryName)) {
            continue;
        }
        Path target = relativePath.resolve(entryName).normalize();
        pathMap.put(target, entry);
    }
    return pathMap;
}

From source file:io.wcm.caravan.commons.httpclient.impl.BeanUtil.java

/**
 * Get map with key/value pairs for properties of a java bean (using {@link BeanUtils#describe(Object)}).
 * An array of property names can be passed that should be masked with "***" because they contain sensitive
 * information./* w w  w .  j  av  a 2  s . c om*/
 * @param beanObject Bean object
 * @param maskProperties List of property names
 * @return Map with masked key/value pairs
 */
public static SortedMap<String, Object> getMaskedBeanProperties(Object beanObject, String[] maskProperties) {
    try {
        SortedMap<String, Object> configProperties = new TreeMap<String, Object>(
                BeanUtils.describe(beanObject));

        // always ignore "class" properties which is added by BeanUtils.describe by default
        configProperties.remove("class");

        // Mask some properties with confidential information (if set to any value)
        if (maskProperties != null) {
            for (String propertyName : maskProperties) {
                if (configProperties.containsKey(propertyName) && configProperties.get(propertyName) != null) {
                    configProperties.put(propertyName, "***");
                }
            }
        }

        return configProperties;
    } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
        throw new IllegalArgumentException("Unable to get properties from: " + beanObject, ex);
    }
}

From source file:org.shept.util.FileUtils.java

/**
 * List the file directory as specified by the name filter and the path directory
 * The maps keys contain name and modification date for comparison
 *//*from ww  w.ja v  a  2  s . com*/
public static SortedMap<FileNameDate, File> fileMapByNameAndDate(String path, String filePattern) {
    FileUtils fu = new FileUtils(); // needed for inner class
    SortedMap<FileNameDate, File> newFileMap = new TreeMap<FileNameDate, File>();
    File fileDir = new File(path);
    if (null != path && fileDir.isDirectory()) {
        FileFilter filter = fu.new Filter(path, filePattern);
        File[] files = fileDir.listFiles(filter);
        for (int i = 0; i < files.length; i++) {
            FileNameDate fk = new FileNameDate(files[i].getName(), files[i].lastModified());
            newFileMap.put(fk, files[i]);
        }
    }
    return newFileMap;
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.filter.GWikiChangeNotificationActionBean.java

/**
 * Parses the not line.//from   w  w  w  .  j  av a 2  s  .c  om
 *
 * @param line the line
 * @return the sorted map
 */
public static SortedMap<String, Boolean> parseNotLine(String line) {
    SortedMap<String, Boolean> ret = new TreeMap<String, Boolean>();
    List<String> tks = Converter.parseStringTokens(line, ", ", false);
    for (String tk : tks) {
        List<String> t = Converter.parseStringTokens(tk, "=", false);
        if (t.size() == 2) {
            ret.put(t.get(0), Boolean.valueOf(t.get(1)));
        } else {
            ret.put(t.get(0), Boolean.FALSE);
        }
    }
    return ret;
}

From source file:org.shept.util.FileUtils.java

/**
 * List the file directory as specified by the name filter and path directory
 * The maps keys contain modification dat for comparison
 * @param path//from  w ww.  ja v a  2 s  .  c om
 * @param filePattern
 * @return
 */
public static SortedMap<Calendar, File> fileMapByDate(String path, String filePattern) {
    FileUtils fu = new FileUtils(); // needed for inner class
    SortedMap<Calendar, File> newFileMap = new TreeMap<Calendar, File>();
    File fileDir = new File(path);
    if (null != path && fileDir.isDirectory()) {
        FileFilter filter = fu.new Filter(path, filePattern);
        File[] files = fileDir.listFiles(filter);
        for (int i = 0; i < files.length; i++) {
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(files[i].lastModified());
            newFileMap.put(cal, files[i]);
        }
    }
    return newFileMap;
}