List of usage examples for java.util Collections min
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp)
From source file:wisc.drivesense.vediorecorder.CameraFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio/*from w w w . j a va2 s .c o m*/ * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<Size>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); //Log.d(TAG, option.toString()); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
From source file:com.tenth.space.ui.fragment.HomeFragment.java
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); // Collect the supported resolutions that are smaller than the preview Surface List<Size> notBigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight && option.getHeight() == option.getWidth() * h / w) { if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) { bigEnough.add(option);/*from w ww. jav a 2 s . co m*/ } else { notBigEnough.add(option); } } } if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else if (notBigEnough.size() > 0) { return Collections.max(notBigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio/* w ww.j av a 2 s.co m*/ * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(final Size[] choices, final int width, final int height, final Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<Size>(); final int w = aspectRatio.getWidth(); final int h = aspectRatio.getHeight(); for (Size option : choices) { final int optionHeight = option.getHeight(); final int optionWidth = option.getWidth(); if (optionHeight == optionWidth * h / w && optionWidth >= width && optionHeight >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(LOGTAG, "Couldn't find any suitable preview size"); return choices[0]; } }
From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio/* w w w .jav a 2s. c o m*/ * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ @SuppressLint("LongLogTag") @DebugLog private static Size chooseOptimalSize(final Size[] choices, final int width, final int height, final Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface final List<Size> bigEnough = new ArrayList<Size>(); for (final Size option : choices) { if (option.getHeight() >= MINIMUM_PREVIEW_SIZE && option.getWidth() >= MINIMUM_PREVIEW_SIZE) { Timber.tag(TAG).i("Adding size: " + option.getWidth() + "x" + option.getHeight()); bigEnough.add(option); } else { Timber.tag(TAG).i("Not adding size: " + option.getWidth() + "x" + option.getHeight()); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { final Size chosenSize = Collections.min(bigEnough, new CompareSizesByArea()); Timber.tag(TAG).i("Chosen size: " + chosenSize.getWidth() + "x" + chosenSize.getHeight()); return chosenSize; } else { Timber.tag(TAG).e("Couldn't find any suitable preview size"); return choices[0]; } }
From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio/* w w w. j ava 2 s .co m*/ * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<Size>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }
From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio// w ww . j a v a 2 s. c om * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new Camera2Fragment.CompareSizesByArea()); } else { Timber.e("Couldn't find any suitable preview size"); return choices[0]; } }
From source file:com.github.rvesse.github.pr.stats.PullRequestStats.java
public void run() throws IOException { if (help.showHelpIfRequested()) { CliCommandUsageGenerator generator = new CliCommandUsageGenerator(); generator.usage(null, null, "pr-stats", this.metadata, this.parserConfig, System.out); return;//from w ww.j a v a2 s .c om } GitHubClient client = new GitHubClient(); prepareCredentials(client); client.setUserAgent("GitHub PR Stats Bot/0.1.0 (+http://github.com/rvesse/gh-pr-stats.git)"); // Get the user just to force us to make one request so we can get stats // about the remaining requests @SuppressWarnings("unused") User user = new UserService(client).getUser(); System.out.println("You have " + client.getRemainingRequests() + " GitHub API requests of " + client.getRequestLimit() + " remaining"); long start = client.getRemainingRequests(); // Collect statistics for the pull requests PullRequestService prService = new PullRequestService(client); RepositoryId repoId = prepareRepositoryId(); List<PullRequest> prs = prService.getPullRequests(repoId, "all"); PullRequestsCollector collector = new PullRequestsCollector( this.userSummary || this.userDetailedStats || this.all, this.mergeSummary || this.mergeDetailedStats || this.all); collector.start(); for (PullRequest pr : prs) { System.out.println("Processing PR #" + pr.getNumber()); collector.collect(client, pr); } collector.end(); // Inform the user about how many API requests were used System.out.println(); System.out.println("You have " + client.getRemainingRequests() + " GitHub API requests of " + client.getRequestLimit() + " remaining"); System.out.println( "Generating statistics used " + (start - client.getRemainingRequests()) + " GitHub API requests"); System.out.println(); // Output Stats // Basic stats outputBasicStatus(collector); System.out.println(); // Age Stats outputAgeStats(collector.getDaysToMergeStats(), "Days to Merge", true); System.out.println(); outputAgeStats(collector.getDaysOpenStats(), "Days Open", true); System.out.println(); outputAgeStats(collector.getDaysToCloseStats(), "Days to Close", true); System.out.println(); // User Stats List<UserCollector> userStats = collector.getUserStats(); UserComparator<UserCollector> userComparator = new UserComparator<UserCollector>(); if (this.userSummary || this.all) { System.out.println("Total Users: " + userStats.size()); if (userStats.size() > 0) { UserCollector maxUser = Collections.max(userStats, userComparator); List<UserCollector> maxUsers = findEquivalent(userStats, maxUser, userComparator); UserCollector minUser = Collections.min(userStats, userComparator); List<UserCollector> minUsers = findEquivalent(userStats, minUser, userComparator); System.out.println("Max Pull Requests by User: " + maxUser.getTotal() + " " + maxUsers); System.out.println("Min Pull Requests by User: " + minUser.getTotal() + " " + minUsers); System.out.println("Average Pull Requests per User: " + (collector.getTotal() / userStats.size())); } System.out.println(); } if (userStats.size() > 0 && (this.userDetailedStats || this.all)) { Collections.sort(userStats, userComparator); for (AbstractUserPullRequestCollector userCollector : userStats) { outputUserStats(userCollector); System.out.println(); } } // Merging User Stats List<MergingUserCollector> mergingUserStats = collector.getMergingUserStats(); UserComparator<MergingUserCollector> mergeUserComparator = new UserComparator<MergingUserCollector>(); if (this.mergeSummary || this.all) { System.out.println("Total Merging Users: " + mergingUserStats.size()); if (mergingUserStats.size() > 0) { MergingUserCollector maxUser = Collections.max(mergingUserStats, mergeUserComparator); List<MergingUserCollector> maxUsers = findEquivalent(mergingUserStats, maxUser, mergeUserComparator); MergingUserCollector minUser = Collections.min(mergingUserStats, mergeUserComparator); List<MergingUserCollector> minUsers = findEquivalent(mergingUserStats, minUser, mergeUserComparator); System.out.println("Max Pull Requests Merged by User: " + maxUser.getMerged() + " " + maxUsers); System.out.println("Min Pull Requests Merged by User: " + minUser.getMerged() + " " + minUsers); System.out.println("Average Pull Requests Merged per User: " + (collector.getMerged() / mergingUserStats.size())); } System.out.println(); } if (mergingUserStats.size() > 0 && (this.mergeDetailedStats || this.all)) { Collections.sort(mergingUserStats, mergeUserComparator); for (MergingUserCollector userCollector : mergingUserStats) { outputUserStats(userCollector); System.out.println(); } } }
From source file:org.libreplan.web.planner.order.OrderPlanningModel.java
public static ZoomLevel calculateDefaultLevel(PlannerConfiguration<TaskElement> configuration) { if (configuration.getData().isEmpty()) { return ZoomLevel.DETAIL_ONE; }/*from www . jav a 2s. com*/ TaskElement earliest = Collections.min(configuration.getData(), TaskElement.getByStartDateComparator()); TaskElement latest = Collections.max(configuration.getData(), TaskElement.getByEndAndDeadlineDateComparator()); LocalDate startDate = earliest.getStartAsLocalDate(); LocalDate endDate = latest.getBiggestAmongEndOrDeadline(); return ZoomLevel.getDefaultZoomByDates(startDate, endDate); }
From source file:br.upe.ecomp.doss.algorithm.apso.APSO.java
protected void doElitistLearningStrategy() { RandomData random = new RandomDataImpl(); APSOParticle[] particles = (APSOParticle[]) getParticles(); List<APSOParticle> apsoParticles = Arrays.asList(particles); APSOParticle bestParticle = Collections.max(apsoParticles, new ComparatorMaximumFitness()); // Dimension that can be changed if the best particle fitness improves after the change int dimensionChange = random.nextInt(0, getProblem().getDimensionsNumber() - 1); double[] currentBestPosition = bestParticle.getBestPosition(); // Standard Deviation of the Gaussian Distribution // TODO usar esse decaimento linear pode ser ruim para ambientes dinamicos double learningElitistRate = sigmaMax - (sigmaMax - sigmaMin) * (this.getIterations() / getMaxIterations()); // Changes position in only one dimension // if(EnumEvolutionaryState.CONVERGENCE) TODO testar com e sem esta condicao double newDimensionPosition = currentBestPosition[dimensionChange] + (getProblem().getUpperBound(dimensionChange) - getProblem().getLowerBound(dimensionChange)) * random.nextGaussian(0, learningElitistRate); // TODO verificar se nao extrapolou o limite do espaco de busca double[] newPosition = currentBestPosition.clone(); newPosition[dimensionChange] = newDimensionPosition; double currentBestFitness = bestParticle.getBestFitness(); double newFitness = getProblem().getFitness(newPosition); // If the change improves the fitness then update the best particle with the new position, // else update the worst particle with the new position. if (getProblem().isFitnessBetterThan(currentBestFitness, newFitness)) { bestParticle.updateBestPosition(newPosition.clone(), newFitness); bestParticle.updateCurrentPosition(newPosition.clone(), newFitness); } else {//from www. j av a 2 s. c o m PSOParticle worstParticle = Collections.min(apsoParticles, new ComparatorMaximumFitness()); worstParticle.updateCurrentPosition(newPosition.clone(), newFitness); worstParticle.updatePBest(getProblem()); } calculateGBest(bestParticle); }
From source file:kr.ac.kpu.wheeling.blackbox.Camera2VideoFragment.java
/** * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose * width and height are at least as large as the respective requested values, and whose aspect * ratio matches with the specified value. * * @param choices The list of sizes that the camera supports for the intended output class * @param width The minimum desired width * @param height The minimum desired height * @param aspectRatio The aspect ratio// w w w .j a va 2s.c om * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) { // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<Size>(); int w = aspectRatio.getWidth(); int h = aspectRatio.getHeight(); Log.d("INFO", "w, h: " + w + h); for (Size option : choices) { Log.d("SIZE", "option Width= " + option.getWidth() + " option Height= " + option.getHeight()); if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= w && option.getHeight() >= h) { Log.d("SELECTED SIZE", "option Width= " + option.getWidth() + " option Height= " + option.getHeight()); bigEnough.add(option); } } // Pick the smallest of those, assuming we found any if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizesByArea()); } else { Log.e(TAG, "Couldn't find any suitable preview size"); return choices[0]; } }