SlideShare a Scribd company logo
Mikaël Barbero
        OBEO
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);
	

 	

   	

 }
	

 	

   }
	

 }
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
EMFPath
EMFPath
About Guava
About Guava

IO
About Guava

IO   Networking
About Guava

IO   Networking   Concurrency
About Guava

IO               Networking   Concurrency



     Primitive types
About Guava

IO               Networking       Concurrency



     Primitive types     Collections
About Guava

IO               Networking       Concurrency



     Primitive types     Collections
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
in com.google.common.collect package




                        Iterables.filter()
                        Iterators.filter()
                      Collections2.filter()
                          Sets.filter()
24   42   13   7   128
24                  42               13                7        128



public     static void demo(Collection<Integer> c) {
	

 	

   Predicate<Integer> isEven = new Predicate<Integer>() {
	

 	

   	

 @Override
	

 	

   	

 public boolean apply(Integer input) {
	

 	

   	

 	

 return (input.intValue() % 2 == 0);
	

 	

   	

 }
	

 	

   };
	

 	

   Collections2.filter(c, isEven);
	

 }
24                  42               13                7        128



public     static void demo(Collection<Integer> c) {
	

 	

   Predicate<Integer> isEven = new Predicate<Integer>() {
	

 	

   	

 @Override
	

 	

   	

 public boolean apply(Integer input) {
	

 	

   	

 	

 return (input.intValue() % 2 == 0);
	

 	

   	

 }
	

 	

   };
	

 	

   Collections2.filter(c, isEven);
	

 }




                       24               42              128
in com.google.common.collect package




 Iterables.transform()
 Iterators.transform()
Collections2.transform()
   Lists.transform()
Apple   Orange   Banana   Kiwi   Pear
Apple              Orange            Banana             Kiwi             Pear



public     void demo(Collection<String> c) {
	

 	

   Function<String, String> toUpperCase = new Function<String, String>() {
	

 	

   	

 @Override
	

 	

   	

 public String apply(String input) {
	

 	

   	

 	

 return input.toUpperCase();
	

 	

   	

 }
	

 	

   };
	

 	

   Collections2.transform(c, toUpperCase);
	

 }
Apple              Orange            Banana             Kiwi             Pear



public     void demo(Collection<String> c) {
	

 	

   Function<String, String> toUpperCase = new Function<String, String>() {
	

 	

   	

 @Override
	

 	

   	

 public String apply(String input) {
	

 	

   	

 	

 return input.toUpperCase();
	

 	

   	

 }
	

 	

   };
	

 	

   Collections2.transform(c, toUpperCase);
	

 }




APPLE             ORANGE           BANANA               KIWI             PEAR
Compose and combine
Functions
    compose
    forPredicate

Predicates
     and
     or
     not
     compose
Beware
of
Beware
of


lazyness
Copy!
Lists.newArrayList()
Lists.newLinkedList()
Sets.newHashSet()
Sets.newLinkedHashSet()
Sets.newTreeSet()



and make it immutable...

        ImmutableList.copyOf()
        ImmutableSet.copyOf()
Path
{
                                 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
Lazy EObjects containment tree walking

   ‣ parent     (eContainer)

   ‣ ancestor
   ‣ ancestorOrSelf
   ‣ child   (eContents)

   ‣ descendant            (eAllContents)

   ‣ descendantOrSelf
   ‣ following
   ‣ followingSibling
   ‣ preceding
   ‣ precedingSibling

 EObject myObject;
 Collection<EObject> fs = followingSibling.of(myObject);
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)
 	

 	

   	

 );
 	

 }
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)
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
Ecore has been Guava-ified through a generator




             +


    that is available for your own Ecore model
time to play
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);
	

 	

   	

 }
	

 	

   }
	

 }
public      void demo2(Library l) {
	

 	

     List<Book> books = l.getBooks();
	

 	

	

 	

     Set<Borrower> allBorrowers =
	

 	

     	

 ImmutableSet.copyOf(
	

 	

     	

 	

 Iterables.concat(
	

 	

     	

 	

 	

 Collections2.transform(books, BookPath.borrowers)));

	

   	

   List<Writer> allWriters = Lists.transform(books, BookPath.author);
	

   	

	

   	

   Predicate<Borrower> predicate = new Predicate<Borrower>() {
	

   	

   	

 @Override
	

   	

   	

 public boolean apply(Borrower borrower) {
	

   	

   	

 	

 return borrower.getLastName().startsWith("B") &&
	

   	

   	

 	

 borrower.getBorrowed().contains(aSpecificBook);
	

   	

   	

 }
	

   	

   };
	

   	

	

   	

   Set<Borrower> filteredBorrowers = Sets.filter(allBorrowers, predicate);
	

   }
public      void demo2(Library l) {
	

 	

     List<Book> books = l.getBooks();
	

 	

	

 	

     Set<Borrower> allBorrowers =
	

 	

     	

 ImmutableSet.copyOf(
	

 	

     	

 	

 Iterables.concat(
	

 	

     	

 	

 	

 Collections2.transform(books, BookPath.borrowers)));

	

   	

   List<Writer> allWriters = Lists.transform(books, BookPath.author);
	

   	

	

   	

   Predicate<Borrower> predicate = new Predicate<Borrower>() {
	

   	

   	

 @Override
	

   	

   	

 public boolean apply(Borrower borrower) {
	

   	

   	

 	

 return borrower.getLastName().startsWith("B") &&
	

   	

   	

 	

 borrower.getBorrowed().contains(aSpecificBook);
	

   	

   	

 }
	

   	

   };
	

   	

	

   	

   Set<Borrower> filteredBorrowers = Sets.filter(allBorrowers, predicate);
	

   }
public      void demo2(Library l) {
	

 	

     List<Book> books = l.getBooks();
	

 	

	

 	

     Set<Borrower> allBorrowers =
	

 	

     	

 ImmutableSet.copyOf(
	

 	

     	

 	

 Iterables.concat(
	

 	

     	

 	

 	

 Collections2.transform(books, BookPath.borrowers)));

	

   	

   List<Writer> allWriters = Lists.transform(books, BookPath.author);
	

   	

	

   	

   Set<Borrower> filteredBorrowers = Sets.filter(allBorrowers, predicate);
	

   }
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
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/
Q&A

More Related Content

PDF
Google Guava for cleaner code
PDF
Google guava
PDF
Google guava - almost everything you need to know
PDF
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
PDF
The core libraries you always wanted - Google Guava
PPTX
Ian 20150116 java script oop
KEY
Google Guava
PPTX
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Google Guava for cleaner code
Google guava
Google guava - almost everything you need to know
Kotlin for Android Developers - Victor Kropp - Codemotion Rome 2018
The core libraries you always wanted - Google Guava
Ian 20150116 java script oop
Google Guava
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor

What's hot (20)

PDF
Kotlin Generation
PDF
Google guava overview
ODP
Groovy intro for OUDL
PDF
The Ring programming language version 1.6 book - Part 15 of 189
PDF
The Ring programming language version 1.7 book - Part 16 of 196
PDF
Google Guava
PDF
Introduction kot iin
PDF
Google Guava - Core libraries for Java & Android
PDF
Clean code with google guava jee conf
PDF
5. Ввод-вывод, доступ к файловой системе
PPT
Swiss army knife Spring
PDF
Sneaking inside Kotlin features
PDF
Miracle of std lib
PPTX
Nice to meet Kotlin
PDF
Jggug 2010 330 Grails 1.3 観察
PDF
Mastering Kotlin Standard Library
KEY
(map Clojure everyday-tasks)
ODP
Scala 2 + 2 > 4
PDF
The Ring programming language version 1.5.2 book - Part 76 of 181
PPTX
Using Reflections and Automatic Code Generation
Kotlin Generation
Google guava overview
Groovy intro for OUDL
The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.7 book - Part 16 of 196
Google Guava
Introduction kot iin
Google Guava - Core libraries for Java & Android
Clean code with google guava jee conf
5. Ввод-вывод, доступ к файловой системе
Swiss army knife Spring
Sneaking inside Kotlin features
Miracle of std lib
Nice to meet Kotlin
Jggug 2010 330 Grails 1.3 観察
Mastering Kotlin Standard Library
(map Clojure everyday-tasks)
Scala 2 + 2 > 4
The Ring programming language version 1.5.2 book - Part 76 of 181
Using Reflections and Automatic Code Generation
Ad

Viewers also liked (15)

PDF
OSGi: Don't let me be Misunderstood
PDF
Eclipseconeurope 2011 - EMFCompare Improvements
PDF
Eclipse simultaneous release in a nutshell
PDF
What every Eclipse developer should know about progress reporting and job can...
PDF
Diff and Merge with Ease: EMF Compare
KEY
EMFCompare 2.0: Scaling to Millions
PDF
Modeling in a Team Environment with EMF Compare and EGit
PDF
Sirius: Graphical Editors for your DSLs
PDF
EMF.Edit the Force Unleashed!
PDF
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
KEY
3mf infinity-and-beyond
ODP
5M lines of code migration
PDF
EMF Compare 2.0: Scaling to Millions (updated)
PDF
The Eclipse IDE - The Force Awakens (Devoxx France 2016)
PDF
Google Guava & EMF @ GTUG Nantes
OSGi: Don't let me be Misunderstood
Eclipseconeurope 2011 - EMFCompare Improvements
Eclipse simultaneous release in a nutshell
What every Eclipse developer should know about progress reporting and job can...
Diff and Merge with Ease: EMF Compare
EMFCompare 2.0: Scaling to Millions
Modeling in a Team Environment with EMF Compare and EGit
Sirius: Graphical Editors for your DSLs
EMF.Edit the Force Unleashed!
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
3mf infinity-and-beyond
5M lines of code migration
EMF Compare 2.0: Scaling to Millions (updated)
The Eclipse IDE - The Force Awakens (Devoxx France 2016)
Google Guava & EMF @ GTUG Nantes
Ad

Similar to EMFPath (20)

PDF
FP in Java - Project Lambda and beyond
PDF
Introduction to new features in java 8
PDF
Java 8 Workshop
PPT
JDK1.7 features
PDF
Clojure - A new Lisp
PDF
Scala is java8.next()
PDF
Ekeko Technology Showdown at SoTeSoLa 2012
PDF
Java7 New Features and Code Examples
PPTX
K is for Kotlin
PDF
京都Gtugコンパチapi
PDF
Reactive programming on Android
PDF
Kotlin: forse è la volta buona (Trento)
PDF
JJUG CCC 2011 Spring
PDF
What is new in java 8 concurrency
PPTX
Introducing PHP Latest Updates
PDF
Productive Programming in Java 8 - with Lambdas and Streams
PDF
Functor, Apply, Applicative And Monad
PDF
The Future of JVM Languages
PDF
响应式编程及框架
FP in Java - Project Lambda and beyond
Introduction to new features in java 8
Java 8 Workshop
JDK1.7 features
Clojure - A new Lisp
Scala is java8.next()
Ekeko Technology Showdown at SoTeSoLa 2012
Java7 New Features and Code Examples
K is for Kotlin
京都Gtugコンパチapi
Reactive programming on Android
Kotlin: forse è la volta buona (Trento)
JJUG CCC 2011 Spring
What is new in java 8 concurrency
Introducing PHP Latest Updates
Productive Programming in Java 8 - with Lambdas and Streams
Functor, Apply, Applicative And Monad
The Future of JVM Languages
响应式编程及框架

EMFPath

  • 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
  • 8. About Guava IO Networking
  • 9. About Guava IO Networking Concurrency
  • 10. About Guava IO Networking Concurrency Primitive types
  • 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
  • 14. in com.google.common.collect package Iterables.filter() Iterators.filter() Collections2.filter() Sets.filter()
  • 15. 24 42 13 7 128
  • 16. 24 42 13 7 128 public static void demo(Collection<Integer> c) { Predicate<Integer> isEven = new Predicate<Integer>() { @Override public boolean apply(Integer input) { return (input.intValue() % 2 == 0); } }; Collections2.filter(c, isEven); }
  • 17. 24 42 13 7 128 public static void demo(Collection<Integer> c) { Predicate<Integer> isEven = new Predicate<Integer>() { @Override public boolean apply(Integer input) { return (input.intValue() % 2 == 0); } }; Collections2.filter(c, isEven); } 24 42 128
  • 18. in com.google.common.collect package Iterables.transform() Iterators.transform() Collections2.transform() Lists.transform()
  • 19. Apple Orange Banana Kiwi Pear
  • 20. Apple Orange Banana Kiwi Pear public void demo(Collection<String> c) { Function<String, String> toUpperCase = new Function<String, String>() { @Override public String apply(String input) { return input.toUpperCase(); } }; Collections2.transform(c, toUpperCase); }
  • 21. Apple Orange Banana Kiwi Pear public void demo(Collection<String> c) { Function<String, String> toUpperCase = new Function<String, String>() { @Override public String apply(String input) { return input.toUpperCase(); } }; Collections2.transform(c, toUpperCase); } APPLE ORANGE BANANA KIWI PEAR
  • 22. Compose and combine Functions compose forPredicate Predicates and or not compose
  • 26. Path
  • 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
  • 28. Lazy EObjects containment tree walking ‣ parent (eContainer) ‣ ancestor ‣ ancestorOrSelf ‣ child (eContents) ‣ descendant (eAllContents) ‣ descendantOrSelf ‣ following ‣ followingSibling ‣ preceding ‣ precedingSibling EObject myObject; Collection<EObject> fs = followingSibling.of(myObject);
  • 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
  • 34. 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); } } }
  • 35. public void demo2(Library l) { List<Book> books = l.getBooks(); Set<Borrower> allBorrowers = ImmutableSet.copyOf( Iterables.concat( Collections2.transform(books, BookPath.borrowers))); List<Writer> allWriters = Lists.transform(books, BookPath.author); Predicate<Borrower> predicate = new Predicate<Borrower>() { @Override public boolean apply(Borrower borrower) { return borrower.getLastName().startsWith("B") && borrower.getBorrowed().contains(aSpecificBook); } }; Set<Borrower> filteredBorrowers = Sets.filter(allBorrowers, predicate); }
  • 36. public void demo2(Library l) { List<Book> books = l.getBooks(); Set<Borrower> allBorrowers = ImmutableSet.copyOf( Iterables.concat( Collections2.transform(books, BookPath.borrowers))); List<Writer> allWriters = Lists.transform(books, BookPath.author); Predicate<Borrower> predicate = new Predicate<Borrower>() { @Override public boolean apply(Borrower borrower) { return borrower.getLastName().startsWith("B") && borrower.getBorrowed().contains(aSpecificBook); } }; Set<Borrower> filteredBorrowers = Sets.filter(allBorrowers, predicate); }
  • 37. public void demo2(Library l) { List<Book> books = l.getBooks(); Set<Borrower> allBorrowers = ImmutableSet.copyOf( Iterables.concat( Collections2.transform(books, BookPath.borrowers))); List<Writer> allWriters = Lists.transform(books, BookPath.author); Set<Borrower> filteredBorrowers = Sets.filter(allBorrowers, predicate); }
  • 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/
  • 40. Q&A