Share

Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Google guava' - 7 code snippet(s) found

 Sample 1. Initialize list using google guava Lists

import java.util.List;
import com.google.common.collect.Lists;

class GoogleListsTest{
public static void main(String[] args){
List list = Lists.newArrayList();
}
}

   Like      Feedback     list  google guava  Lists  Lists.newArrayList  com.google.common.collect.Lists


 Sample 2. Loading Cache Map using Google Guava LoadingCache and CacheBuilder

LoadingCache<String,String> loadingCache = CacheBuilder.newBuilder().maximumSize(100).expireAfterWrite(1, TimeUnit.MINUTES).build(new CacheLoader<String,String>(){
   @Override
   public String load(String arg0) throws Exception {
      return "";
   }
});

   Like      Feedback     google guava  loadingcache  CacheBuilder  CacheLoader


 Sample 3. Filtering objects using google.common.base.Predicate

static Collection<Employee> employeesGreaterThan30(Collection<Employee> employees) {
return filter(employees, new Predicate<Employee>() {
@Override
public boolean apply(Employee employee) {
return employee.getAge() > 30;
}
});
}

   Like      Feedback     predicate  google.common.base.Predicate  filter objects   alternate for predicate before java 8  collections  google guava


 Sample 4. Order Collection using google.common.collect.Ordering

Collection<Employee> sortedEmployeess = Ordering.from(new Comparator<Employee>() {
@Override
public int compare(Employee employee1, Employee employee2) {
return employee1.getAge() - employee2.getAge();
}
};).sortedCopy(employees);

   Like      Feedback     collections  sorting collections   sorting collections using google library  comparator  compare method  google.common.collect.Ordering  google guava


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
 Sample 5. Repeat a string using Google Guava Strings Class

System.out.println(Strings.repeat("Hello", 5));

   Like      Feedback     google guava  google guava string  strings.repeat  repeat characters   repeat string


 Sample 6. Usage of com.google.common.base.Preconditions.checkNotNull

Preconditions.checkNotNull(objectRef, "object reference holds null at this point");

   Like      Feedback     Google Guava  Preconditions


 Sample 7. Usage of com.google.common.base.Preconditions.checkArgument

Preconditions.checkArgument(argument >= 0, "argument should be a positive number");

   Like      Feedback     Google Guava  Preconditions



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus