Example usage for java.util SortedSet last

List of usage examples for java.util SortedSet last

Introduction

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

Prototype

E last();

Source Link

Document

Returns the last (highest) element currently in this set.

Usage

From source file:com.espertech.esper.filter.TestFilterSpecParamComparator.java

public void testCompareAll() {
    SortedSet<FilterOperator> sorted = new TreeSet<FilterOperator>(comparator);

    for (int i = 0; i < FilterOperator.values().length; i++) {
        FilterOperator op = FilterOperator.values()[i];
        sorted.add(op);// w w w  . j  av a  2s  .co m
    }

    assertEquals(FilterOperator.EQUAL, sorted.first());
    assertEquals(FilterOperator.BOOLEAN_EXPRESSION, sorted.last());
    assertEquals(
            "[EQUAL, IS, IN_LIST_OF_VALUES, RANGE_OPEN, RANGE_HALF_OPEN, RANGE_HALF_CLOSED, RANGE_CLOSED, LESS, LESS_OR_EQUAL, GREATER_OR_EQUAL, GREATER, NOT_RANGE_CLOSED, NOT_RANGE_HALF_CLOSED, NOT_RANGE_HALF_OPEN, NOT_RANGE_OPEN, NOT_IN_LIST_OF_VALUES, NOT_EQUAL, IS_NOT, BOOLEAN_EXPRESSION]",
            sorted.toString());

    log.debug(".testCompareAll " + Arrays.toString(sorted.toArray()));
}

From source file:com.gtwm.pb.model.manageData.WordCloud.java

/**
 * @param textLowerCase/* w ww .jav  a2s . c  om*/
 *            Input text, must be lower case
 * @param minWeight
 *            Minimum tag weight, e.g. a font size
 * @param maxWeight
 *            Max. tag weight
 * @param maxTags
 *            Maximum number of tags to return, -1 for all tags
 * @param additionalStopWords
 *            Set of words to specifically exclude, in addition to the
 *            standard set [and, not, after, yes, no, ...]
 */
public WordCloud(String textLowerCase, int minWeight, int maxWeight, int maxTags,
        Set<String> additionalStopWords) {
    String[] wordArray = textLowerCase.split("\\W");
    Set<String> stopWords = new HashSet<String>(Arrays.asList(stopWordsArray));
    for (String additionalStopWord : additionalStopWords) {
        stopWords.add(additionalStopWord.toLowerCase().trim());
    }
    LancasterStemmer stemmer = new LancasterStemmer();
    String wordStem;
    Frequency frequencies = new Frequency();
    for (String wordString : wordArray) {
        if ((!stopWords.contains(wordString)) && (wordString.length() >= minWordLength)) {
            wordStem = stemmer.stripSuffixes(wordString);
            // Record the mapping of the stem to its origin so the most
            // common origin can be re-introduced when the cloud is
            // generated
            this.recordStemOrigin(wordString, wordStem);
            frequencies.addValue(wordStem);
        }
    }
    // Compute std. dev of frequencies so we can remove outliers
    DescriptiveStatistics stats = new DescriptiveStatistics();
    Iterator freqIt = frequencies.valuesIterator();
    long stemFreq;
    while (freqIt.hasNext()) {
        stemFreq = frequencies.getCount(freqIt.next());
        stats.addValue(stemFreq);
    }
    double mean = stats.getMean();
    double stdDev = stats.getStandardDeviation();
    long minFreq = Long.MAX_VALUE;
    long maxFreq = 0;
    // Remove outliers
    freqIt = frequencies.valuesIterator();
    int upperLimit = (int) (mean + (stdDev * 10));
    int lowerLimit = (int) (mean - stdDev);
    if (lowerLimit < 2) {
        lowerLimit = 2;
    }
    int numWords = 0;
    int numRawWords = wordArray.length;
    boolean removeLowOutliers = (numRawWords > (maxTags * 10));
    while (freqIt.hasNext()) {
        wordStem = (String) freqIt.next();
        stemFreq = frequencies.getCount(wordStem);
        // For a large input set, remove high and low outliers.
        // For a smaller set, just high freq. outliers
        if ((stemFreq > upperLimit) || ((stemFreq < lowerLimit) && removeLowOutliers)) {
            freqIt.remove();
        } else {
            numWords++;
            if (stemFreq > maxFreq) {
                maxFreq = stemFreq;
            } else if (stemFreq < minFreq) {
                minFreq = stemFreq;
            }
        }
    }
    // Cut down to exact required number of tags by removing smallest
    if (lowerLimit < minFreq) {
        lowerLimit = (int) minFreq;
    }
    if (numWords > maxTags) {
        while (numWords > maxTags) {
            freqIt = frequencies.valuesIterator();
            SMALLREMOVAL: while (freqIt.hasNext()) {
                stemFreq = frequencies.getCount(freqIt.next());
                if (stemFreq < lowerLimit) {
                    freqIt.remove();
                    numWords--;
                    if (numWords == maxTags) {
                        break SMALLREMOVAL;
                    }
                }
            }
            int step = (int) ((mean - lowerLimit) / 3);
            if (step < 1) {
                step = 1;
            }
            lowerLimit += step;
        }
        // The new min. freq. may have changed
        minFreq = Long.MAX_VALUE;
        freqIt = frequencies.valuesIterator();
        while (freqIt.hasNext()) {
            stemFreq = frequencies.getCount(freqIt.next());
            if (stemFreq < minFreq) {
                minFreq = stemFreq;
            }
        }
    }
    // Scale and create tag objects
    double scaleFactor;
    if (maxFreq == minFreq) {
        scaleFactor = (double) (maxWeight - minWeight) / 4; // TODO: a realistic
        // scale factor in this
        // case
    } else {
        scaleFactor = (double) (maxWeight - minWeight) / (maxFreq - minFreq);
    }
    freqIt = frequencies.valuesIterator();
    int weight;
    while (freqIt.hasNext()) {
        wordStem = (String) freqIt.next();
        stemFreq = frequencies.getCount(wordStem);
        // Might still be some left less than the min. threshold
        if (stemFreq <= minFreq) {
            weight = minWeight;
        } else {
            weight = (int) (Math.ceil((double) (stemFreq - minFreq) * scaleFactor) + minWeight);
        }
        SortedSet<WordInfo> origins = this.stemOriginMap.get(wordStem);
        String mostCommonOrigin = origins.last().getName();
        Set<String> synonyms = new TreeSet<String>();
        for (WordInfo origin : origins) {
            synonyms.add(origin.getName());
        }
        WordInfo word = new Word(mostCommonOrigin, weight, synonyms);
        this.words.add(word);
    }
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

@Test
public void testTrackUser() throws Exception {
    long now = System.currentTimeMillis();
    Statistics stats = new Statistics(now, 0, 0, 0);
    stats.trackUser("homer", "A", "X");
    stats.trackUser("marge", "B", "Y");
    stats.trackUser("homer", "A", "X");
    stats.trackUser("bart", "C", "Z");
    SortedSet<UserInfo> info = stats.getUserInfo();
    assertInfoSet(stats, info);//from   ww w .j  a  va  2s  .  c o  m
    assertEquals(DigestUtils.shaHex("bart"), info.last().getUserHash());
    assertEquals("C", info.last().getDepartment());
    assertEquals("Z", info.last().getLocation());
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

@Test
public void testTrackUsage() throws Exception {
    long now = System.currentTimeMillis();
    Statistics stats = new Statistics(now, 0, 0, 0);
    stats.trackUsage("homer", "/projects", "x");
    stats.trackUsage("marge", "/projects/a", "y");
    stats.trackUsage("marge", "/projects/b", "z");
    stats.trackUsage("homer", "/projects", "y");
    stats.trackUsage("bart", "/projects/a", "y");
    SortedSet<UsageInfo> info = stats.getUsageInfo();
    assertInfoSet(stats, info);/*from www .j  a  v a  2  s .co  m*/
    assertEquals(DigestUtils.shaHex("bart"), info.last().getUserHash());
    assertEquals("/projects/a", info.last().getPath());
    assertEquals("y", info.last().getReferer());
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

@Test
public void testTrackBrowser() throws Exception {
    long now = System.currentTimeMillis();
    Statistics stats = new Statistics(now, 0, 0, 0);
    stats.trackBrowser("homer", "UserAgent1");
    stats.trackBrowser("marge", "UserAgent2");
    stats.trackBrowser("bart", "UserAgent1");
    SortedSet<BrowserInfo> info = stats.getBrowserInfo();
    assertInfoSet(stats, info);/*from w  ww.j a v  a 2 s  .  c om*/
    assertEquals(DigestUtils.shaHex("bart"), info.last().getUserHash());
    assertEquals("UserAgent1", info.last().getUserAgent());
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

@Test
public void testTrackReferer() throws Exception {
    long now = System.currentTimeMillis();
    Statistics stats = new Statistics(now, 0, 0, 0);
    stats.trackReferer("homer", "ref35");
    stats.trackReferer("marge", null);
    stats.trackReferer("bart", "ref12");
    SortedSet<RefererInfo> info = stats.getRefererInfo();
    assertInfoSet(stats, info);// www  . j a v a 2s. c o m
    assertEquals(DigestUtils.shaHex("bart"), info.last().getUserHash());
    assertEquals("ref12", info.last().getReferer());
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

@Test
public void testTrackSearch() throws Exception {
    long now = System.currentTimeMillis();
    Statistics stats = new Statistics(now, 0, 0, 0);
    stats.trackSearch("homer", "queryA", 25, 1234L);
    stats.trackSearch("marge", "queryB", 2, 344L);
    stats.trackSearch("bart", "queryC", 0, 723L);
    stats.trackSearch("marge", "queryC", 0, 567L);
    SortedSet<SearchInfo> info = stats.getSearchInfo();
    assertInfoSet(stats, info);/* w  w  w.  j  a v a  2  s  .c o m*/
    assertEquals(DigestUtils.shaHex("marge"), info.last().getUserHash());
    assertEquals("queryC", info.last().getQueryString());
    assertEquals(0, info.last().getResultCount());
    assertEquals(567L, info.last().getDuration());
}

From source file:org.eclipse.skalli.commons.StatisticsTest.java

@Test
public void testResponseTime() throws Exception {
    long now = System.currentTimeMillis();
    Statistics stats = new Statistics(now, 0, 0, 0);
    stats.trackResponseTime("homer", "/projects", 12L);
    stats.trackResponseTime("marge", "/favorites", 2837L);
    stats.trackResponseTime("bart", "/projects/a", 54L);
    SortedSet<ResponseTimeInfo> info = stats.getResponseTimeInfo();
    assertInfoSet(stats, info);/* w ww . j  a  v a2s.c o m*/
    assertEquals(DigestUtils.shaHex("bart"), info.last().getUserHash());
    assertEquals("/projects/a", info.last().getPath());
    assertEquals(54L, info.last().getResponseTime());
}

From source file:edu.cornell.mannlib.vitro.webapp.freemarker.loader.FreemarkerTemplateLoader.java

/**
 * Get the best template for this name. Walk the tree finding all possible
 * matches, then choose our favorite.//from ww  w .j  a va2 s . c o  m
 */
@Override
public Object findTemplateSource(String name) throws IOException {
    if (StringUtils.isBlank(name)) {
        return null;
    }

    SortedSet<PathPieces> matches = findAllMatches(new PathPieces(name));

    if (matches.isEmpty()) {
        return null;
    } else {
        return matches.last().path.toFile();
    }
}

From source file:hu.ppke.itk.nlpg.purepos.decoder.BeamedViterbi.java

private List<Pair<List<Integer>, Double>> findMax(final HashMap<NGram<Integer>, Node> beam, int resultsNumber) {

    // Node max = Collections.max(beam.values());
    // Node act = max;
    // return decompose(max);

    SortedSet<Node> sortedKeys = new TreeSet<Node>(beam.values());

    List<Pair<List<Integer>, Double>> ret = new ArrayList<Pair<List<Integer>, Double>>();
    Node max;/*from   w w w  . j  a  v a 2 s  . c o m*/
    for (int i = 0; i < resultsNumber && !sortedKeys.isEmpty(); ++i) {
        max = sortedKeys.last();
        sortedKeys.remove(max);
        List<Integer> maxTagSeq = decompose(max);
        ret.add(Pair.of(maxTagSeq, max.weight));
    }
    return ret;

}