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:nu.yona.server.device.rest.DeviceController.java
private void logLongAppActivityBatch(MessageType messageType, UUID userId, AppActivitiesDto appActivities) { int numAppActivities = appActivities.getActivities().length; List<Activity> appActivityCollection = Arrays.asList(appActivities.getActivities()); Comparator<? super Activity> comparator = (a, b) -> a.getStartTime().compareTo(b.getStartTime()); ZonedDateTime minStartTime = Collections.min(appActivityCollection, comparator).getStartTime(); ZonedDateTime maxStartTime = Collections.max(appActivityCollection, comparator).getStartTime(); switch (messageType) { case ERROR://from w w w . jav a 2 s . c o m logger.error( "User with ID {} posts too many ({}) app activities, with start dates ranging from {} to {} (device time: {}). App activities ignored.", userId, numAppActivities, minStartTime, maxStartTime, appActivities.getDeviceDateTime()); break; case WARNING: logger.warn( "User with ID {} posts many ({}) app activities, with start dates ranging from {} to {} (device time: {})", userId, numAppActivities, minStartTime, maxStartTime, appActivities.getDeviceDateTime()); break; default: throw new IllegalStateException("Unsupported message type: " + messageType); } }
From source file:net.sourceforge.fenixedu.domain.CompetenceCourse.java
private CompetenceCourseInformation getOldestCompetenceCourseInformation() { final Set<CompetenceCourseInformation> competenceCourseInformations = getCompetenceCourseInformationsSet(); if (competenceCourseInformations.isEmpty()) { return null; }/*from ww w . j av a2s . c o m*/ return Collections.min(competenceCourseInformations, CompetenceCourseInformation.COMPARATORY_BY_EXECUTION_PERIOD); }
From source file:org.psikeds.resolutionengine.datalayer.knowledgebase.util.FeatureValueHelper.java
public static FeatureValue min(final Collection<? extends FeatureValue> randomList) { return ((randomList == null) || randomList.isEmpty() ? null : Collections.min(randomList, COMPARATOR)); }
From source file:net.sourceforge.fenixedu.domain.serviceRequests.AcademicServiceRequest.java
final public AcademicServiceRequestSituation getActiveSituation() { return !getAcademicServiceRequestSituationsSet().isEmpty() ? Collections.min(getAcademicServiceRequestSituationsSet(), AcademicServiceRequestSituation.COMPARATOR_BY_MOST_RECENT_SITUATION_DATE_AND_ID) : null;/*from ww w . j av a 2 s. c o m*/ }
From source file:org.libreplan.web.limitingresources.QueuesState.java
private static LimitingResourceQueueElement earliest(List<LimitingResourceQueueElement> list) { Validate.isTrue(!list.isEmpty());//from w w w . java 2 s .c o m return Collections.min(list, LimitingResourceQueueElement.byStartTimeComparator()); }
From source file:org.squashtest.tm.service.internal.repository.hibernate.TestCaseDaoImpl.java
private Date getMinDate(TestCase tc) { return Collections.min(tc.getMilestones(), new Comparator<Milestone>() { @Override/*from w w w.ja v a2s .c o m*/ public int compare(Milestone m1, Milestone m2) { return m1.getEndDate().before(m2.getEndDate()) ? -1 : 1; } }).getEndDate(); }
From source file:com.google.android.apps.watchme.StreamerActivity.java
private static Size chooseOptimalSize(Size[] choices, int width, int height) { List<Size> bigEnough = new ArrayList<Size>(); for (Size option : choices) { if (option.getHeight() == option.getWidth() * height / width && option.getWidth() >= width && option.getHeight() >= height) { bigEnough.add(option);//from w w w.ja va2 s . c om } } if (bigEnough.size() > 0) { return Collections.min(bigEnough, new CompareSizeByArea()); } else { return choices[0]; } }
From source file:com.example.janicduplessis.myapplication.CameraFragment.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 *///w ww . j a v a 2 s .c o m private void setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); 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()); Size smalest = Collections.min(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); //mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2); mImageReader = ImageReader.newInstance(smalest.getWidth(), smalest.getHeight(), ImageFormat.JPEG, 2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // 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. mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } mCameraId = cameraId; 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. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }
From source file:com.movie.mood.Camera2BasicFragment.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 2s . co m*/ private void setUpCameraOutputs(int width, int height) { Activity activity = getActivity(); 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; } int imageFormat = ImageFormat.JPEG; // For still image captures, we use the smallest available size. Size smallest = Collections.min(Arrays.asList(map.getOutputSizes(imageFormat)), new CompareSizesByArea()); mImageReader = ImageReader.newInstance(smallest.getWidth(), smallest.getHeight(), imageFormat, /*maxImages*/2); mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler); // Find out if we need to swap dimension to get the preview size relative to sensor // coordinate. int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); //noinspection ConstantConditions /* Orientation of the camera sensor */ final int mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); boolean swappedDimensions = false; switch (displayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: if (mSensorOrientation == 90 || mSensorOrientation == 270) { swappedDimensions = true; } break; case Surface.ROTATION_90: case Surface.ROTATION_270: if (mSensorOrientation == 0 || mSensorOrientation == 180) { swappedDimensions = true; } break; default: Log.e(TAG, "Display rotation is invalid: " + displayRotation); } Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); int rotatedPreviewWidth = width; int rotatedPreviewHeight = height; int maxPreviewWidth = displaySize.x; int maxPreviewHeight = displaySize.y; if (swappedDimensions) { rotatedPreviewWidth = height; rotatedPreviewHeight = width; maxPreviewWidth = displaySize.y; maxPreviewHeight = displaySize.x; } 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. mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, smallest); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { mTextureView.setAspectRatio(mPreviewSize.getWidth(), mPreviewSize.getHeight()); } else { mTextureView.setAspectRatio(mPreviewSize.getHeight(), mPreviewSize.getWidth()); } // Check if the flash is supported. Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); mFlashSupported = available == null ? false : available; mCameraId = cameraId; 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. ErrorDialog.newInstance("camera error!!").show(getChildFragmentManager(), FRAGMENT_DIALOG); e.printStackTrace(); } }
From source file:com.example.camera2apidemo.Camera2BasicFragment.java
/** * ?/* w w w .j av a2s . c o m*/ * @param choices ?list * @param textureViewWidth texture view * @param textureViewHeight texture view * @param maxWidth * @param maxHeight * @param aspectRatio ?(pictureSize, ?pictureSizetextureSize??, ??) * @return ? * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that * is at least as large as the respective texture view size, and that is at most as large as the * respective max size, and whose aspect ratio matches with the specified value. If such size * doesn't exist, choose the largest one that is at most as large as the respective max size, * 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 textureViewWidth The width of the texture view relative to sensor coordinate * @param textureViewHeight The height of the texture view relative to sensor coordinate * @param maxWidth The maximum width that can be chosen * @param maxHeight The maximum height that can be chosen * @param aspectRatio The aspect ratio * @return The optimal {@code Size}, or an arbitrary one if none were big enough */ private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth, int maxHeight, Size aspectRatio) { // ??, textureSize // Collect the supported resolutions that are at least as big as the preview Surface List<Size> bigEnough = new ArrayList<>(); // ??, ?textureSize // 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); } else { notBigEnough.add(option); } } } // 1. bigEnough?, ?? // 2. ?bigEnough?, notBigEnough?, ?? // 3. ??, , ? // Pick the smallest of those big enough. If there is no one big enough, pick the // largest of those not big enough. 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]; } }