SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
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
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

Más contenido relacionado

La actualidad más candente

Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
Mario Fusco
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 

La actualidad más candente (20)

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

Destacado

OSGi: Don't let me be Misunderstood
OSGi: Don't let me be MisunderstoodOSGi: Don't let me be Misunderstood
OSGi: Don't let me be Misunderstood
mikaelbarbero
 
Diff and Merge with Ease: EMF Compare
Diff and Merge with Ease: EMF CompareDiff and Merge with Ease: EMF Compare
Diff and Merge with Ease: EMF Compare
mikaelbarbero
 
EMF.Edit the Force Unleashed!
EMF.Edit the Force Unleashed!EMF.Edit the Force Unleashed!
EMF.Edit the Force Unleashed!
mikaelbarbero
 
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
Generating an Android App with Acceleo (Eclipse Summit Europe 2010)
mikaelbarbero
 
Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantes
mikaelbarbero
 

Destacado (15)

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

Similar a EMFPath

FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
elliando dias
 
Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012
Coen De Roover
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
Kiyotaka Oku
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 

Similar a EMFPath (20)

FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
JDK1.7 features
JDK1.7 featuresJDK1.7 features
JDK1.7 features
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
Scala is java8.next()
Scala is java8.next()Scala is java8.next()
Scala is java8.next()
 
Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
京都Gtugコンパチapi
京都Gtugコンパチapi京都Gtugコンパチapi
京都Gtugコンパチapi
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrency
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And Monad
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
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
  • 4.
  • 5.
  • 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