Example usage for java.util SortedMap size

List of usage examples for java.util SortedMap size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings in this map.

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//  www .  j a  va  2 s .c om
        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());
    }/*  w  ww.ja v a 2s.  c o  m*/
    LOG.info("Added " + checksumMap.size() + " checksums for snapshot files.");
    return checksumMap;
}

From source file:com.redhat.rhn.frontend.action.kickstart.PowerManagementAction.java

/**
 * Sets up and returns a list of supported Cobbler power types.
 * @param request the current request/* w  ww . j a va  2 s .c  o  m*/
 * @param strutsDelegate the Struts delegate
 * @param errors ActionErrors that might have already been raised
 * @return the types
 */
public static SortedMap<String, String> setUpPowerTypes(HttpServletRequest request,
        StrutsDelegate strutsDelegate, ActionErrors errors) {
    SortedMap<String, String> types = new TreeMap<String, String>();
    String typeString = ConfigDefaults.get().getCobblerPowerTypes();
    if (typeString != null) {
        List<String> typeNames = Arrays.asList(typeString.split(" *, *"));
        for (String typeName : typeNames) {
            types.put(LocalizationService.getInstance().getPlainText("cobbler.powermanagement." + typeName),
                    typeName);
        }
    }
    request.setAttribute(TYPES, types);

    if (types.size() == 0) {
        strutsDelegate.addError(errors, "kickstart.powermanagement.jsp.no_types",
                ConfigDefaults.POWER_MANAGEMENT_TYPES);
        strutsDelegate.saveMessages(request, errors);
    }
    return types;
}

From source file:cherry.foundation.telno.AreaCodeTableFactoryTest.java

@Test
public void test() throws Exception {

    List<Resource> resources = new ArrayList<>(9);
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124070.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124071.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124072.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124073.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124074.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124075.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124076.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124077.xls"));
    resources.add(new ClassPathResource("cherry/goods/telno/soumu/000124078.xls"));
    AreaCodeTableFactory factory = new AreaCodeTableFactory();
    factory.setSoumuExcelParser(new SoumuExcelParser());
    factory.setResources(resources);// w  w w .j  a v a2  s  . com

    Trie<String, Integer> trie = factory.getObject();
    SortedMap<String, Integer> map = trie.prefixMap("042");
    assertEquals(790, map.size());
    assertEquals(new TreeSet<Integer>(asList(2, 3, 4)), new TreeSet<>(map.values()));

    assertEquals(4554 + 5683 + 3400 + 5343 + 5307 + 3000 + 5548 + 4526 + 5330, trie.size());
    assertEquals(Trie.class, factory.getObjectType());
    assertFalse(factory.isSingleton());
}

From source file:edu.cmu.sv.modelinference.eventtool.PredictionModel.java

PredictionModel(SortedMap<Integer, Double> upperThreshold, SortedMap<Integer, Double> lowerThreshold) {
    checkArgument(upperThreshold.size() == lowerThreshold.size());
    this.upperThreshold = upperThreshold;
    this.lowerThreshold = lowerThreshold;
}

From source file:com.aqnote.app.wifianalyzer.vendor.model.VendorServiceTest.java

@Test
public void testFindAll() throws Exception {
    // setup/*from ww w . ja  va 2 s. co  m*/
    List<VendorData> vendorDatas = withVendorDatas();
    when(database.findAll()).thenReturn(vendorDatas);
    // execute
    SortedMap<String, List<String>> actual = fixture.findAll();
    // validate
    verify(database).findAll();

    assertEquals(3, actual.size());
    assertEquals(1, actual.get(VendorNameUtils.cleanVendorName(vendorDatas.get(0).getName())).size());
    assertEquals(3, actual.get(VendorNameUtils.cleanVendorName(vendorDatas.get(1).getName())).size());
    assertEquals(1, actual.get(VendorNameUtils.cleanVendorName(vendorDatas.get(4).getName())).size());

    List<String> macs = actual.get(VendorNameUtils.cleanVendorName(vendorDatas.get(1).getName()));
    assertEquals(vendorDatas.get(3).getMac(), macs.get(0));
    assertEquals(vendorDatas.get(1).getMac(), macs.get(1));
    assertEquals(vendorDatas.get(2).getMac(), macs.get(2));
}

From source file:com.vrem.wifianalyzer.vendor.model.VendorServiceTest.java

@Test
public void testFindAll() throws Exception {
    // setup/*from ww  w . j  ava2s .co m*/
    List<VendorData> vendorData = withVendorData();
    when(database.findAll()).thenReturn(vendorData);
    // execute
    SortedMap<String, List<String>> actual = fixture.findAll();
    // validate
    verify(database).findAll();

    assertEquals(3, actual.size());
    assertEquals(1, actual.get(VendorNameUtils.cleanVendorName(vendorData.get(0).getName())).size());
    assertEquals(3, actual.get(VendorNameUtils.cleanVendorName(vendorData.get(1).getName())).size());
    assertEquals(1, actual.get(VendorNameUtils.cleanVendorName(vendorData.get(4).getName())).size());

    List<String> macs = actual.get(VendorNameUtils.cleanVendorName(vendorData.get(1).getName()));
    assertEquals(vendorData.get(3).getMac(), macs.get(0));
    assertEquals(vendorData.get(1).getMac(), macs.get(1));
    assertEquals(vendorData.get(2).getMac(), macs.get(2));
}

From source file:fr.gael.dhus.util.functional.collect.SortedMapTest.java

/** Constructor: Empty map param. */
@Test// w  ww  .  jav  a2  s. c  om
public void emptyMapTest() {
    SortedMap sorted_map = new SortedMap(Collections.emptyMap(), cmp);
    Assert.assertTrue(sorted_map.isEmpty());
    Assert.assertEquals(sorted_map.size(), 0);
    Assert.assertFalse(sorted_map.keySet().iterator().hasNext());
    Assert.assertFalse(sorted_map.values().iterator().hasNext());
    Assert.assertFalse(sorted_map.entrySet().iterator().hasNext());
}

From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java

/**
 * Affichage des facteurs du Kiviat : tous les facteurs ou seulement ceux ayant une note
 * /*from   w  w  w . j a v  a  2 s .c o  m*/
 * @param pValues les donnes  afficher : facteur + note
 * @param pNullValuesList la liste des facteurs dont la note est nulle
 * @param pAllFactors tous les facteurs (="true") ou seulement les facteurs ayant une note
 * @param pFactorsMin nombre de facteurs minimal que l'on doit afficher sur le Kiviat
 * @return values les donnes rellement  afficher : facteur + note
 */
private static SortedMap deleteFactors(SortedMap pValues, ArrayList pNullValuesList, String pAllFactors,
        int pFactorsMin) {
    SortedMap values = new TreeMap();
    // Seulement les facteurs ayant une note ? ==> suppression des facteurs ayant une note nulle.
    // Mais trois facteurs doivent au moins s'afficher (nuls ou pas !)
    if (pValues.size() > pFactorsMin && !pAllFactors.equals("true")) {
        // Nombre de suppressions possible
        int nbTotalDeletions = pValues.size() - pFactorsMin;
        // Nombre de suppressions effectu
        int nbCurrentDeletions = 0;
        // Parcours de la liste des facteurs avec une note nulle, pour les supprimer de l'affichage
        Iterator itList = pNullValuesList.iterator();
        while (itList.hasNext() && nbCurrentDeletions < nbTotalDeletions) {
            String keyListe = (String) itList.next();
            pValues.remove(keyListe);
            nbCurrentDeletions += 1;
        }
    }
    values.putAll(pValues);
    return values;
}

From source file:com.jts.rest.profileservice.utils.RestServiceHelper.java

/**
 * Uses MemberChallenge service to get all the associated challenge information for a user
 * Sorts the challenge information with end date
 * Returns all the active challenges and 3 most recent past challenge 
 * @param sessionId//w  w  w. jav a  2  s.  co  m
 * @param username
 * @return
 * @throws MalformedURLException
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static JSONObject getProcessedChallengesM1(String sessionId, String username)
        throws MalformedURLException, IOException {
    //get all challenges
    JSONArray challenges = getChallenges(sessionId, username);

    JSONArray activeChallenges = new JSONArray();
    JSONArray pastChallenges = new JSONArray();
    SortedMap<Long, JSONObject> pastChallengesByDate = new TreeMap<Long, JSONObject>();
    Iterator<JSONObject> iterator = challenges.iterator();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-ddhh:mm:ss");

    while (iterator.hasNext()) {
        JSONObject challenge = iterator.next();
        //identify active challenge with status
        if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) {
            activeChallenges.add(challenge);
        } else {
            String endDateStr = ((String) challenge.get("End_Date__c")).replace("T", "");
            Date date = new Date();
            try {
                date = dateFormat.parse(endDateStr);
            } catch (ParseException pe) {
                logger.log(Level.SEVERE, "Error occurent while parsing date " + endDateStr);
            }
            pastChallengesByDate.put(date.getTime(), challenge);
        }
    }

    //from the sorted map extract the recent challenge
    int pastChallengeSize = pastChallengesByDate.size();
    if (pastChallengeSize > 0) {
        Object[] challengeArr = (Object[]) pastChallengesByDate.values().toArray();
        int startIndex = pastChallengeSize > 3 ? pastChallengeSize - 3 : 0;
        for (int i = startIndex; i < pastChallengeSize; i++) {
            pastChallenges.add(challengeArr[i]);
        }
    }
    JSONObject resultChallenges = new JSONObject();
    resultChallenges.put("activeChallenges", activeChallenges);
    resultChallenges.put("pastChallenges", pastChallenges);
    resultChallenges.put("totalChallenges", challenges.size());
    return resultChallenges;
}