Java 8 TreeMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TreeMap class.

This code example shows how to use the following methods:
@SuppressWarnings("serial") 
public class CheckWithCheck extends AbstractAnnotationCheck<CheckWith> { 
 
    final static String mes = "validation.invalid";
 
    Map<String, String> variables = new TreeMap<String, String>();
    Check check;
 
    @Override 
    public void configure(CheckWith checkWith) {
        setMessage(checkWith.message());
        try { 
            Constructor<?> constructor = checkWith.value().getDeclaredConstructor();
            constructor.setAccessible(true);
            check = (Check)constructor.newInstance();
            check.checkWithCheck = this;
        } catch(Exception e) {
            throw new UnexpectedException(e);
        } 
    } 
9
CodeRank
This code example shows how to use the following methods:
	@MapKeyType( @Type(type="integer") ) 
	@ElementCollection 
	@Sort(type = SortType.NATURAL)  
	@Type(type = "float") 
	@MapKeyColumn(nullable = false) 
	private SortedMap<Integer, Float> mvalues = new TreeMap<Integer, Float>(); 
 
	public Integer getId() { 
		return id; 
	} 
 
	public void setId(Integer id) { 
		this.id = id; 
	} 
 
	public Map<Integer, Float> getMvalues() { 
		return mvalues; 
	} 
 
	public void setMvalues(SortedMap<Integer, Float> mValues) { 
9
CodeRank
This code example shows how to use the following methods:ceilingKey, containsKey, firstKey, get, isEmpty
 
 
    private String findConsumerByPartition(final TreeMap<Long, String> consumerMap, final String partition) {
        final Long hash = this.alg.hash(partition);
        Long target = hash;
        if (!consumerMap.containsKey(hash)) {
            target = consumerMap.ceilingKey(hash);
            // if (hash == null) { 
            // target = consumerMap.floorKey(hash); 
            // } 
            // else { 
            // final Long floor = consumerMap.floorKey(hash); 
            // if (floor != null) { 
            // target = Math.abs(hash - floor) > Math.abs(hash - target) ? 
            // target : floor; 
            // } 
            // } 
            if (target == null && !consumerMap.isEmpty()) {
                target = consumerMap.firstKey();
            } 

8
CodeRank
This code example shows how to use the following methods:size
 
  /** 
   * @return return the number of unique objects aggregated 
   */ 
  public String getReport() {
    return "" + uniqItems.size();
  } 
 
  /** 
   *  
   * @return the set of the unique objects 
   */ 
  public Set<Object> getUniqueItems() {
    return uniqItems.keySet();
  } 
 
  /** 
   * reset the aggregator 
   */ 
  public void reset() { 
8
CodeRank
This code example shows how to use the following methods:firstKey, get, tailMap
    public R getShard(String key) {
        return resources.get(getShardInfo(key));
    } 
 
    public S getShardInfo(byte[] key) {
        SortedMap<Long, S> tail = nodes.tailMap(algo.hash(key));
        if (tail.isEmpty()) {
            return nodes.get(nodes.firstKey());
        } 
        return tail.get(tail.firstKey());
    } 
 
    public S getShardInfo(String key) {
        return getShardInfo(SafeEncoder.encode(getKeyTag(key)));
    } 
 
    /** 
     * A key tag is a special pattern inside a key that, if preset, is the only 
     * part of the key hashed in order to select the server for this key. 
     * 
8
CodeRank
This code example shows how to use the following methods:containsKey
 
        writeToEquityCurve(time);
    } 
 
    private void complainIfOverwriting(DateTime time) throws Exception {
        if (equityCurve.containsKey(time)) {
            throw new Exception("Cannot overwrite an existing price: " + time);
        } 
    } 
 
    public TreeMap<DateTime, BigDecimal> getEquityCurve() {
        return equityCurve;
    } 
 
    public BigDecimal valueAtTime(DateTime time) {
        return equityCurve.get(time);
    } 
 
    public BigDecimal getCurrentAmount() {
        return equityCurve.lastEntry().getValue();
8
CodeRank
This code example shows how to use the following methods:put
 
        today = new DateTime();
        yesterday = today.minusDays(1);
        twoDaysAgo = today.minusDays(2);
 
        prices = new TreeMap<DateTime, BigDecimal>();
        prices.put(today, new BigDecimal(9.0));
        prices.put(yesterday, new BigDecimal(11.0));
        prices.put(twoDaysAgo, new BigDecimal(10.0));
 
        series = new TimeSeries(prices);
    } 
 
    public void testOpen() { 
        DateTime oneMinuteLater = today.plusMinutes(1);
        prices.put(oneMinuteLater, new BigDecimal(9.1));
 
        assertEquals(series.openOnDay(today), new BigDecimal(9.0));
        assertEquals(series.openOnDay(oneMinuteLater), new BigDecimal(9.0));
        assertEquals(series.openOnDay(yesterday), new BigDecimal(11.0));
8
CodeRank
This code example shows how to use the following methods:containsKey, get, put
 
    removeAnyContainerTokenIfExpired(); 
     
    Long expTime = tokenId.getExpiryTimeStamp();
    // We might have multiple containers with same expiration time. 
    if (!recentlyStartedContainerTracker.containsKey(expTime)) {
      recentlyStartedContainerTracker
        .put(expTime, new ArrayList<ContainerId>());
    } 
    recentlyStartedContainerTracker.get(expTime).add(tokenId.getContainerID());
 
  } 
 
  protected synchronized void removeAnyContainerTokenIfExpired() { 
    // Trying to remove any container if its container token has expired. 
    Iterator<Entry<Long, List<ContainerId>>> containersI =
        this.recentlyStartedContainerTracker.entrySet().iterator();
    Long currTime = System.currentTimeMillis();
    while (containersI.hasNext()) {
      Entry<Long, List<ContainerId>> containerEntry = containersI.next();
8
CodeRank
This code example shows how to use the following methods:
import java.util.Set; 
import java.util.TreeMap; 
 
public class FillerRegistry implements IFillerRegistry { 
 
	private TreeMap<String, IFillerPattern> patterns = new TreeMap<String, IFillerPattern>(); 
	private Set<ActionFiller> patternActions = new HashSet<ActionFiller>(); 
 
	@Override 
	public void addPattern(IFillerPattern pattern) { 
		patterns.put(pattern.getUniqueTag(), pattern); 
		patternActions.add(new ActionFiller(pattern)); 
	} 
 
	@Override 
	public IFillerPattern getPattern(String patternName) { 
		return patterns.get(patternName); 
	} 
 
	@Override 
9
CodeRank
This code example shows how to use the following methods:size
  public void startVector(ArrayList v, String tag) throws IOException {
    out.writeVectorHeader(v.size());
  } 
 
  public void startMap(TreeMap m, String tag) throws IOException {
    out.writeMapHeader(m.size());
  } 
 
  public void endRecord(Record r, String tag) throws IOException {
    out.writeListFooter();
  } 
 
  public void endVector(ArrayList v, String tag) throws IOException {}
 
  public void endMap(TreeMap m, String tag) throws IOException {}
 
} 
8
CodeRank

Related Java 8 TreeMap Questions & Answers:

See Code Examples for Java 8 TreeMap Methods: