Upload
-
View
8.083
Download
7
Embed Size (px)
DESCRIPTION
2012년 자바카페 OPEN 세미나에서 발표한 내용입니다. Google Guava에 대한 소개입니다.
Citation preview
2012. 6. 16
2012년 자바카페 OPEN세미나
JavaCafeJJJJava DDDDeveloper’s FFFForum
community
주제 : Introduction to Google Guava
JavaCafeJJJJava DDDDeveloper’s FFFForum
Community
구아바 ????
소개
� Google Core Library (JavaSE 5.0 +)� 구글 자바 프로젝트에서 기본적으로 사용� Google Guava로 명칭을 통일� Andorid 개발 지원� GWT 개발 지원� Apache license 2.0
지겹다. 또 라이브러리야???
식상해…………….
Google Guava
Apache CommonsLang 컴포넌트
Apache CommonsCollections 컴포넌트
유용한 유틸리티
수많은 프로젝트에비슷한 기능은 없을까?
비슷한 기능을재사용 할 수는 없을까?
Apache Commons Library
� 프로그램의 공통적인 기능을 재사용하기위한 목적으로 시작
� Google Library와 더불어 전세계적으로 가장 많이 사용되고 있는 Library
� 현재 Commons Library는 40여개의 컴포넌트들로 구성
� 각각의 컴포넌트를 필요에 따라서 선택적으로 사용하는 것이 가능
대표적인 코드 저장소인 Google Code(http://code.google.com/)와소스포지(http://sourceforge.net/)에 공개된 약 160,000개의 오픈소스 프로젝트 중Commons 라이브러리가 사용된 프로젝트를 분석하여 시각적으로 표현한 것
JavaSE Standard lang을 위한 유틸리티
java.lang.*
java.lang.* Packages
� Basic Class� Object, Process, Runtime, System, Thread,
Class, ClassLoader
� Wrapping Class� Boolean, Byte, Character, Double, Float,
Integer, Long
� String Class� String, StringBuffer, StringBuilder
특징
� Base Function� ObjectUtils, ClassUtils, ArrayUtils, BooleanUtils
� 문자열 조작� StringUtils, StringEscapeUtils, RandomStringUtils,
Tokenizer, WordUtils� Character 핸들링
� CharSetUtils, CharSet, CharRange, CharUtils� JVM Interaction
� SystemUtils, CharEncoding� Serialization
� SerializationUtils, SerializationException
JavaSE Standard Collection을 위한 유틸리티
java.util.*
java.util.* Packages
� Collections Class� ArrayList, Array, HashMap, HashSet,
LinkedList, Vector, Stack
� Utility Class� Timer, Random, Properties, Locale, Date,
Calendar
특징
� Collection 유틸리티� Ordered Maps� Bidirectional Maps� Queues� Buffers� Bags
Apache Commons짱 좋아요!
그냥 이거 쓰면 안되나요?
Lang 컴포넌트 Collection 컴포넌트
JavaSE 5 (-) 지원 JavaSE 5 (-) 지원
JavaSE 5 (+) 지원 JavaSE 5 (+) 미지원
각각 다른 패키지로 제공됨 현재 개발 중단됨
Java 5 특징
� Generics 개념 도입� Enum 타입 추가� 언어차원의 Annotation 지원� 파라미터 가변인자 (Varargs : Variable
Argument List)
출처 http://en.wikipedia.org/wiki/Java_version_history
2004 ??????
Release Note
� Last Published� 2011년 11월 09일 (Version:3.1)
� javaSE 5.0 기준으로 재개발하여 배포� Commons Lang 2.x
� JDK 1.2 ~ JDK 1.4 까지 지원� org.apache.commons.lang.*
� Commons Lang 3.x � JDK 1.5 이상 지원� org.apache.commons.lang3.*
� 개발시 사용하는 JDK 기준으로 선택적으로 사용� 필요에 의하여 혼용하여 사용 가능 (권장하지 않음)
Release Note
� Last Published� 2008년 4월 15일 (Version:3.2.1)
� 현재 Commons Collections 개발중단� Commons Collections 라이브러리
� JDK 1.2 ~ JDK 1.4 까지 지원� org.apache.commons.collection.*
� 개발시 사용하는 JDK 버전이 1.5 이상일 경우 사용을권장하지 않음
소개
� Google Core Library (JavaSE 5.0 +)� 구글 자바 프로젝트에서 기본적으로 사용� Google Guava로 명칭을 통일� Andorid 개발 지원� GWT 개발 지원� Apache license 2.0
Google Guava
Apache CommonsLang 컴포넌트
Apache CommonsCollections 컴포넌트
유용한 유틸리티
Release Note
� Last Published� 2012년 4월 30일 (Version:Release12)
� Apache Commons Collections 라이브러리가Generic를 지원하지 않아 대체하려 개발 시작
� 2009년 JDK 1.5를 기반으로 프로젝트 시작� Release11까지는 JDK 1.5 기반� Release12부터 JDK 1.6 기반� 버전업을 하면서 이름 변경
� Google Collections Library => Google Guava
제공되는 기능
• Collections• Concurrency• Primitives• Reflection• Comparison• I/O• Hashing• networking
• Strings• Math• In-memory caching• Publish/Subscribe• Various basic data
제공되는 기능
• Collections• Concurrency• Primitives• Reflection• Comparison• I/O• Hashing• networking
• Strings• Math• In-memory caching• Publish/Subscribe• Various basic data
“JDK-plus”!!!
Basic 유틸리티 (1/4)
� Object 클래스 유틸리티� java.lang.Object 클래스 Wrapping 유틸리티� com.google.common.base.Objects� equals() : equals 메소드 Override 지원� hashCode() : hashCode 메소드 Override 지원� toString() : toString 메소드 Override 지원
Basic 유틸리티 (2/4)
� Null 체크 유틸리티� 문자열의 null 문제를 다양하게 체크� com.google.common.base.Strings� emptyToNull(String) : 파라미터로 넘어온
값이 Empty 일 경우 Null 반환� isNullOrEmpty(String) : 파라미터로 넘어온
값이 Null이나 Empty인지 검사� nullToEmpty(String) : 파라미터로 넘어온 값
이 Null 일 경우 Empty 반환
Basic 유틸리티 (3/4)
� Precondition 유틸리티� 파라미터로 전달되는 값의 유효성 검사� com.google.common.base.Preconditions� checkArgument(boolean) : 인자 값을 미리
테스트하여 정상인지 검사� checkNotNull(T) : 인자 값을 미리 테스트하
여 Null인지 검사� checkState(boolean) : 인자값을 미리 테스트
하여 상태값을 검사
Basic 유틸리티 (4/4)
� Ordering 유틸리티� 객체 정렬을 위한 다양한 기능 제공� com.google.common.collect.Ordering� reverse() : 값을 반대로 정렬� nullsFirst() : null이 존재할 경우 처음으로 정렬� nullsLast() : null이 존재할 경우 마지막으로 정렬
Strings 유틸리티 (1/2)
� Joiner 유틸리티� 다양한 형태의 iterator를 하나로 합친다.� com.google.common.base.Joiner� join(Object[] parts) : 파라미터로 넘어온 배
열을 하나의 문자열로 합친다.� on(String separator) : 합칠 문자열 사이의
Separator를 지정� skipNulls() : 합칠 문자열 중 Null 값 제거
Strings 유틸리티 (2/2)
� Splitter 유틸리티� 문자열을 다양한 방식으로 분리한다.� com.google.common.base.Splitter� split(CharSequence sequnce) : 파라미터로
넘어온 문자열을 분리한다.� on(String separator) : 분리할 기분
Separator를 지정� omitEmptyStrings() : 분리 된 결과물에서
Empty 제거
Collection 유틸리티
Immutable Collections
새롭게 추가된 Collection� Multiset
� com.google.common.collect.Multiset� 두 개 이상의 키를 핸들링 할 수 있는 Set 형태의 Collection� HashMultiset, TreeMultiset, LinkedHashMultiset,
ImmutableMultiset� Multimap
� com.google.common.collect.Multimap� 두 개 이상의 키를 핸들링 할 수 있는 Map 형태의 Collection� HashMultimap, TreeMultimap, LinkedHashMultimap,
ImmutableListMultimap� BiMap
� com.google.common.collect.BiMap� 일반적인 Map과 달리 key와 value 양방향으로 검색이 가능한
Collection� HashBiMap, ImmutableBiMap, EnumBiMap, EnumHashBiMap
Guava 라이브러리를 써야하는 이유
� Apache Commons Collection의 경우 개발된지 10여년이 되었다.
� Apache Commons Collection의 경우JavaSE 5의 혜택이 없다. (generics, varags, enums, autoboxing)
� Google Guava의 경우 좀더 현대적이다. (Generic 지원, JDK7 지원)
� 아파치 라이센스 2.0 � Java Collection Framework와 완벽한 호환