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:com.hro.museapp.map.ClusteringMapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cluster_map);

    listType = getIntent().getIntExtra("type", TYPE_ALL);

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    FragmentManager fm = getSupportFragmentManager();
    SupportMapFragment f = (SupportMapFragment) fm.findFragmentById(R.id.map);
    map = f.getExtendedMap();/*from w w w. j  a va  2 s. c om*/

    gps = new GPSTracker(ClusteringMapActivity.this);
    //gps = PlacesLoader.getGPS();

    // mapView = (MapView) this.findViewById(R.id.map);

    float cameraZoom = 8;
    LatLng cameraLatLng = new LatLng(52.281602, 5.503235);
    if (savedInstanceState != null) {
        double savedLat = savedInstanceState.getDouble("lat");
        double savedLng = savedInstanceState.getDouble("lng");
        cameraLatLng = new LatLng(savedLat, savedLng);

        cameraZoom = savedInstanceState.getFloat("zoom", 12);
    }
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, cameraZoom));

    map.setClustering(new ClusteringSettings().iconDataProvider(new DemoIconProvider(getResources()))
            .addMarkersDynamically(true));
    map.setMyLocationEnabled(true);

    map.setInfoWindowAdapter(new InfoWindowAdapter() {

        private TextView tv;
        {
            tv = new TextView(ClusteringMapActivity.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 {
                String title = marker.getTitle();
                tv.setText(title);
                return tv;
            }
        }
    });

    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)));
            } else {
                // String title = marker.getTitle();
                // String mid = MarkerGenerator.mapPlaceToId.get(title);
                String mid = (String) marker.getData();

                Intent in = new Intent(getApplicationContext(), ShowPlaceActivity.class);
                // sending mid to next activity
                in.putExtra(MarkerGenerator.TAG_MID, mid);

                // starting new activity and expecting some response back
                startActivityForResult(in, 100);
            }
        }
    });

    // MarkerGenerator.addMarkers(map);
    new AddMarkersInBackground().execute();

}

From source file:br.upe.ecomp.doss.algorithm.apso.APSO.java

private double calculateEvolutionaryFactor() {
    double evolFactor;
    APSOParticle[] particles = (APSOParticle[]) getParticles();
    List<APSOParticle> parciclesList = Arrays.asList(particles);
    APSOParticle particleAux = Collections.min(parciclesList, new ComparatorMeanDistance());
    double dmin = particleAux.getMeanDistanceToOthersParticles();
    particleAux = Collections.max(parciclesList, new ComparatorMeanDistance());
    double dmax = particleAux.getMeanDistanceToOthersParticles();
    particleAux = Collections.max(parciclesList, new ComparatorMaximumFitness());
    double dg = particleAux.getMeanDistanceToOthersParticles();

    evolFactor = (dg - dmin) / (dmax - dmin);

    return evolFactor;
}

From source file:org.webrtc.CameraEnumerationAndroid.java

public static int[] getFramerateRange(android.hardware.Camera.Parameters parameters, final int framerate) {
    List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange();
    if (listFpsRange.isEmpty()) {
        Logging.w(TAG, "No supported preview fps range");
        return new int[] { 0, 0 };
    }/*from   ww w.  jav  a2s .com*/
    return Collections.min(listFpsRange, new ClosestComparator<int[]>() {
        @Override
        int diff(int[] range) {
            final int maxFpsWeight = 10;
            return range[android.hardware.Camera.Parameters.PREVIEW_FPS_MIN_INDEX] + maxFpsWeight
                    * abs(framerate - range[android.hardware.Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
        }
    });
}

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  w  w w.j  a v  a  2 s .co 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: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:org.webrtc.CameraEnumerationAndroid.java

public static android.hardware.Camera.Size getClosestSupportedSize(
        List<android.hardware.Camera.Size> supportedSizes, final int requestedWidth,
        final int requestedHeight) {
    return Collections.min(supportedSizes, new ClosestComparator<android.hardware.Camera.Size>() {
        @Override/*from  www  .  java2s  .  c  o  m*/
        int diff(android.hardware.Camera.Size size) {
            return abs(requestedWidth - size.width) + abs(requestedHeight - size.height);
        }
    });
}

From source file:com.palantir.paxos.PaxosStateLogImpl.java

public long getExtremeLogEntry(Extreme extreme) {
    lock.lock();//  w ww  .  j  av a  2 s  .c o 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:org.apache.kylin.cube.cuboid.Cuboid.java

private static Long translateToOnTreeCuboid(AggregationGroup agg, long cuboidID) {
    if ((cuboidID & ~agg.getPartialCubeFullMask()) > 0) {
        //the partial cube might not contain all required dims
        return null;
    }/*from  w  w  w  .j  av a 2 s  .c o  m*/

    // add mandantory
    cuboidID = cuboidID | agg.getMandatoryColumnMask();

    // add hierarchy
    for (HierarchyMask hierarchyMask : agg.getHierarchyMasks()) {
        long fullMask = hierarchyMask.fullMask;
        long intersect = cuboidID & fullMask;
        if (intersect != 0 && intersect != fullMask) {

            boolean startToFill = false;
            for (int i = hierarchyMask.dims.length - 1; i >= 0; i--) {
                if (startToFill) {
                    cuboidID |= hierarchyMask.dims[i];
                } else {
                    if ((cuboidID & hierarchyMask.dims[i]) != 0) {
                        startToFill = true;
                        cuboidID |= hierarchyMask.dims[i];
                    }
                }
            }
        }
    }

    // add joint dims
    for (Long joint : agg.getJoints()) {
        if (((cuboidID | joint) != cuboidID) && ((cuboidID & ~joint) != cuboidID)) {
            cuboidID = cuboidID | joint;
        }
    }

    if (!agg.isOnTree(cuboidID)) {
        // no column, add one column
        long nonJointDims = removeBits((agg.getPartialCubeFullMask() ^ agg.getMandatoryColumnMask()),
                agg.getJoints());
        if (nonJointDims != 0) {
            long nonJointNonHierarchy = removeBits(nonJointDims,
                    Collections2.transform(agg.getHierarchyMasks(), new Function<HierarchyMask, Long>() {
                        @Override
                        public Long apply(HierarchyMask input) {
                            return input.fullMask;
                        }
                    }));
            if (nonJointNonHierarchy != 0) {
                //there exists dim that does not belong to any joint or any hierarchy, that's perfect
                return cuboidID | Long.lowestOneBit(nonJointNonHierarchy);
            } else {
                //choose from a hierarchy that does not intersect with any joint dim, only check level 1 
                long allJointDims = agg.getJointDimsMask();
                for (HierarchyMask hierarchyMask : agg.getHierarchyMasks()) {
                    long dim = hierarchyMask.allMasks[0];
                    if ((dim & allJointDims) == 0) {
                        return cuboidID | dim;
                    }
                }
            }
        }

        cuboidID = cuboidID | Collections.min(agg.getJoints(), cuboidSelectComparator);
        Preconditions.checkState(agg.isOnTree(cuboidID));
    }
    return cuboidID;
}

From source file:net.sourceforge.fenixedu.domain.ExecutionYear.java

public ExecutionSemester getFirstExecutionPeriod() {
    return Collections.min(this.getExecutionPeriodsSet(), ExecutionSemester.COMPARATOR_BY_SEMESTER_AND_YEAR);
}

From source file:simon.databasedemo.DemoFragment.java

@Override
protected void setUpMap() {
    //addCircles();

    map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        ArrayList<LatLng> markerPoints = new ArrayList<LatLng>();

        // Initializing
        Marker markero;// w ww. j a  v a  2 s  .c  o  m
        Marker markerd;

        @Override
        public void onMapClick(LatLng point) {
            // Already two locations
            if (markerPoints.size() > 1) {

                markerPoints.clear();
                map.clear();
                Calendar c = Calendar.getInstance();
                int day;
                day = c.get(Calendar.DAY_OF_MONTH);
                MarkerGenerator.setUpMap(map, day, month);
            }

            // Adding new item to the ArrayList
            markerPoints.add(point);

            // Creating MarkerOptions
            MarkerOptions options = new MarkerOptions();

            // Setting the position of the marker
            options.position(point);

            //???

            if (markerPoints.size() == 1) {
                options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); //?
                //markero = map.addMarker(options);
            } else if (markerPoints.size() == 2) {
                options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); //?
                //markerd = map.addMarker(options);
            }

            // Add new marker to the Google Map Android API V2
            map.addMarker(options);

            // Checks, whether start and end locations are captured
            if (markerPoints.size() >= 2) {
                LatLng origin = markerPoints.get(0);
                LatLng dest = markerPoints.get(1);

                // Getting URL to the Google Directions API
                String url = getDirectionsUrl(origin, dest);

                DownloadTask downloadTask = new DownloadTask();
                downloadTask.execute(url);
                //                    Uri gmmIntentUri = Uri.parse("geo:" + origin + "?q=" + dest);
                //                    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                //                    mapIntent.setPackage("com.google.android.apps.maps");
                //                    startActivity(mapIntent);
            }

        }
    });

    updateClustering(clusterSizeSeekbar.getProgress(), clusterCheckbox.isChecked());

    map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        private TextView tv;

        {
            tv = new TextView(getActivity());
            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 {
                if (marker.getData() instanceof MutableData) {
                    MutableData mutableData = marker.getData();
                    tv.setText("Value: " + mutableData.value);
                    return tv;
                }
            }

            return null;
        }
    });

    map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            if (marker.isCluster()) {
                List<Marker> markers = marker.getMarkers();
                LatLngBounds.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)));
            }
        }
    });
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(23.6440, 120.9337), 7));
    Calendar c = Calendar.getInstance();
    int day;
    day = c.get(Calendar.DAY_OF_MONTH);
    MarkerGenerator.setUpMap(map, day, month);
    BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE);
    //        for (MutableData data : dataArray) {
    //            map.addMarker(new MarkerOptions().position(data.position).icon(icon).data(data));
    //        }
}