List of usage examples for java.util Collections max
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)
From source file:arun.com.chromer.browsing.customtabs.dynamictoolbar.AppColorExtractorJob.java
private int getPreferredColorFromSwatches(Palette palette) { final List<Palette.Swatch> swatchList = ColorUtil.getSwatchListFromPalette(palette); final Palette.Swatch prominentSwatch = Collections.max(swatchList, (swatch1, swatch2) -> { int a = swatch1 == null ? 0 : swatch1.getPopulation(); int b = swatch2 == null ? 0 : swatch2.getPopulation(); return a - b; });/*from ww w . jav a 2s . c o m*/ if (prominentSwatch != null) return prominentSwatch.getRgb(); else return -1; }
From source file:org.opencms.site.xmlsitemap.CmsDetailPageDuplicateEliminatingSitemapGenerator.java
/** * @see org.opencms.site.xmlsitemap.CmsXmlSitemapGenerator#generateSitemapBeans() *//* w w w . j a va 2 s . c o m*/ @Override public List<CmsXmlSitemapUrlBean> generateSitemapBeans() throws CmsException { List<CmsXmlSitemapUrlBean> parentResult = super.generateSitemapBeans(); List<CmsXmlSitemapUrlBean> result = Lists.newArrayList(); Multimap<String, CmsXmlSitemapUrlBean> detailPageBeans = ArrayListMultimap.create(); // We want to eliminate duplicate detail pages for the same detail content and locale, // so first we group the XML sitemap beans belonging to detail pages by their locale/content combination, // and then we sort each group by the sitemap configuration where the detail page is coming from, // and then only take the last element in each group. for (CmsXmlSitemapUrlBean urlBean : parentResult) { if (urlBean.getDetailPageResource() == null) { result.add(urlBean); } else { String localeKey = urlBean.getOriginalResource().getStructureId() + "_" + urlBean.getLocale(); detailPageBeans.put(localeKey, urlBean); } } Comparator<CmsXmlSitemapUrlBean> pathComparator = new Comparator<CmsXmlSitemapUrlBean>() { public int compare(CmsXmlSitemapUrlBean urlbean1, CmsXmlSitemapUrlBean urlbean2) { String subsite1 = urlbean1.getSubsite(); if (subsite1 == null) { subsite1 = ""; } String subsite2 = urlbean2.getSubsite(); if (subsite2 == null) { subsite2 = ""; } return subsite1.compareTo(subsite2); } }; for (String key : detailPageBeans.keySet()) { result.add(Collections.max(detailPageBeans.get(key), pathComparator)); } return result; }
From source file:com.tlongdev.bktf.adapter.HistoryAdapter.java
private void buildDataSet() { long first = Collections.min(mDataSet, priceAgeComparator).getLastUpdate(); long last = Collections.max(mDataSet, priceAgeComparator).getLastUpdate(); long days = TimeUnit.MILLISECONDS.toDays(last - first); int textColor = ContextCompat.getColor(mContext, R.color.text_primary); //Setup the X axis of the chart ArrayList<String> xValues = new ArrayList<>(); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yy", Locale.ENGLISH); for (long day = 0; day < days * 1.1; day++) { xValues.add(dateFormat.format(new Date(first + (day * 86400000L)))); }//from www .jav a 2 s . c o m if (mDataSet.size() > 0) { ArrayList<Entry> entries = new ArrayList<>(); for (Price price : mDataSet) { int day = (int) TimeUnit.MILLISECONDS.toDays(price.getLastUpdate() - first); entries.add(new Entry( (float) price.getConvertedAveragePrice(mContext, mItem.getPrice().getCurrency()), day)); } LineDataSet set = new LineDataSet(entries, mItem.getPrice().getCurrency()); set.setColor(textColor); set.setCircleColor(textColor); set.setHighLightColor(textColor); set.setAxisDependency(YAxis.AxisDependency.LEFT); set.setDrawValues(false); //Add data to the chart mData = new LineData(xValues, set); } }
From source file:com.thoughtworks.gauge.Table.java
private int getMaxStringSize(List<String> candidates) { if (candidates == null || candidates.isEmpty()) { return -1; }// w w w .ja v a2 s . c o m return Collections.max(candidates, maxStringLength()).length(); }
From source file:ddf.catalog.transformer.OverlayMetacardTransformer.java
public static List<Vector> calculateBoundingBox(List<Vector> boundary) { double maxLon = Collections.max(boundary, Comparator.comparing(v -> v.get(0))).get(0); double minLon = Collections.min(boundary, Comparator.comparing(v -> v.get(0))).get(0); double maxLat = Collections.max(boundary, Comparator.comparing(v -> v.get(1))).get(1); double minLat = Collections.min(boundary, Comparator.comparing(v -> v.get(1))).get(1); List<Vector> boundingBox = new ArrayList<>(); boundingBox.add(new BasicVector(new double[] { minLon, maxLat })); boundingBox.add(new BasicVector(new double[] { maxLon, minLat })); return boundingBox; }
From source file:com.palantir.paxos.PaxosStateLogImpl.java
public long getExtremeLogEntry(Extreme extreme) { lock.lock();/* w w w.ja va 2 s . co m*/ try { File dir = new File(path); List<File> files = getLogEntries(dir); if (files == null) { return PaxosAcceptor.NO_LOG_ENTRY; } try { File file = (extreme == Extreme.GREATEST) ? Collections.max(files, nameAsLongComparator()) : Collections.min(files, nameAsLongComparator()); long seq = getSeqFromFilename(file); return seq; } catch (NoSuchElementException e) { return PaxosAcceptor.NO_LOG_ENTRY; } } finally { lock.unlock(); } }
From source file:hu.ppke.itk.nlpg.purepos.MorphTagger.java
private IToken findBestLemma(IToken t, int position) { Collection<IToken> stems; if (Util.analysisQueue.hasAnal(position)) { stems = Util.analysisQueue.getAnalysises(position); stems = this.simplifyLemmata(stems); this.isLastGuessed = false; } else {//from www. ja va 2 s .c om stems = analyzer.analyze(t); this.isLastGuessed = false; } Map<ILemmaTransformation<String, Integer>, Double> tagLogProbabilities = model.getLemmaGuesser() .getTagLogProbabilities(t.getToken()); Map<IToken, Pair<ILemmaTransformation<String, Integer>, Double>> lemmaSuffixProbs = LemmaUtil .batchConvert(tagLogProbabilities, t.getToken(), model.getTagVocabulary()); boolean useMorph = true; if (Util.isEmpty(stems)) { this.isLastGuessed = true; // the guesser is used useMorph = false; stems = lemmaSuffixProbs.keySet(); } // matching tags Collection<IToken> possibleStems = new HashSet<IToken>(); for (IToken ct : stems) { if (t.getTag().equals(ct.getTag())) { // possibleStems.add(new Token(ct.getToken(), ct.getStem(), ct // .getTag())); possibleStems.add(ct); // possibleStems.add(new Token(ct.getToken(), Util.toLower(ct // .getStem()), ct.getTag())); } } if (Util.isEmpty(possibleStems)) { // error handling return new Token(t.getToken(), t.getToken(), t.getTag()); } // most frequrent stem IToken best; if (possibleStems.size() == 1 && !Util.isUpper(t.getToken())) { best = possibleStems.iterator().next(); } else { if (stemFilter != null) { possibleStems = stemFilter.filterStem(possibleStems); } List<Pair<IToken, ILemmaTransformation<String, Integer>>> comp = new LinkedList<Pair<IToken, ILemmaTransformation<String, Integer>>>(); for (IToken possTok : possibleStems) { Pair<ILemmaTransformation<String, Integer>, Double> pair = lemmaSuffixProbs.get(possTok); ILemmaTransformation<String, Integer> traf; if (pair != null) { traf = pair.getKey(); } else { traf = LemmaUtil.defaultLemmaRepresentation(possTok, model.getData()); } comp.add(Pair.of(possTok, traf)); if (!useMorph) { IToken lowerTok = new Token(possTok.getToken(), Util.toLower(possTok.getStem()), possTok.getTag()); comp.add(Pair.of(lowerTok, traf)); } } //try { best = Collections.max(comp, lemmaComparator).getKey(); //} catch (Exception e) { // System.err.println(t); // return null; //} } IToken ret = decodeLemma(best); return ret; }
From source file:MainActivity.java
protected void takePicture(View view) { if (null == mCameraDevice) { return;/*from w w w . jav a 2 s . com*/ } CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId()); StreamConfigurationMap configurationMap = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (configurationMap == null) return; Size largest = Collections.max(Arrays.asList(configurationMap.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); ImageReader reader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, 1); List<Surface> outputSurfaces = new ArrayList<Surface>(2); outputSurfaces.add(reader.getSurface()); outputSurfaces.add(new Surface(mTextureView.getSurfaceTexture())); final CaptureRequest.Builder captureBuilder = mCameraDevice .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(reader.getSurface()); captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { Image image = null; try { image = reader.acquireLatestImage(); ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.capacity()]; buffer.get(bytes); OutputStream output = new FileOutputStream(getPictureFile()); output.write(bytes); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (image != null) { image.close(); } } } }; HandlerThread thread = new HandlerThread("CameraPicture"); thread.start(); final Handler backgroudHandler = new Handler(thread.getLooper()); reader.setOnImageAvailableListener(readerListener, backgroudHandler); final CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { super.onCaptureCompleted(session, request, result); Toast.makeText(MainActivity.this, "Picture Saved", Toast.LENGTH_SHORT).show(); startPreview(session); } }; mCameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession session) { try { session.capture(captureBuilder.build(), captureCallback, backgroudHandler); } catch (CameraAccessException e) { e.printStackTrace(); } } @Override public void onConfigureFailed(CameraCaptureSession session) { } }, backgroudHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.example.mediastock.util.Utilities.java
/** * Find most represented swatch of the palette, based on population. *//* w w w . j av a2 s. co m*/ public static Palette.Swatch getDominantSwatch(Palette palette) { return Collections.max(palette.getSwatches(), new Comparator<Palette.Swatch>() { @Override public int compare(Palette.Swatch sw1, Palette.Swatch sw2) { return Integer.compare(sw1.getPopulation(), sw2.getPopulation()); } }); }
From source file:fm.last.moji.tracker.pool.MultiHostTrackerPool.java
private ManagedTrackerHost nextHost() throws TrackerException { return Collections.max(managedHosts, HostPriorityOrder.INSTANCE); }