List of usage examples for java.util Collections sort
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> void sort(List<T> list, Comparator<? super T> c)
From source file:com.kevinquan.google.activityrecoginition.model.MotionHelper.java
public static List<MotionSnapshot> parseMotionSnapshots(Cursor result, final boolean sortDescending) { if (!CursorUtils.hasResults(result)) { Log.d(TAG, "No results were provided to parse motion snapshots from"); return new ArrayList<MotionSnapshot>(); }//from w w w . j ava2s.co m Hashtable<Long, MotionSnapshot> snapshots = new Hashtable<Long, MotionSnapshot>(); do { Motion thisMotion = new Motion(result); if (thisMotion.getTimestamp() == 0) { Log.w(TAG, "Current motion seems corrupt: " + thisMotion); continue; } if (!snapshots.containsKey(thisMotion.getTimestamp())) { MotionSnapshot snapshot = new MotionSnapshot(thisMotion); snapshots.put(snapshot.getTimestamp(), snapshot); } else { if (!snapshots.get(thisMotion.getTimestamp()).addMotion(thisMotion)) { Log.w(TAG, "Could not add motion to snapshot: " + thisMotion.toString()); } } } while (result.moveToNext()); List<MotionSnapshot> results = new ArrayList<MotionSnapshot>(); results.addAll(snapshots.values()); Collections.sort(results, new Comparator<MotionSnapshot>() { @Override public int compare(MotionSnapshot lhs, MotionSnapshot rhs) { int result = ((Long) lhs.getTimestamp()).compareTo((Long) rhs.getTimestamp()); return sortDescending ? -1 * result : result; } }); return results; }
From source file:eu.scidipes.toolkits.pawebapp.util.FrameworkUtils.java
/** * Retrieves a <code>List</code> of {@link RepInfoCategory}s via the Framework which is sorted by ascending * alphabetical order based on the category's name. * /*ww w .ja v a 2s .c o m*/ * @return a list of categories sorted by name */ public static List<RepInfoCategory> getSortedCategories() { final Comparator<RepInfoCategory> ricComparator = new Comparator<RepInfoCategory>() { @Override public int compare(final RepInfoCategory cat1, final RepInfoCategory cat2) { return cat1.getName().compareTo(cat2.getName()); } }; final List<RepInfoCategory> categories = new ArrayList<>(FrameworkWrapper.getAllPredefinedCategories()); Collections.sort(categories, ricComparator); return categories; }
From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.StudentExecutionYearsProvider.java
@Override public Object provide(Object source, Object currentValue) { List<ExecutionYear> result = new ArrayList(((RegistrationSelectExecutionYearBean) source).getRegistration() .getStudent().getEnrolmentsExecutionYears()); Collections.sort(result, new BeanComparator("year")); return result; }
From source file:com.yattatech.domain.Seminary.java
public List<Couple> getOrderedCouplesByHusbandName() { if (couples == null) { couples = new ArrayList<Couple>(); }/* w w w .java 2 s . com*/ final ArrayList<Couple> orderCouples = new ArrayList<Couple>(couples); Collections.sort(orderCouples, COMPARATOR_0); return orderCouples; }
From source file:de.thischwa.pmcms.gui.treeview.TreeViewSiteRecourceNode.java
public List<T> getSiteResources() { Collections.sort(siteResources, new ResourceComparator()); return siteResources; }
From source file:com.sqewd.open.dal.core.persistence.query.EntityListSorter.java
public <T extends AbstractEntity> void sort(final List<T> entities) throws Exception { Collections.sort(entities, this); }
From source file:Person.java
public void order(boolean asc) { Comparator<Person> comp = asc ? new ComparePerson() : Collections.reverseOrder(new ComparePerson()); Collections.sort(this.listPersons, comp); }
From source file:Main.java
public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(parameters.getSupportedPreviewSizes()); Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() { @Override/*from www . j av a 2 s . c o m*/ public int compare(Camera.Size a, Camera.Size b) { int aPixels = a.height * a.width; int bPixels = b.height * b.width; if (bPixels < aPixels) { return -1; } if (bPixels > aPixels) { return 1; } return 0; } }); Point bestSize = null; float screenAspectRatio = (float) screenResolution.x / (float) screenResolution.y; float diff = Float.POSITIVE_INFINITY; for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { int realWidth = supportedPreviewSize.width; int realHeight = supportedPreviewSize.height; int pixels = realWidth * realHeight; if (pixels < MIN_PREVIEW_PIXELS || pixels > MAX_PREVIEW_PIXELS) { continue; } boolean isCandidatePortrait = realWidth < realHeight; int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { return new Point(realWidth, realHeight); } float aspectRatio = (float) maybeFlippedWidth / (float) maybeFlippedHeight; float newDiff = Math.abs(aspectRatio - screenAspectRatio); if (newDiff < diff) { bestSize = new Point(realWidth, realHeight); diff = newDiff; } } if (bestSize == null) { Camera.Size defaultSize = parameters.getPreviewSize(); bestSize = new Point(defaultSize.width, defaultSize.height); } return bestSize; }
From source file:com.speedment.examples.social.JSONImage.java
public static List<JSONImage> parseFrom(String json) { final JSONObject container = (JSONObject) JSONValue.parse(json); final JSONArray array = (JSONArray) container.get("images"); final List<JSONImage> images = new ArrayList<>(); array.stream().forEach(o -> {//from ww w.j a v a 2 s . c o m final JSONObject obj = (JSONObject) o; final JSONImage img = new JSONImage(); final long time = Long.parseLong(obj.get("uploaded").toString()); final LocalDateTime ldt = LocalDateTime.ofEpochSecond(time / 1000L, (int) (time % 1000) * 1000, ZoneOffset.UTC); img.title = obj.get("title").toString(); img.description = obj.get("description").toString(); img.uploaded = ldt; img.uploader = JSONUser.parse((JSONObject) obj.get("uploader")); img.image = fromBase64(obj.get("img_data").toString()); images.add(img); }); Collections.sort(images, Comparator.reverseOrder()); return images; }
From source file:net.sourceforge.fenixedu.presentationTier.renderers.providers.AcademicIntervalProvider.java
@Override public Object provide(Object source, Object current) { List<AcademicInterval> result = AcademicInterval.readAcademicIntervals(AcademicPeriod.SEMESTER); Collections.sort(result, new ReverseComparator(AcademicInterval.COMPARATOR_BY_BEGIN_DATE)); return result; }