Example usage for java.util Collections min

List of usage examples for java.util Collections min

Introduction

In this page you can find the example usage for java.util Collections min.

Prototype

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) 

Source Link

Document

Returns the minimum element of the given collection, according to the order induced by the specified comparator.

Usage

From source file:net.sourceforge.fenixedu.domain.candidacy.Candidacy.java

private CandidacySituation getFirstCandidacySituation() {
    return Collections.min(getCandidacySituationsSet(), CandidacySituation.DATE_COMPARATOR);
}

From source file:es.udc.gii.common.eaf.algorithm.operator.selection.TournamentSelection.java

@Override
protected Individual select(EvolutionaryAlgorithm algorithm, List<Individual> individuals) {

    Individual[] pool = null;//  w w w. j a  v a  2s .  c  o m
    Individual[] individualsArray = null;
    Individual selected;

    int maxRandom = individuals.size() - 1;
    int selectedIndividual;

    pool = new Individual[poolSize];
    individualsArray = new Individual[individuals.size()];
    individualsArray = individuals.toArray(individualsArray);

    //LLeno la ventana:
    for (int j = 0; j < pool.length; j++) {

        selectedIndividual = (int) Math.round(EAFRandom.nextDouble() * maxRandom);
        pool[j] = (Individual) individualsArray[selectedIndividual].clone();

    }

    return Collections.min(Arrays.asList(pool), algorithm.getComparator());

}

From source file:org.n52.iceland.coding.encode.ResponseWriterRepository.java

private ResponseWriterKey chooseWriter(Set<Class<?>> compatible, Class<?> clazz) {
    if (compatible.isEmpty()) {
        return null;
    }//from w  ww  .  j  a va2  s. c om
    Comparator<Class<?>> comparator = new ClassSimilarityComparator(clazz);
    return new ResponseWriterKey(Collections.min(compatible, comparator));
}

From source file:org.phenotips.data.similarity.internal.RestrictedFeatureClusterView.java

/**
 * {@inheritDoc} If access is matchable and there is exactly one reference phenotype that is identical to the
 * category (ancestor), report the category as the parent of the ancestor for privacy.
 *
 * @see org.phenotips.data.similarity.internal.DefaultFeatureClusterView#getRoot()
 *///from w  ww.  j av  a  2  s .  c  om
@Override
public VocabularyTerm getRoot() {
    if (this.access.isPrivateAccess()) {
        return null;
    } else if (this.access.isLimitedAccess() && this.ancestor != null && this.reference.size() == 1) {
        String refId = this.reference.iterator().next().getId();
        String ancestorId = this.ancestor.getId();
        // Check if the reference and ancestor terms are the same term
        if (refId != null && StringUtils.equals(refId, ancestorId)) {
            Set<VocabularyTerm> parents = this.ancestor.getParents();
            if (parents.isEmpty()) {
                return null;
            } else if (parents.size() == 1) {
                return parents.iterator().next();
            } else {
                // Get an arbitrary parent in a deterministic manner (lowest ID)
                VocabularyTerm parent = Collections.min(parents, new Comparator<VocabularyTerm>() {
                    @Override
                    public int compare(VocabularyTerm o1, VocabularyTerm o2) {
                        String id1 = o1.getId();
                        String id2 = o2.getId();
                        return id1 == null || id2 == null ? 0 : id1.compareTo(id2);
                    }
                });
                return parent;
            }
        }
    }
    return super.getRoot();
}

From source file:net.sourceforge.fenixedu.domain.accounting.PaymentPlan.java

public Installment getFirstInstallment() {
    return (getInstallmentsSet().size() == 0) ? null
            : Collections.min(getInstallmentsSet(), Installment.COMPARATOR_BY_ORDER);
}

From source file:org.apache.kylin.cube.cuboid.Cuboid.java

static long translateToValidCuboid(CubeDesc cubeDesc, long cuboidID) {
    long baseCuboidId = getBaseCuboidId(cubeDesc);
    if (cubeDesc.getAllCuboids().contains(cuboidID)) {
        return cuboidID;
    }// www  . j av  a  2  s.  c o m
    List<Long> onTreeCandidates = Lists.newArrayList();
    for (AggregationGroup agg : cubeDesc.getAggregationGroups()) {
        Long candidate = translateToOnTreeCuboid(agg, cuboidID);
        if (candidate != null) {
            onTreeCandidates.add(candidate);
        }
    }

    if (onTreeCandidates.size() == 0) {
        return baseCuboidId;
    }

    long onTreeCandi = Collections.min(onTreeCandidates, cuboidSelectComparator);
    if (isValid(cubeDesc, onTreeCandi)) {
        return onTreeCandi;
    }

    return new CuboidScheduler(cubeDesc).getValidParent(onTreeCandi);
}

From source file:org.dragoneronca.nlp.wol.graph_building.FirstSenseGraphBuilder.java

private void linkSenseFromTerms(Sense sense, RangedSenseScanner.AlphabeticRange alphabeticRange,
        RangedSenseIteratorFactory rangedSenseIteratorFactory) {

    TAGGER.tagSenses(Arrays.asList(sense).iterator());

    for (TaggedTerm taggedTerm : sense.getTaggedGloss()) {

        if (!alphabeticRange.isInRange(taggedTerm.getLemma())) {
            continue;
        }//from   ww  w  . ja v a  2s. co m

        Set<Sense> targetSenses = getTargetSenses(sense, Language.EN, taggedTerm.getPOS(),
                taggedTerm.getLemma(), rangedSenseIteratorFactory);

        if (targetSenses.isEmpty()) {
            return;
        }

        Sense firstSense = Collections.min(targetSenses, new Comparator<Sense>() {
            @Override
            public int compare(Sense sense1, Sense sense2) {
                return Integer.compare(sense1.getNumber(), sense2.getNumber());
            }
        });

        TermSemanticEdge semanticEdge = new TermSemanticEdge(firstSense, MAX_PROBABILITY, taggedTerm);
        semanticEdge.setOriginSense(sense);
        Set<SemanticEdge> outEdges = sense.getOutEdges();
        if (outEdges == null) {
            outEdges = new HashSet<>();
            sense.setOutEdges(outEdges);
        }
        outEdges.add(semanticEdge);
        entityManager.persist(semanticEdge);
    }
}

From source file:org.openlmis.core.model.StockCard.java

public Date getEarliestLotExpiryDate() {
    List<LotOnHand> lotOnHandList = FluentIterable.from(getLotOnHandListWrapper())
            .filter(new Predicate<LotOnHand>() {
                @Override//from   w w  w. j a v  a 2s.  c o m
                public boolean apply(LotOnHand lotOnHand) {
                    return lotOnHand.getQuantityOnHand() > 0;
                }
            }).toList();
    if (lotOnHandList.isEmpty()) {
        return null;
    }
    return Collections.min(lotOnHandList, new Comparator<LotOnHand>() {
        @Override
        public int compare(LotOnHand lhs, LotOnHand rhs) {
            return lhs.getLot().getExpirationDate().compareTo(rhs.getLot().getExpirationDate());
        }
    }).getLot().getExpirationDate();
}

From source file:org.apache.drill.exec.server.rest.profile.OperatorWrapper.java

public void addSummary(TableBuilder tb) {

    String path = new OperatorPathBuilder().setMajor(major).setOperator(firstProfile).build();
    tb.appendCell(path, null);/*from  w  w w . j  av a 2  s  .c om*/
    tb.appendCell(operatorType == null ? "UNKNOWN_OPERATOR" : operatorType.toString(), null);

    double setupSum = 0.0;
    double processSum = 0.0;
    double waitSum = 0.0;
    double memSum = 0.0;
    for (ImmutablePair<OperatorProfile, Integer> ip : ops) {
        OperatorProfile profile = ip.getLeft();
        setupSum += profile.getSetupNanos();
        processSum += profile.getProcessNanos();
        waitSum += profile.getWaitNanos();
        memSum += profile.getPeakLocalMemoryAllocated();
    }

    final ImmutablePair<OperatorProfile, Integer> shortSetup = Collections.min(ops, Comparators.setupTime);
    final ImmutablePair<OperatorProfile, Integer> longSetup = Collections.max(ops, Comparators.setupTime);
    tb.appendNanos(shortSetup.getLeft().getSetupNanos(), String.format(format, shortSetup.getRight()));
    tb.appendNanos(Math.round(setupSum / size), null);
    tb.appendNanos(longSetup.getLeft().getSetupNanos(), String.format(format, longSetup.getRight()));

    final ImmutablePair<OperatorProfile, Integer> shortProcess = Collections.min(ops, Comparators.processTime);
    final ImmutablePair<OperatorProfile, Integer> longProcess = Collections.max(ops, Comparators.processTime);
    tb.appendNanos(shortProcess.getLeft().getProcessNanos(), String.format(format, shortProcess.getRight()));
    tb.appendNanos(Math.round(processSum / size), null);
    tb.appendNanos(longProcess.getLeft().getProcessNanos(), String.format(format, longProcess.getRight()));

    final ImmutablePair<OperatorProfile, Integer> shortWait = Collections.min(ops, Comparators.waitTime);
    final ImmutablePair<OperatorProfile, Integer> longWait = Collections.max(ops, Comparators.waitTime);
    tb.appendNanos(shortWait.getLeft().getWaitNanos(), String.format(format, shortWait.getRight()));
    tb.appendNanos(Math.round(waitSum / size), null);
    tb.appendNanos(longWait.getLeft().getWaitNanos(), String.format(format, longWait.getRight()));

    final ImmutablePair<OperatorProfile, Integer> peakMem = Collections.max(ops,
            Comparators.operatorPeakMemory);
    tb.appendBytes(Math.round(memSum / size), null);
    tb.appendBytes(peakMem.getLeft().getPeakLocalMemoryAllocated(), null);
}

From source file:pl.mg6.android.maps.extensions.demo.DemoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.demo);/*from   w ww  . j a v  a2s  . co  m*/

    FragmentManager fm = getSupportFragmentManager();
    SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map);
    map = f.getExtendedMap();

    addCircles();

    map.setOnMapClickListener(new OnMapClickListener() {

        @Override
        public void onMapClick(LatLng position) {
            for (Circle circle : map.getCircles()) {
                if (circle.contains(position)) {
                    Toast.makeText(DemoActivity.this, "Clicked " + circle.getData(), Toast.LENGTH_SHORT).show();
                    return;
                }
            }
        }
    });

    map.setClustering(
            new ClusteringSettings().clusterOptionsProvider(new DemoClusterOptionsProvider(getResources()))
                    .addMarkersDynamically(true));

    map.setInfoWindowAdapter(new InfoWindowAdapter() {

        private TextView tv;
        {
            tv = new TextView(DemoActivity.this);
            tv.setTextColor(Color.BLACK);
        }

        private Collator collator = Collator.getInstance();
        private Comparator<Marker> comparator = new Comparator<Marker>() {
            public int compare(Marker lhs, Marker rhs) {
                String leftTitle = lhs.getTitle();
                String rightTitle = rhs.getTitle();
                if (leftTitle == null && rightTitle == null) {
                    return 0;
                }
                if (leftTitle == null) {
                    return 1;
                }
                if (rightTitle == null) {
                    return -1;
                }
                return collator.compare(leftTitle, rightTitle);
            }
        };

        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                int i = 0;
                String text = "";
                while (i < 3 && markers.size() > 0) {
                    Marker m = Collections.min(markers, comparator);
                    String title = m.getTitle();
                    if (title == null) {
                        break;
                    }
                    text += title + "\n";
                    markers.remove(m);
                    i++;
                }
                if (text.length() == 0) {
                    text = "Markers with mutable data";
                } else if (markers.size() > 0) {
                    text += "and " + markers.size() + " more...";
                } else {
                    text = text.substring(0, text.length() - 1);
                }
                tv.setText(text);
                return tv;
            } else {
                Object data = marker.getData();
                if (data instanceof MutableData) {
                    MutableData mutableData = (MutableData) data;
                    tv.setText("Value: " + mutableData.value);
                    return tv;
                }
            }

            return null;
        }
    });

    map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                Builder builder = LatLngBounds.builder();
                for (Marker m : markers) {
                    builder.include(m.getPosition());
                }
                LatLngBounds bounds = builder.build();
                map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds,
                        getResources().getDimensionPixelSize(R.dimen.padding)));
            }
        }
    });

    MarkerGenerator.addMarkersInPoland(map);
    MarkerGenerator.addMarkersInWorld(map);

    BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE);
    for (MutableData data : dataArray) {
        map.addMarker(new MarkerOptions().position(data.position).icon(icon).data(data));
    }

    setUpClusteringViews();
}