2. public void demo(Library l) {
List<Book> books = l.getBooks();
Set<Borrower> allBorrowers = new HashSet<Borrower>();
List<Writer> allWriters = new ArrayList<Writer>();
for (Book book : books) {
List<Borrower> borrowers = book.getBorrowers();
allBorrowers.addAll(borrowers);
allWriters.add(book.getAuthor());
}
Set<Borrower> filteredBorowers = new HashSet<Borrower>();
for (Borrower borrower : allBorrowers) {
if (borrower.getLastName().startsWith("B") &&
borrower.getBorrowed().contains(aSpecificBook)) {
filteredBorowers.add(borrower);
}
}
}
3. About Guava
Java library used internally Superset of Google
@ Google for years Collections
s s
ti on ti on
c
lle llec
Co 5 Co a r03 a r08
gle v0. gle v1 uav uav
G oo G oo G G
2007 2008 2009 2010 2011
11. About Guava
IO Networking Concurrency
Primitive types Collections
12. About Guava
IO Networking Concurrency
Primitive types Collections
13. in com.google.common.base package
public interface Predicate<T> {
Predicate<T> to filter boolean apply(T from);
out a collection }
pu blic interface Function<F, T> {
T apply(F from);
Function<F, T> to
} transform a collection
27. {
public interface Function<F, T>
Set of functions and }
T apply(F from);
public interface Predicate<T> {
predicates for EMF objects }
boolean apply(T from);
Code generators for your
own Ecore models
and few other utility classes
29. Common predicates
Having
IsKind/IsType
IsAncestor/IsChild
public static Collection<EObject> demoHaving(Collection<EObject> c) {
return Collections2.filter(c,
Having.feature(EcorePackage.Literals.ENAMED_ELEMENT__NAME,
StringPredicates.firstUpperCase)
);
}
30. non-EMF functions & predicates
Strings
length : Function<String, Integer>
toL1Case : Function<String, String> Comparable
toLowerCase : Function<String, String>
toU1Case : Function<String, String> Predicates to
toUpperCase : Function<String, String> test ordering:
trim : Function<String, String> equal
replaceAll(Pattern, String) less than
replaceAll(String, String) greater than
replaceFirst(Pattern, String) less or equal
replaceFirst(String, String) greater or equal
substring(int)
substring(int, int)
31. Ecore API has been Guava-ified
‣ EObject.eResource() is wrapped as a Function in
EObjectPath.eResource
‣ EObject.eIsProxy() is wrapped as a Predicate in
EObjectPath.eIsProxy
‣ EClass.getESuperTypes() is wrapped as a
Function in EClass.eSuperTypes
‣ EReference.isContainment() is wrapped as a
Predicate in ERefrencePath.isContainment
32. Ecore has been Guava-ified through a generator
+
that is available for your own Ecore model
38. Wha t you should remember
about this presentation
1. Function and Predicate
2. Lazyness
3. Walking EObjects containment tree
along XPath-like axes
4. Code generators for your own Ecore
model
39. What you should REALLY remember
about this presentation
1. Guava is cool!
2. EMF is cool too!
3. EMFPath bridges the gap between
Guava and EMF
4. EMFPath is cool - Q.E.D
EMFPath v0.4.0 is available NOW!
http://code.google.com/a/eclipselabs.org/p/emfpath/