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:org.libreplan.web.planner.order.OrderPlanningModel.java
public static ZoomLevel calculateDefaultLevel(PlannerConfiguration<TaskElement> configuration) { if (configuration.getData().isEmpty()) { return ZoomLevel.DETAIL_ONE; }//from w w w .j a va2s . 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:de.bund.bfr.knime.pmmlite.core.PmmUtils.java
public static <T> T getMaxCounted(Collection<T> values) { return Collections.max(LinkedHashMultiset.create(values).entrySet(), (o1, o2) -> Integer.compare(o1.getCount(), o2.getCount())).getElement(); }
From source file:net.sourceforge.fenixedu.domain.accounting.Receipt.java
private Integer generateReceiptNumber(int year) { final List<Receipt> receipts = getReceiptsFor(year); return receipts.isEmpty() ? 1 : Collections.max(receipts, Receipt.COMPARATOR_BY_NUMBER).getReceiptNumber() + 1; }
From source file:com.jaspersoft.jasperserver.remote.services.impl.PermissionsServiceImpl.java
public ObjectPermission getEffectivePermission(Resource resource, Authentication authentication) { ObjectPermission permission = new ObjectPermissionImpl(); permission.setPermissionRecipient(authentication.getPrincipal()); BasicAclEntry[] effectiveAcls = (BasicAclEntry[]) aclService.getAcls(resource, authentication); if (effectiveAcls != null) { BasicAclEntry entry = Collections.max(Arrays.asList(effectiveAcls), aclCompartor); permission.setPermissionMask(entry.getMask()); permission.setURI(extractUriFromEntry(entry)); } else {//from w ww. ja v a 2s.com permission.setPermissionMask(JasperServerAclEntry.NOTHING); } return permission; }
From source file:com.google.uzaygezen.core.BoundedRollupTest.java
@Test public void subtreeIsOptimalWithinConstraints() { final List<int[]> list = Lists.newArrayList(); IntArrayCallback callback = new ListCollector(list); for (int n = 0; n < 3; ++n) { list.clear();// w w w. j a v a2 s .com // Exact sum means that no array will be a prefix of another one. TestUtils.generateSpecWithExactSum(n, 2 * n, callback); Collections.sort(list, IntArrayComparator.INSTANCE); BoundedRollup<Integer, LongContent> rollup = BoundedRollup.create(TestUtils.ZERO_LONG_CONTENT, Integer.MAX_VALUE); MapNode<Integer, LongContent> fullTreeRoot = createTree(list, rollup); checkTreeIsComplete(list, n, fullTreeRoot); int fullTreeSize = fullTreeRoot.subtreeSizeAndLeafCount()[0]; for (int i = 1; i <= fullTreeSize + 5; ++i) { List<List<MapNode<Integer, LongContent>>> allPossibleExpansions = allPossibleExpansions( fullTreeRoot, i); BoundedRollup<Integer, LongContent> constrainedRollup = BoundedRollup .create(TestUtils.ZERO_LONG_CONTENT, i); MapNode<Integer, LongContent> constrainedTreeRoot = createTree(list, constrainedRollup); List<MapNode<Integer, LongContent>> actual = constrainedTreeRoot.preorder(); List<List<MapNode<Integer, LongContent>>> all = toSortedValueListList(allPossibleExpansions); List<MapNode<Integer, LongContent>> constrained = toSortedValueList(actual); List<List<MapNode<Integer, LongContent>>> allSameSize = Lists.newArrayList(); for (List<MapNode<Integer, LongContent>> row : all) { Assert.assertTrue(row.size() <= constrained.size()); if (row.size() == constrained.size()) { allSameSize.add(row); } } Assert.assertEquals(Collections.max(allSameSize, new ListComparator<MapNode<Integer, LongContent>>( new MapNodeValueComparator<Integer, LongContent>())), constrained); } } }
From source file:org.apache.storm.scheduler.utils.ArtifactoryConfigLoader.java
private String loadMostRecentArtifact(String location, String host, Integer port) { // Is this a directory or is it a file? JSONObject json = getArtifactMetadata(location, host, port); if (json == null) { LOG.error("got null metadata"); return null; }/* w w w . j av a 2 s. com*/ String downloadURI = (String) json.get("downloadUri"); // This means we are pointing at a file. if (downloadURI != null) { // Then get it and return the file as string. String returnValue = doGet(null, location, host, port); saveInArtifactoryCache(returnValue); return returnValue; } // This should mean that we were pointed at a directory. // Find the most recent child and load that. JSONArray msg = (JSONArray) json.get("children"); if (msg == null || msg.size() == 0) { LOG.error("Expected directory children not present"); return null; } JSONObject newest = (JSONObject) Collections.max(msg, new DirEntryCompare()); if (newest == null) { LOG.error("Failed to find most recent artifact uri in {}", location); return null; } String uri = (String) newest.get("uri"); if (uri == null) { LOG.error("Expected directory uri not present"); return null; } String returnValue = doGet(null, location + uri, host, port); saveInArtifactoryCache(returnValue); return returnValue; }
From source file:com.example.camera2apidemo.Camera2Fragment.java
private String setUpCameraOutputs(int width, int height) { Activity activity = getActivity();//from www .ja v a 2 s . co m CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // ??? We don't use a front facing camera in this sample. Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } // ?? ?? StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; return cameraId; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. // ErrorDialog.newInstance(getString(R.string.camera_error)) // .show(getChildFragmentManager(), FRAGMENT_DIALOG); } return null; }
From source file:norbert.mynemo.core.selection.RecommenderSelector.java
/** * Removes from the given collection all evaluations that are significantly worst. The left * evaluations are non significantly different. *///from w w w .ja v a 2 s.co m private void retainBestEvaluations(Collection<RecommenderEvaluation> evaluations) { checkNotNull(evaluations); EvaluationComparator comparator = new EvaluationComparator(metric); Collection<RecommenderEvaluation> rejectedEvaluations = new ArrayList<>(); for (RecommenderEvaluation evalA : evaluations) { for (RecommenderEvaluation evalB : evaluations) { if (areSignificantlyDifferent(evalA, evalB)) { rejectedEvaluations.add(Collections.max(newArrayList(evalA, evalB), comparator)); } } } evaluations.removeAll(rejectedEvaluations); }
From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *//*from w w w . ja v a 2 s. c om*/ private void setUpCameraOutputs(int width, int height) { if (isViewAvailable()) { CameraManager manager = (CameraManager) activityView.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); // We don't use a front facing camera in this sample. Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } imageDimension = map.getOutputSizes(SurfaceTexture.class)[0]; // For still image captures, we use the largest available size. Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); Point displaySize = new Point(); activityView.getWindowManager().getDefaultDisplay().getSize(displaySize); int rotatedPreviewWidth = width; int rotatedPreviewHeight = height; int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; if (maxPreviewWidth > MAX_PREVIEW_WIDTH) { maxPreviewWidth = MAX_PREVIEW_WIDTH; } if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) { maxPreviewHeight = MAX_PREVIEW_HEIGHT; } // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = activityView.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activityView.getTextureView().setAspectRatio(previewSize.getWidth(), previewSize.getHeight()); } else { activityView.getTextureView().setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); } return; } } catch (CameraAccessException e) { e.printStackTrace(); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. } } }
From source file:org.libreplan.business.planner.entities.allocationalgorithms.UntilFillingHoursAllocator.java
private EffortDuration getMaxAssignment(List<? extends DayAssignment> newAssignments) { if (newAssignments.isEmpty()) { return zero(); }/* ww w . ja v a2 s .c om*/ DayAssignment max = Collections.max(newAssignments, DayAssignment.byDurationComparator()); return max.getDuration(); }