extendsV>m){
comparator=parator();
try{
buildFromSorted(m.size(),m.entrySet().iterator(),null,null);
}catch(IOExceptione){
}catch(ClassNotFoundExceptione){
}
}
publicintsize(){
returnsize;
}
publicbooleancontainsKey(Objectkey){
returngetEntry(key)!
=null;
}
publicbooleancontainsValue(Objectvalue){
for(Entrye=getFirstEntry();e!
=null;e=successor(e)){
if(valEquals(value,e.value))
returntrue;
}
returnfalse;
}
publicVget(Objectkey){
Entryp=getEntry(key);
returnp==null?
null:
p.value;
}
publicComparator
superK>comparator(){
returncomparator;
}
publicKfirstKey(){
returnkey(getFirstEntry());
}
publicKlastKey(){
returnkey(getLastEntry());
}
@SuppressWarnings({"rawtypes","unchecked"})
publicvoidputAll(Map
extendsK,?
extendsV>map){
intmapSize=map.size();
if(size==0&&mapSize!
=0&&mapinstanceofSortedMap){
Comparable
superK>cmp=(Comparable
superK>)((SortedMap)map).comparator();
if(cmp==comparator||(cmp!
=null&&cmp.equals(comparator))){
++modCount;
try{
buildFromSorted(mapSize,map.entrySet().iterator(),null,null);
}catch(IOExceptione){
}catch(ClassNotFoundExceptione){
}
return;
}
}
super.putAll(map);
}
@SuppressWarnings("unchecked")
finalEntrygetEntry(Objectkey){
if(comparator!
=null){
returngetEntryUsingComparator(key);
}
if(key==null)
thrownewNullPointerException();
Comparable
superK>k=(Comparable
superK>)key;
Entryp=root;
while(p!
=null){
intcmp=pareTo(p.key);
if(cmp<0){
p=p.left;
}elseif(cmp>0){
p=p.right;
}else{
returnp;
}
}
returnnull;
}
@SuppressWarnings("unchecked")
finalEntrygetEntryUsingComparator(Objectkey){
Kk=(K)key;
Comparator
superK>cpr=comparator;
if(cpr!
=null){
Entryp=root;
while(p!
=null){
intcmp=pare(k,p.key);
if(cmp<0)
p=p.left;
elseif(cmp>0)
p=p.right;
else
returnp;
}
}
returnnull;
}
finalEntrygetCeilingEntry(Objectkey){
Entryp=root;
while(p!
=null){
intcmp=compare(key,p.key);
if(cmp<0){
if(p.left!
=null)
p=p.left;
else
returnp;
}elseif(cmp<0){
if(p.right!
=null)
p=p.right;
else{
Entryparent=p.parent;
Entrych=p;
while(parent!
=null&&ch==parent.right){
ch=parent;
parent=parent.parent;
}
returnparent;
}
}else{
returnp;
}
}
returnnull;
}
finalEntrygetFloorEntry(Objectkey){
Entryp=root;
while(p!
=null){
intcmp=compare(key,p.key);
if(cmp>0){
if(p.right!
=null)
p=p.right;
else
returnp;
}elseif(cmp<0){
if(p.left!
=null)
p=p.left;
else{
Entryparent=p.parent;
Entrych=p;
while(parent!
=null&&ch==parent.left){
ch=parent;
parent=parent.parent;
}
returnparent;
}
}else{
returnp;
}
}
returnnull;
}
finalEntrygetHigherEntry(Objectkey){
Entryp=root;
while(p!
=null){
intcmp=compare(key,p.key);
if(cmp<0){
if(p.left!
=null)
p=p.left;
else
returnp;
}else{
if(p.right!
=null)
p=p.right;
else{
Entryparent=p.parent;
Entrych=p;
while(parent!
=null&&ch==parent.right){
ch=parent;
parent=parent.parent;
}
returnparent;
}
}
}
returnnull;
}
finalEntrygetLowerEntry(Objectkey){
Entryp=root;
while(p!
=null){
intcmp=compare(key,p.key);
if(cmp>0){
if(p.right!
=null)
p=p.right;
else
returnp;
}else{
if(p.left!
=null)
p=p.left;
else{
Entryparent=p.parent;
Entrych=p;
while(parent!
=null&&ch==parent.left){
ch=parent;
parent=parent.parent;
}
returnparent;
}
}
}
returnnull;
}
@SuppressWarnings("unchecked")
publicVput(Kkey,Vvalue){
Entryt=root;
if(t==null){
root=newEntry(key,value,null);
root.height=1;
size++;
modCount++;
returnnull;
}
intcmp;
Entryparent;
Comparator
superK>cpr=comparator;
if(cpr!
=null){
do{
parent=t;
cmp=pare(key,t.key);
if(cmp<0)
t=t.left;
elseif(cmp>0)
t=t.right;
else
returnt.setValue(value);
}while(t!
=null);
}else{
do{
parent=t;
cmp=((Comparable
superK>)key).compareTo(t.key);
if(cmp<0)
t=t.left;
elseif(cmp>0)
t=t.right;
else
returnt.setValue(value);
}while(t!
=null);
}
Entrye=newEntry(key,value,parent);
if(cmp<0)
parent.left=e;
else
parent.right=e;
fixAfterInsertion(e);
size++;
modCount++;
returnnull;
}
publicVremove(Objectkey){
Entryp=getEntry(key);
if(p==null){
returnnull;
}
VoldVal=p.value;
deleteEntry(p);
returnoldVal;
}
publicvoidclear(){
size=0;
modCount++;
root=null;
}
@SuppressWarnings("unchecked")
publicObjectclone(){
AVLTreeMapclone=null;
try{
clone=(AVLTreeMap)super.clone();
}catch(CloneNotSupportedExceptione){
thrownewInternalError();
}
clone.root=null;
clone.size=0;
clone.modCount=0;
clone.entrySet=null;
clone.keySet=null;
clone.descendingMap=null;
try{
clone.buildFromSorted(size,entrySet().iterator(),null,null);
}catch(IOExceptione){
}catch(ClassNotFoundExceptione){
}
returnclone;
}
publicMap.EntryfirstEntry(){
returnexportEntry(getFirstEntry());
}
publicMap.EntrylastEntry(){
returnexportEntry(getLastEntry());
}
publicMap.EntrypollFirstEntry(){
AVLTreeMap.Entryp=getFirstEntry();
Map.Entryresult=exportEntry(p);
if(p!
=null)
deleteEntry(p);
returnresult;
}
publicMap.EntrypollLastEntry(){
AVLTreeMap.Entrye=getLastEntry();
Map.Entryresult=exportEntry(e);
if(e!
=null)
deleteEntry(e);
returnresult;
}
publicMap.EntrylowerEntry(Kkey){
returnexportEntry(getLowerEntry(key));
}
publicKlowerKey(Kkey){
returnkeyOrNull(getLowerEntry(key));
}
publicMap.EntryfloorEntry(Kkey){
returnexportEntry(getFloorEntry(key));
}
publicKfloorKey(Kkey){
returnkeyOrNull(getFloorEntry(key));
}
publicMap.EntryceilingEntry(Kkey){
returnexportEntry(getCeilingEntry(key));
}
publicKceilingKey(Kkey){
returnkeyOrNull(getCeilingEntry(key));
}
publicMap.EntryhigherEntry(Kkey){
returnexportEntry(getHigherEntry(key));
}
publicKhigherKey(Kkey){
returnkeyOrNull(getHigherEntry(key));
}
privatetransientEntrySetentrySet=null;
privatetransientKeySetnavigableKeySet=null;
privatetransientNavigableMapdescendingMap=null;
@SuppressWarnings("unused")
privatetransientSetkeySet=null;
privatetransientCollectionvalues=null;
publicSetkeySet(){
returnnavigableKeySet();
}
@SuppressWarnings({"unchecked","rawtypes"})
publicNavigableSetnavigableKeySet(){
KeySetks=navigableKeySet;
return(ks!
=null)?
ks:
(navigableKeySet=newKeySet(this));
}
publicNavigableSetdescendingKeySet(){
returndescendingMap().navigableKeySet();
}
publicSet>entrySet(){
EntrySetes=entrySet;
return(es!
=null)?
es:
(entrySet=newEntrySet());
}
publicCollectionvalues(){
Collectionvs=values;
return(vs!
=null)?
vs:
(values=newValues());
}
@SuppressWarnings({"unchecked","rawtypes"})
publicNavigableMapdescendingMap(){
NavigableMapkm=descendingMap;
return(km!
=null)?
km:
(descendingMap=newDescendingSubMap(this,true,null,true,true,null,true));
}
@SuppressWarnings({"unchecked","rawtypes"})
publicNavigableMapsubMap(KfromKey,booleanfromInclusive,KtoKey,booleantoInclusive){
returnnewAscendingSubMap(this,false,fromKey,fromInclusive,false,toKey,toInclusive);
}
@SuppressWarnings({"unchecked","rawtypes"})
publicNavigableMapheadMap(KtoKey,booleaninclusive){
returnnewAscendingSubMap(this,true,null,true,false,toKey,inclusive);
}
@SuppressWarnings({"unchecked","rawtypes"})
publicNavigableMaptailMap(KfromKey,booleaninclusive){
returnnewAscendingSubMap(this,false,fr