Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package uk.co.optimisticpanda.atom;
 
 import static com.google.common.base.Predicates.equalTo;
 import static com.google.common.base.Predicates.in;
 
 import java.util.List;
 
 import  javax.ws.rs.core.MediaType;
public enum EntryFunctions {
    ;

    
If any category is present then return true
    public static Predicate<EntryhaveACategoryOf(String... categories) {
        final List<Stringlist = Arrays.asList(categories);
        return new Predicate<Entry>() {
            public boolean apply(Entry input) {
                for (Category category : input.getCategories()) {
                    if (in(list).apply(category.getTerm())) {
                        return true;
                    }
                }
                return false;
            }
        };
    };

    
If any category is present then return false
    public static Predicate<EntrydontHaveCategory(String... categories) {
        final List<Stringlist = Arrays.asList(categories);
        return new Predicate<Entry>() {
            public boolean apply(Entry input) {
                for (Category category : input.getCategories()) {
                    if (in(list).apply(category.getTerm())) {
                        return false;
                    }
                }
                return true;
            }
        };
    };

    
Return true if we have an entry that has an id that matches thi
    public static Predicate<EntryidEquals(final String id) {
        return new Predicate<Entry>() {
            public boolean apply(Entry input) {
                if (input.getId() != null) {
                    return id.equals(input.getId().toString());
                } else {
                    return false;
                }
            }
        };
    };

    
Return true if we have an entry that has content that matches this mediatyp
    public static Predicate<EntrycontentHasMediaType(final MediaType mediaType) {
        return new Predicate<Entry>() {
            public boolean apply(Entry input) {
                return equalTo(mediaType.toString()).apply(input.getContentMimeType().toString());
            }
        };
    };

    
Order entries by updatedDate - earliest to lates
    public static Ordering<EntryearliestToLatest() {
        return new Ordering<Entry>() {
            public int compare(Entry o1Entry o2) {
                return ComparisonChain.start() //
                        .compare(o1.getUpdated(), o2.getUpdated(), Ordering.natural().nullsLast()) //
                        .result();
            }
        };
    }

    
Order entries by updatedDate - latest to earlies
    public static Ordering<EntrylatestToEarliest() {
        return earliestToLatest().reverse();
    }

    
Do not order entrie
    public static Ordering<EntrynaturalOrdering() {
        return new Ordering<Entry>() {
            @Override
            public int compare(Entry leftEntry right) {
                return 0;
            }
        };
    }
New to GrepCode? Check out our FAQ X