https://www.yiibai.com/guava
https://wizardforcel.gitbooks.io/guava-tutorial/content/1.html
checkArgument(i < j, "Expected i < j, but %s > %s", i, j);
checkNotNull(a, "parameter is Null");
equals,避免抛出NullPointerException
Objects.equal("a", "a"); // returns true Objects.equal(null, "a"); // returns false Objects.equal("a", null); // returns false Objects.equal(null, null); // returns true
hashCode,
System.out.println(Objects.hashCode("a","b","c"));
Person person=new Person("peida",23);
System.out.println(Objects.hashCode(person));
可设置过期的cache
https://segmentfault.com/a/1190000011105644
http://ifeve.com/google-guava-collectionutilities/
com.google.common.collect.Maps
更简单的创建,newLinkedHashMap(),newConcurrentMap()
Map< String, String> aNewMap = Maps.newHashMap();
Lists,Sets
List<TypeThatsTooLongForItsOwnGood> list = Lists.newArrayList()
com.google.common.collect.Multimap
//Map<String, List<String>>
// lower -> a, b, c
// upper -> A, B
Multimap<String,String> multimap = ArrayListMultimap.create();
multimap.put("lower", "a");
multimap.put("lower", "b");
multimap.put("lower", "c");
multimap.put("upper", "A");
multimap.put("upper", "B");
Map<String, Collection<String>> map = multimap.asMap();
com.google.common.collect.Multiset
多个重复的值
Multiset<String> multiset = HashMultiset.create();
multiset.add("a");
multiset.add("a");
multiset.add("c");
Set<String> set = multiset.elementSet();
ImmutableMap,比java直接构建静态map要简单
Map<String, Integer> salary = ImmutableMap.<String, Integer> builder()
.put("John", 1000)
.put("Jane", 1500)
.put("Adam", 2000)
.put("Tom", 2000)
.build();
com.google.common.base.Joiner
Joiner joiner = Joiner.on("; ").skipNulls(); return joiner.join("Harry", null, "Ron", "Hermione");
com.google.common.base.Splitter
Splitter.on(',') .trimResults() .omitEmptyStrings() .split("foo,bar,, qux");
com.google.common.hash.Hashing
md5
sha256
sha512
sha1
murmur3_128
murmur3_32
goodFastHash