Example usage for java.util Collections max

List of usage examples for java.util Collections max

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:com.visualnavigate.CameraFragment.java

/**
 * 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/*from   www . j  a v  a2  s  .c  o m*/
 * @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) {

    // 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);
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the largest 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.max(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");
        //httpHelper.logRequest("error", "Couldn't find any suitable preview size", this.getActivity());
        return choices[0];
    }
}

From source file:net.sourceforge.fenixedu.domain.student.Student.java

public Registration getLastConcludedRegistration() {
    List<Registration> concludedRegistrations = getConcludedRegistrations();
    return concludedRegistrations.isEmpty() ? null
            : (Registration) Collections.max(concludedRegistrations, Registration.COMPARATOR_BY_START_DATE);
}

From source file:com.example.android.tflitecamerademo.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   www  .  j a v  a  2 s  .  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;
            }

            // // For still image captures, we use the largest available size.
            Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new CompareSizesByArea());
            imageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                    /*maxImages*/ 2);

            // 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 */
            int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (sensorOrientation == 90 || sensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (sensorOrientation == 0 || sensorOrientation == 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;
            }

            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 = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight());
            } else {
                textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
            }

            this.cameraId = cameraId;
            return;
        }
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to access Camera", e);
    } 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:fr.xebia.magritte.classifier.lite.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 www .  j  a  v a 2s  .c om*/
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());
            imageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                    /*maxImages*/ 2);

            // 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 */
            int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            boolean swappedDimensions = false;
            switch (displayRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                if (sensorOrientation == 90 || sensorOrientation == 270) {
                    swappedDimensions = true;
                }
                break;
            case Surface.ROTATION_90:
            case Surface.ROTATION_270:
                if (sensorOrientation == 0 || sensorOrientation == 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;
            }

            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 = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight());
            } else {
                textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
            }

            this.cameraId = 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:net.sourceforge.fenixedu.domain.student.Student.java

public Registration getLastRegistration() {
    Collection<Registration> activeRegistrations = getRegistrationsSet();
    return activeRegistrations.isEmpty() ? null
            : (Registration) Collections.max(activeRegistrations, Registration.COMPARATOR_BY_START_DATE);
}

From source file:com.manufacton.cordova.MyCameraManager.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
 */// ww  w .  j  a  va2 s. co m
private void setUpCameraOutputs(int width, int height) {
    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());

            // 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
            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.
            int cameraLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
            if (cameraLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY
                    && android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.LOLLIPOP) {
                Log.d(TAG, "LEGACY CAMERA DETECTED & OLD OS DETECTED");
                Size[] sizes = map.getOutputSizes(SurfaceTexture.class);
                for (Size option : sizes) {
                    Log.d(TAG, "available : WIDTH: " + option.getWidth() + " HEIGHT: " + option.getHeight());
                }
                mImageReader = ImageReader.newInstance(640, 480, ImageFormat.JPEG, 2);
            } else {
                Log.d(TAG, "LEGACY CAMERA NOT DETECTED");
                mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedPreviewWidth,
                        rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, largest);
                mImageReader = ImageReader.newInstance(mPreviewSize.getWidth(), mPreviewSize.getHeight(),
                        ImageFormat.JPEG, 2);
                Log.d(TAG, "For mPreviewSize: WIDTH: " + mPreviewSize.getWidth() + " HEIGHT: "
                        + mPreviewSize.getHeight());
            }

            mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

            // 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) {
        e.printStackTrace();
    }
}

From source file:com.tzutalin.dlibtest.CameraConnectionFragment.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
 *//* ww  w  . ja va  2 s.  co  m*/
@DebugLog
@SuppressLint("LongLogTag")
private void setUpCameraOutputs(final int width, final int height) {
    final Activity activity = getActivity();
    final CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
    try {
        SparseArray<Integer> cameraFaceTypeMap = new SparseArray<>();
        // Check the facing types of camera devices
        for (final String cameraId : manager.getCameraIdList()) {
            final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                if (cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) != null) {
                    cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_FRONT,
                            cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) + 1);
                } else {
                    cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_FRONT, 1);
                }
            }

            if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) {
                if (cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) != null) {
                    cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_BACK,
                            cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_BACK) + 1);
                } else {
                    cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_BACK, 1);
                }
            }
        }

        Integer num_facing_back_camera = cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_BACK);
        for (final String cameraId : manager.getCameraIdList()) {
            final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
            final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            // If facing back camera or facing external camera exist, we won't use facing front camera
            if (num_facing_back_camera != null && num_facing_back_camera > 0) {
                // We don't use a front facing camera in this sample if there are other camera device facing types
                if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
                    continue;
                }
            }

            final StreamConfigurationMap map = characteristics
                    .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

            if (map == null) {
                continue;
            }

            // For still image captures, we use the largest available size.
            final Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.YUV_420_888)),
                    new CompareSizesByArea());

            // 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), width, height, largest);

            // We fit the aspect ratio of TextureView to the size of preview we picked.
            final int orientation = getResources().getConfiguration().orientation;
            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight());
            } else {
                textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
            }

            CameraConnectionFragment.this.cameraId = cameraId;
            return;
        }
    } catch (final CameraAccessException e) {
        Timber.tag(TAG).e("Exception!", e);
    } catch (final 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:net.sourceforge.fenixedu.domain.student.Student.java

public Registration getLastRegistrationForDegreeType(final DegreeType degreeType) {
    Collection<Registration> registrations = getRegistrationsByDegreeType(degreeType);
    return registrations.isEmpty() ? null
            : (Registration) Collections.max(registrations, new BeanComparator("startDate"));
}

From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.SantanderBatchFillerWorker.java

private Degree getDegree(SantanderBatch batch, Person person) {
    final Student student = person.getStudent();
    if (student == null) {
        return null;
    }/*w ww  .  j a  va2 s.com*/

    final DateTime begin = batch.getExecutionYear().getBeginDateYearMonthDay().toDateTimeAtMidnight();
    final DateTime end = batch.getExecutionYear().getEndDateYearMonthDay().toDateTimeAtMidnight();
    final Set<StudentCurricularPlan> studentCurricularPlans = new HashSet<StudentCurricularPlan>();
    StudentCurricularPlan pickedSCP;

    for (final Registration registration : student.getRegistrationsSet()) {
        if (!registration.isActive()) {
            continue;
        }
        if (registration.getDegree().isEmpty()) {
            continue;
        }
        final RegistrationProtocol registrationAgreement = registration.getRegistrationProtocol();
        if (!registrationAgreement.allowsIDCard()) {
            continue;
        }
        final DegreeType degreeType = registration.getDegreeType();
        if (!degreeType.isBolonhaType()) {
            continue;
        }
        for (final StudentCurricularPlan studentCurricularPlan : registration.getStudentCurricularPlansSet()) {
            if (studentCurricularPlan.isActive()) {
                if (degreeType == DegreeType.BOLONHA_DEGREE || degreeType == DegreeType.BOLONHA_MASTER_DEGREE
                        || degreeType == DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE
                        || degreeType == DegreeType.BOLONHA_ADVANCED_SPECIALIZATION_DIPLOMA) {
                    studentCurricularPlans.add(studentCurricularPlan);
                } else {
                    final RegistrationState registrationState = registration.getActiveState();
                    if (registrationState != null) {
                        final DateTime dateTime = registrationState.getStateDate();
                        if (!dateTime.isBefore(begin) && !dateTime.isAfter(end)) {
                            studentCurricularPlans.add(studentCurricularPlan);
                        }
                    }
                }
            }
        }
    }
    if (studentCurricularPlans.isEmpty()) {
        return null;
    }
    pickedSCP = Collections.max(studentCurricularPlans, new Comparator<StudentCurricularPlan>() {

        @Override
        public int compare(final StudentCurricularPlan o1, final StudentCurricularPlan o2) {
            final DegreeType degreeType1 = o1.getDegreeType();
            final DegreeType degreeType2 = o2.getDegreeType();
            if (degreeType1 == degreeType2) {
                final YearMonthDay yearMonthDay1 = o1.getStartDateYearMonthDay();
                final YearMonthDay yearMonthDay2 = o2.getStartDateYearMonthDay();
                final int c = yearMonthDay1.compareTo(yearMonthDay2);
                return c == 0 ? o1.getExternalId().compareTo(o2.getExternalId()) : c;
            } else {
                return degreeType1.compareTo(degreeType2);
            }
        }

    });
    return pickedSCP.getRegistration().getDegree();
    //        final String degreeNameForIdCard = degree.getIdCardName();
    //        if (degreeNameForIdCard == null || degreeNameForIdCard.isEmpty()) {
    //            throw new Error("No degree name for id card specified.");
    //        }
    //        if (degreeNameForIdCard.length() > 50) {
    //            throw new Error("Length of degree name for id card to long: " + degreeNameForIdCard + " has more than 50 characters.");
    //        }
    //        return degreeNameForIdCard;
    //return pickedSCP.getRegistration().getDegree().getSigla();
}

From source file:edu.harvard.med.screensaver.model.screenresults.ScreenResult.java

/**
 * Get the number of replicates (assay plates) associated with this screen result. If the
 * replicate count was not explicitly specified at instantiation time, calculate the replicate
 * count by finding the maximum replicate ordinal value from the screen result's
 * data columns; if none of the data columns have their replicate
 * ordinal values defined, replicate count is 1.
 *
 * @return the number of replicates (assay plates) associated with this
 *         <code>ScreenResult</code>
 *///w w w  . ja  va 2 s.c o m
@Column(nullable = false)
public Integer getReplicateCount() {
    if (_replicateCount == null) {
        if (getDataColumns().size() == 0) {
            _replicateCount = 0;
        } else {
            DataColumn maxOrdinalCol = Collections.max(getDataColumns(), new Comparator<DataColumn>() {
                public int compare(DataColumn col1, DataColumn col2) {
                    if (col1.getReplicateOrdinal() == null && col2.getReplicateOrdinal() == null) {
                        return 0;
                    }
                    if (col1.getReplicateOrdinal() == null && col2.getReplicateOrdinal() != null) {
                        return -1;
                    }
                    if (col1.getReplicateOrdinal() != null && col2.getReplicateOrdinal() == null) {
                        return 1;
                    }
                    return col1.getReplicateOrdinal().compareTo(col2.getReplicateOrdinal());
                }
            });
            _replicateCount = maxOrdinalCol.getReplicateOrdinal();
            if (_replicateCount == null) {
                // every DataColumn had null replicateOrdinal value
                _replicateCount = 1;
            }
        }
    }
    return _replicateCount;
}