treemap 有一个方法tailmap 来获取一个sortedmap,它的key 不小于fromkey。跟踪源码发现tailmap在NavigableSubMap的construct方法中完成了工作。这是代码。
NavigableSubMap(TreeMap<K,V> m,
boolean fromStart, K lo, boolean loInclusive,
boolean toEnd, K hi, boolean hiInclusive) {
if (!fromStart && !toEnd) {
if (m.compare(lo, hi) > 0)
throw new IllegalArgumentException("fromKey > toKey");
} else {
if (!fromStart) // type check
m.compare(lo, lo);
if (!toEnd)
m.compare(hi, hi);
}
this.m = m;
this.fromStart = fromStart;
this.lo = lo;
this.loInclusive = loInclusive;
this.toEnd = toEnd;
this.hi = hi;
this.hiInclusive = hiInclusive;
}
在 this.toEnd = toEnd 的步骤之后;NavigableSubMap 类有尾地图。它是如何完成的?