List of usage examples for java.util Collections max
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
From source file:TwitterClustering.java
public static Long findClosestNumber(List list, Long num) { if (list.size() > 0) { // Check list does not empty Long smaller = (Long) Collections.min(list); // get min number from // the list Long larger = (Long) Collections.max(list); // get max number from // the list for (int i = 0; i < list.size(); i++) { // Traverse list if (num == (Long) list.get(i)) // if find the passed number in // the list {// w w w . j a v a2 s . com return num; // than return num } if (num > (Long) list.get(i) && smaller < (Long) list.get(i)) // find // nearest // smaller { smaller = (Long) list.get(i); } if (num < (Long) list.get(i) && larger > (Long) list.get(i)) // find // nearest // larger { larger = (Long) list.get(i); } } return (num - smaller < larger - num ? smaller : larger); // return // closest // number } return new Long(0); }
From source file:be.ugent.maf.cellmissy.analysis.singlecell.preprocessing.impl.SingleCellWellPreProcessorImpl.java
@Override public void generateShiftedCoordinatesRanges(SingleCellWellDataHolder singleCellWellDataHolder) { Double[][] transposedMatrix = AnalysisUtils .transpose2DArray(singleCellWellDataHolder.getShiftedTrackCoordinatesMatrix()); // compute the min and the max coordinates Double xMin = Collections.min(Arrays.asList(transposedMatrix[0])); Double xMax = Collections.max(Arrays.asList(transposedMatrix[0])); Double yMin = Collections.min(Arrays.asList(transposedMatrix[1])); Double yMax = Collections.max(Arrays.asList(transposedMatrix[1])); Double[][] shiftedCoordinatesRanges = new Double[2][2]; shiftedCoordinatesRanges[0] = new Double[] { xMin, xMax }; shiftedCoordinatesRanges[1] = new Double[] { yMin, yMax }; singleCellWellDataHolder.setShiftedCoordinatesRanges(shiftedCoordinatesRanges); }
From source file:com.wet.wired.jsr.player.ScreenPlayer.java
private void countTotalFramesAndTime() { totalFrames = Collections.max(frameIndex.keySet()); totalTime = frameIndex.get(totalFrames).getFrameTime(); }
From source file:eu.annocultor.tagger.postprocessors.PeopleTermFilter.java
private boolean checkDates(Set<Integer> ulanBirthYears, Set<Integer> ulanDeathYears, int reqBirthYear, int reqDeathYear, int toleranceMultiplier, boolean lifeDate) { // tolerance of 1 year per 100 years back int toleranceOnDeathYear = (2000 - reqDeathYear) * toleranceMultiplier / 100; int toleranceOnBirthYear = (2000 - reqBirthYear) * toleranceMultiplier / 100; if (lifeDate) { return (reqBirthYear >= (Collections.min(ulanBirthYears) - toleranceOnBirthYear)) && (ulanDeathYears.isEmpty() || reqBirthYear <= (Collections.max(ulanDeathYears) + toleranceOnDeathYear)); } else {//from w ww .jav a2s . com // old people should have death year if (reqBirthYear <= allDeadYear && (ulanDeathYears == null || ulanDeathYears.isEmpty())) return false; // if present, birth year should match if (reqBirthYear > 0) { if (!(ulanBirthYears.isEmpty() || (reqBirthYear >= (Collections.min(ulanBirthYears) - toleranceOnBirthYear)) && (reqBirthYear <= (Collections.max(ulanBirthYears) + toleranceOnBirthYear)))) return false; } // if present, death year should match if (reqDeathYear != 0) { // young guys have their right to be alive if (!(reqBirthYear > allDeadYear && ulanDeathYears.isEmpty())) { if (!(ulanDeathYears.isEmpty() || (reqDeathYear >= (Collections.min(ulanDeathYears) - toleranceOnDeathYear)) && (reqDeathYear <= (Collections.max(ulanDeathYears) + toleranceOnDeathYear)))) return false; } } } return true; }
From source file:com.mycompany.complexity.tool.mvn.TreeLayoutDois.java
private int calculateDimensionY(V v) { int size = 0; int childrenNum = graph.getSuccessors(v).size(); List<Integer> maxSize = new ArrayList<>(); if (childrenNum != 0) { for (V element : graph.getSuccessors(v)) { if (!alreadyCalculatedY.contains(element)) { alreadyCalculatedY.add(element); size += calculateDimensionY(element) + distY; }//from w w w . j a v a 2 s . co m } } size = Math.max(0, size - distY); maxSize.add(size); return Collections.max(maxSize); }
From source file:org.kalypso.observation.result.TupleResultUtilities.java
/** * @author thuel2/* ww w . j a va 2s.co m*/ * @return returns maximum value for component of a tupleResult. <br> * Works for components of XmlType XS_BOOLEAN, XS_DOUBLE, XS_DATE, XS_STRING. <br> * For all others <code>object.toString()</code> will be used for comparison. */ public static Object findComponentMaxById(final TupleResult result, final String compID) { final IComponent comp = TupleResultUtilities.findComponentById(result, compID); if (comp == null) { return null; } final QName valueTypeName = comp.getValueTypeName(); final int iComp = result.indexOfComponent(comp); if (XmlTypes.XS_BOOLEAN.equals(valueTypeName)) { final List<Boolean> values = new ArrayList<>(); for (final IRecord record : result) { values.add((Boolean) record.getValue(iComp)); } if (values.size() < 1) { return null; } return Collections.max(values); } else if (XmlTypes.XS_DOUBLE.equals(valueTypeName)) { // TODO think about other numerical types: // XmlTypes.XS_BYTE, XmlTypes.XS_DECIMAL, XmlTypes.XS_FLOAT, XmlTypes.XS_INT, XmlTypes.XS_INTEGER, // XmlTypes.XS_LONG, XmlTypes.XS_SHORT final List<java.lang.Double> values = new ArrayList<>(); for (final IRecord record : result) { values.add((java.lang.Double) record.getValue(iComp)); } if (values.size() < 1) { return null; } return Collections.max(values); } else if (XmlTypes.XS_DATE.equals(valueTypeName)) { // TODO think about other date types // XmlTypes.XS_DATETIME, XmlTypes.XS_DURATION, XmlTypes.XS_TIME final List<Date> values = new ArrayList<>(); for (final IRecord record : result) { values.add((Date) record.getValue(iComp)); } if (values.size() < 1) { return null; } return Collections.max(values); } else if (XmlTypes.XS_STRING.equals(valueTypeName)) { final List<String> values = new ArrayList<>(); for (final IRecord record : result) { values.add((String) record.getValue(iComp)); } if (values.size() < 1) { return null; } return Collections.max(values); } else { final List<String> values = new ArrayList<>(); for (final IRecord record : result) { values.add(record.getValue(iComp).toString()); } if (values.size() < 1) { return null; } return Collections.max(values); } }
From source file:com.github.aptd.simulation.elements.train.CTrain.java
@Override protected final synchronized Instant determinenextstatechange() { switch (m_state) { case DRIVING: return m_lastcontinuousupdate.plus( Math.round((m_timetable.get(m_ttindex).m_tracklength - m_positionontrack) / DRIVING_SPEED), ChronoUnit.SECONDS); case WAITING_TO_DRIVE: return m_doorsnotclosedlocked.isEmpty() ? m_laststatechange : Instant.MAX; case ARRIVED: if (m_ttindex + 1 >= m_timetable.size()) return Instant.MAX; return Collections.max(Arrays.asList(m_timetable.get(m_ttindex).m_publisheddeparture, m_laststatechange.plus(30, ChronoUnit.SECONDS))); default:/* w w w.j a v a 2 s. c o m*/ return m_laststatechange.plus(30, ChronoUnit.SECONDS); } }
From source file:uk.ac.ebi.atlas.bioentity.properties.BioEntityPropertyService.java
private List<PropertyLink> fetchPoLinksOrderedByDepth() { List<PropertyLink> propertyLinks = Lists.newArrayList(); if (!depthToPoTerms.isEmpty()) { for (int i = Collections.max(depthToPoTerms.keySet()); i >= 1; i--) { for (GoPoTerm goPoTerm : depthToPoTerms.get(i)) { Optional<PropertyLink> link = linkBuilder.createLink(identifier, "po", goPoTerm.accession(), species);//w ww .j a v a 2 s . c o m if (link.isPresent()) { propertyLinks.add(link.get()); } } } } return propertyLinks; }
From source file:org.apache.kylin.source.kafka.hadoop.KafkaFlatTableJob.java
private void setupMapper(CubeSegment cubeSeg) throws IOException { // set the segment's offset info to job conf Map<Integer, Long> offsetStart = cubeSeg.getSourcePartitionOffsetStart(); Map<Integer, Long> offsetEnd = cubeSeg.getSourcePartitionOffsetEnd(); Integer minPartition = Collections.min(offsetStart.keySet()); Integer maxPartition = Collections.max(offsetStart.keySet()); job.getConfiguration().set(CONFIG_KAFKA_PARITION_MIN, minPartition.toString()); job.getConfiguration().set(CONFIG_KAFKA_PARITION_MAX, maxPartition.toString()); for (Integer partition : offsetStart.keySet()) { job.getConfiguration().set(CONFIG_KAFKA_PARITION_START + partition, offsetStart.get(partition).toString()); job.getConfiguration().set(CONFIG_KAFKA_PARITION_END + partition, offsetEnd.get(partition).toString()); }/*from www .j a v a2 s . c om*/ job.setMapperClass(KafkaFlatTableMapper.class); job.setInputFormatClass(KafkaInputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setNumReduceTasks(0); }
From source file:com.ebay.pulsar.sessionizer.cluster.SessionizerLoopbackRingListener.java
@Override public boolean isLeader() { if (shutdownFlag || leavingCluster) { return false; }//from ww w . ja v a2 s .com lock.readLock().lock(); try { ArrayList<Long> copy = new ArrayList<Long>(activeConsumers); if (copy.isEmpty()) { return false; } Long maxConsumerId = Collections.max(copy); return maxConsumerId == getHostId(); } finally { lock.readLock().unlock(); } }