在学习GSON的过程中,发现了GSON的基础数据类型LinkedTreeMap,因此展开学习。
private final LinkedTreeMap<String, JsonElement> members =
new LinkedTreeMap<String, JsonElement>();
LinkedTreeMap,一切如此的熟悉,在jdk中有LinkedMap有TreeMap有TreeMap,这个LinkedTreeMap是个什么,顾名思义,这应该是一个连续的且有序的集合。
package com.google.gson.internal;
一看包名,这是google自己实现的map。
Node<K, V> parent;
Node<K, V> left;
Node<K, V> right;
Node<K, V> next;
Node<K, V> prev;
final K key;
V value;
int height;
咋一看,这是啥啊。一个结点包含了父节点,左右结点和前后结点,但是不要慌我们接着往下看。
接着回到LinkedTreeMap,在类的最开时定义了一个比较器NATURAL_ORDER
private static final Comparator<Comparable> NATURAL_ORDER = new Comparator<Comparable>() {
public int compare(Comparable a, Comparable b)