1 25 26 package org.snipsnap.snip.storage.query; 27 28 import java.util.*; 29 30 36 37 public class QueryKit { 38 46 public static List querySorted(List list, Comparator c, int size) { 47 ArrayList result = new ArrayList(list); 48 Collections.sort(result, c); 49 return result.subList(0, Math.min(size, result.size())); 50 } 51 52 60 public static List querySorted(List list, Query query, Comparator c) { 61 List result = query(list, query); 62 Collections.sort(result, c); 63 return result; 64 } 65 66 75 public static List querySorted(List list, Query query, Comparator c, int size) { 76 List result = query(list, query); 77 Collections.sort(result, c); 78 return result.subList(0, Math.min(size, result.size())); 79 } 80 86 public static List query(List list, Query query) { 87 Iterator iterator = list.iterator(); 88 List result = new ArrayList(); 89 while (iterator.hasNext()) { 90 Object object = iterator.next(); 91 if (query.fit(object)) { 92 result.add(object); 93 } 94 } 95 return result; 96 } 97 } 98 | Popular Tags |