java.util.SortedMap#lastKey ( )源码实例Demo

下面列出了java.util.SortedMap#lastKey ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: TreeMapTest.java
public void test_lastKey_after_subMap() {
    TreeMap<String, String> tm = new TreeMap<String, String>();
    tm.put("001", "VAL001");
    tm.put("003", "VAL003");
    tm.put("002", "VAL002");
    SortedMap<String, String> sm = tm;
    String firstKey = (String) sm.firstKey();
    String lastKey = "";
    for (int i = 1; i <= tm.size(); i++) {
        try {
            lastKey = (String) sm.lastKey();
        } catch (NoSuchElementException excep) {
            fail("NoSuchElementException thrown when there are elements in the map");
        }
        sm = sm.subMap(firstKey, lastKey);
    }
}
 
源代码2 项目: ganttproject   文件: ChangeTaskProgressRuler.java
/**
 * @return progress value corresponding to the given {@code pixels} value.
 */
Progress getProgress(int pixels) {
  if (pixels < myMinPx) {
    return new Progress(0, myTask.getDuration());
  }
  SortedMap<Integer, Integer> tailMap = myPixel2progress.tailMap(pixels);
  if (tailMap.isEmpty()) {
    return new Progress(100, myTask.getDuration());
  }
  if (tailMap.firstKey().intValue() == pixels) {
    return new Progress(tailMap.get(pixels), myTask.getDuration());
  }

  SortedMap<Integer, Integer> headMap = myPixel2progress.headMap(pixels);
  int lowerPx = headMap.isEmpty() ? 0 : headMap.lastKey();
  int lowerProgress = headMap.isEmpty() ? 0 : headMap.get(lowerPx);
  int upperPx = tailMap.firstKey();
  int upperProgress = tailMap.get(upperPx);

  float diffProgress = (upperProgress - lowerProgress) * ((float) (pixels - lowerPx) / (float) (upperPx - lowerPx));
  int overallProgress = (int) (lowerProgress + diffProgress);
  return new Progress(overallProgress, myTask.getDuration());
}
 
源代码3 项目: codebuff   文件: Maps.java
@Override
public K lastKey() {
  SortedMap<K, V> headMap = sortedMap();
  while (true) {
    // correctly throws NoSuchElementException when filtered map is empty.
    K key = headMap.lastKey();
    if (apply(key, unfiltered.get(key))) {
      return key;
    }
    headMap = sortedMap().headMap(key);
  }
}
 
private Double calcScoreDifference(SortedMap<Double, SortedSet<String>> scoredCats)
{
  if (scoredCats.size() < 2)
  {
    return null;
  }

  Double score1 = scoredCats.lastKey();
  Double score2 = scoredCats.headMap(score1).lastKey();

  return score1 - score2;
}
 
源代码5 项目: gemfirexd-oss   文件: Graph.java
/**
 * Add an edge to this graph.
 * @param timestamp
 * @param edgeName
 * @param source
 * @param dest
 * @param isFromPattern 
 */
public void addEdge(long timestamp, String edgeName, String state, String source,
    String dest, boolean isFromPattern) {

  Vertex destVertex = new Vertex(this, dest, state, timestamp);
  SortedMap<Long, Vertex> map  = this.indexedVertices.get(dest);
  if(map == null) {
    map = new TreeMap<Long, Vertex>();
    this.indexedVertices.put(dest, map);
  }
  
  //If this edge is being added by a pattern event, only
  //add the edge if the destination changes state as a result
  //of this edge. This cuts down on noise in the graph.
  if(isFromPattern) {
    SortedMap<Long, Vertex> headMap = map.headMap(timestamp);
    if(headMap != null && !headMap.isEmpty()) {
      Long previousKey = headMap.lastKey();
      Vertex previousVertex = headMap.get(previousKey);
      if(previousVertex.getState().equals(state)) {
        return;
      }
    } else {
      //Super hack here. Don't add a transition from the non existent state to
      //the destroyed state in a lifeline.
      if(state.equals("destroyed")) {
        return;
      }
    }
  }
  map.put(timestamp, destVertex);
  
  edges.add(new Edge(this, timestamp, edgeName, source, destVertex));
}
 
源代码6 项目: ghidra   文件: Locator.java
public Location getLocation(int expandedLineNo) {
	SortedMap<Integer, Location> headMap = map.headMap(expandedLineNo + 1);
	Integer key;
	Location location;
	Location correctLocation;
	if (headMap.size() == 0) {
		return null;
	}
	key = headMap.lastKey();
	location = headMap.get(key);
	int actualLineNumber = expandedLineNo - key + location.lineno;
	correctLocation = new Location(location.filename, actualLineNumber);
	return correctLocation;
}
 
源代码7 项目: scava   文件: ST.java
/**
 * Returns the largest key in the symbol table less than or equal to <tt>key</tt>.
 * @return the largest key in the symbol table less than or equal to <tt>key</tt>
 * @param key the key
 * @throws NoSuchElementException if the symbol table is empty
 * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>
 */
public Key floor(Key key) {
    if (key == null) throw new NullPointerException("called floor() with null key");
    // headMap does not include key if present (!)
    if (st.containsKey(key)) return key;
    SortedMap<Key, Value> head = st.headMap(key);
    if (head.isEmpty()) throw new NoSuchElementException();
    return head.lastKey();
}
 
源代码8 项目: gemfirexd-oss   文件: Edge.java
public Vertex getSource() {
  SortedMap<Long, Vertex> sourceMap = graph.getIndexedVertices().get(source);
  if(sourceMap == null) {
    return null;
  }
  SortedMap<Long, Vertex> headMap = sourceMap.headMap(dest.getTimestamp() + 1);
  if(headMap.isEmpty()) {
    return null;
  }
  Long closestTimestamp = headMap.lastKey();
  return headMap.get(closestTimestamp);
}
 
private int purge(final RollingFileManager manager) {
    final SortedMap<Integer, Path> eligibleFiles = getEligibleFiles(manager);
    LOGGER.debug("Found {} eligible files, max is  {}", eligibleFiles.size(), maxFiles);
    while (eligibleFiles.size() >= maxFiles) {
        try {
            final Integer key = eligibleFiles.firstKey();
            Files.delete(eligibleFiles.get(key));
            eligibleFiles.remove(key);
        } catch (final IOException ioe) {
            LOGGER.error("Unable to delete {}", eligibleFiles.firstKey(), ioe);
            break;
        }
    }
    return eligibleFiles.size() > 0 ? eligibleFiles.lastKey() : 1;
}
 
源代码10 项目: netbeans   文件: InputGestureTest.java
public void testReadALogAndTestInputGestures() throws Exception {
    InputStream is = getClass().getResourceAsStream("NB1216449736.0");
    SortedMap<Integer,InputGesture> expectedGestures = new TreeMap<Integer,InputGesture>();
    expectedGestures.put(35, InputGesture.MENU);
    expectedGestures.put(59, InputGesture.KEYBOARD);
    expectedGestures.put(66, InputGesture.MENU);
    expectedGestures.put(80, InputGesture.MENU);
    expectedGestures.put(81, InputGesture.MENU);
    expectedGestures.put(177, InputGesture.KEYBOARD);
    expectedGestures.put(197, InputGesture.KEYBOARD);
    expectedGestures.put(205, InputGesture.MENU);
    TestHandler records = new TestHandler(is);
    for (int cnt = 0;; cnt++) {
        LOG.log(Level.INFO, "Reading {0}th record", cnt);
        LogRecord r = records.read();
        if (r == null) {
            break;
        }
        if (r.getSequenceNumber() > expectedGestures.lastKey()) {
            break;
        }
        LOG.log(Level.INFO, "Read {0}th record, seq {1}", new Object[] { cnt, r.getSequenceNumber() });

        InputGesture g = InputGesture.valueOf(r);
        InputGesture exp = expectedGestures.get((int)r.getSequenceNumber());
        assertEquals(cnt + ": For: " + r.getSequenceNumber() + " txt:\n`"+ r.getMessage() +
            "\nkey: " + r.getResourceBundleName()
            , exp, g);
    }
    is.close();
}
 
源代码11 项目: lams   文件: LearningController.java
@RequestMapping(value = "/previousQuestion")
   private String previousQuestion(@ModelAttribute("surveyForm") AnswerForm surveyForm,
    MultiValueMap<String, String> errorMap, HttpServletRequest request) {
Integer questionSeqID = surveyForm.getQuestionSeqID();
String sessionMapID = surveyForm.getSessionMapID();

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(sessionMapID);
SortedMap<Integer, AnswerDTO> surveyItemMap = getQuestionList(sessionMap);

if (!errorMap.isEmpty()) {
    request.setAttribute("errorMap", errorMap);
    return "pages/learning/learning";
}

SortedMap<Integer, AnswerDTO> subMap = surveyItemMap.headMap(questionSeqID);
if (subMap.isEmpty()) {
    questionSeqID = surveyItemMap.firstKey();
} else {
    questionSeqID = subMap.lastKey();
}

// get current question index of total questions
int currIdx = new ArrayList<>(surveyItemMap.keySet()).indexOf(questionSeqID) + 1;
surveyForm.setCurrentIdx(currIdx);

if (questionSeqID.equals(surveyItemMap.firstKey())) {
    surveyForm.setPosition(SurveyConstants.POSITION_FIRST);
} else {
    surveyForm.setPosition(SurveyConstants.POSITION_INSIDE);
}
surveyForm.setQuestionSeqID(questionSeqID);
request.setAttribute("surveyForm", surveyForm);
return "pages/learning/learning";
   }
 
源代码12 项目: jdk1.8-source-analysis   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}
 
源代码13 项目: jdk8u-jdk   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}
 
源代码14 项目: jdk8u60   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}
 
源代码15 项目: openjdk-8-source   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}
 
源代码16 项目: jdk8u_jdk   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}
 
源代码17 项目: pinpoint   文件: EagerSamplingHandler.java
private S reduceSampledPoints(SortedMap<Long, S> sampledPointCandidates) {
    Long lastKey = sampledPointCandidates.lastKey();
    return sampledPointCandidates.get(lastKey);
}
 
源代码18 项目: openjdk-8   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}
 
源代码19 项目: medialibrary   文件: LocalMergeAlbum.java
@Override
public ArrayList<MediaItem> getMediaItem(int start, int count) {

    // First find the nearest mark position <= start.
    SortedMap<Integer, int[]> head = mIndex.headMap(start + 1);
    int markPos = head.lastKey();
    int[] subPos = head.get(markPos).clone();
    MediaItem[] slot = new MediaItem[mSources.length];

    int size = mSources.length;

    // fill all slots
    for (int i = 0; i < size; i++) {
        slot[i] = mFetcher[i].getItem(subPos[i]);
    }

    ArrayList<MediaItem> result = new ArrayList<MediaItem>();

    for (int i = markPos; i < start + count; i++) {
        int k = -1;  // k points to the best slot up to now.
        for (int j = 0; j < size; j++) {
            if (slot[j] != null) {
                if (k == -1 || mComparator.compare(slot[j], slot[k]) < 0) {
                    k = j;
                }
            }
        }

        // If we don't have anything, all streams are exhausted.
        if (k == -1) break;

        // Pick the best slot and refill it.
        subPos[k]++;
        if (i >= start) {
            result.add(slot[k]);
        }
        slot[k] = mFetcher[k].getItem(subPos[k]);

        // Periodically leave a mark in the index, so we can come back later.
        if ((i + 1) % PAGE_SIZE == 0) {
            mIndex.put(i + 1, subPos.clone());
        }
    }

    return result;
}
 
源代码20 项目: openjdk-jdk9   文件: EnvHelp.java
private static void hideAttributes(SortedMap<String, ?> map) {
    if (map.isEmpty())
        return;

    final SortedSet<String> hiddenStrings;
    final SortedSet<String> hiddenPrefixes;

    String hide = (String) map.get(HIDDEN_ATTRIBUTES);
    if (hide != null) {
        if (hide.startsWith("="))
            hide = hide.substring(1);
        else
            hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
        hiddenStrings = new TreeSet<String>();
        hiddenPrefixes = new TreeSet<String>();
        parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
    } else {
        hide = DEFAULT_HIDDEN_ATTRIBUTES;
        synchronized (defaultHiddenStrings) {
            if (defaultHiddenStrings.isEmpty()) {
                parseHiddenAttributes(hide,
                                      defaultHiddenStrings,
                                      defaultHiddenPrefixes);
            }
            hiddenStrings = defaultHiddenStrings;
            hiddenPrefixes = defaultHiddenPrefixes;
        }
    }

    /* Construct a string that is greater than any key in the map.
       Setting a string-to-match or a prefix-to-match to this string
       guarantees that we will never call next() on the corresponding
       iterator.  */
    String sentinelKey = map.lastKey() + "X";
    Iterator<String> keyIterator = map.keySet().iterator();
    Iterator<String> stringIterator = hiddenStrings.iterator();
    Iterator<String> prefixIterator = hiddenPrefixes.iterator();

    String nextString;
    if (stringIterator.hasNext())
        nextString = stringIterator.next();
    else
        nextString = sentinelKey;
    String nextPrefix;
    if (prefixIterator.hasNext())
        nextPrefix = prefixIterator.next();
    else
        nextPrefix = sentinelKey;

    /* Read each key in sorted order and, if it matches a string
       or prefix, remove it. */
keys:
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();

        /* Continue through string-match values until we find one
           that is either greater than the current key, or equal
           to it.  In the latter case, remove the key.  */
        int cmp = +1;
        while ((cmp = nextString.compareTo(key)) < 0) {
            if (stringIterator.hasNext())
                nextString = stringIterator.next();
            else
                nextString = sentinelKey;
        }
        if (cmp == 0) {
            keyIterator.remove();
            continue keys;
        }

        /* Continue through the prefix values until we find one
           that is either greater than the current key, or a
           prefix of it.  In the latter case, remove the key.  */
        while (nextPrefix.compareTo(key) <= 0) {
            if (key.startsWith(nextPrefix)) {
                keyIterator.remove();
                continue keys;
            }
            if (prefixIterator.hasNext())
                nextPrefix = prefixIterator.next();
            else
                nextPrefix = sentinelKey;
        }
    }
}