FileDocCategorySizeDatePackage
SizeAreaComparator.javaAPI DocAndroid 5.1 API2253Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.legacy

SizeAreaComparator

public class SizeAreaComparator extends Object implements Comparator
Comparator for api1 {@link Camera.Size} objects by the area.

This comparator totally orders by rectangle area. Tie-breaks on width.

Fields Summary
Constructors Summary
Methods Summary
public intcompare(Camera.Size size, Camera.Size size2)
{@inheritDoc}

        checkNotNull(size, "size must not be null");
        checkNotNull(size2, "size2 must not be null");

        if (size.equals(size2)) {
            return 0;
        }

        long width = size.width;
        long width2 = size2.width;
        long area = width * size.height;
        long area2 = width2 * size2.height;

        if (area == area2) {
            return (width > width2) ? 1 : -1;
        }

        return (area > area2) ? 1 : -1;
    
public static Camera.SizefindLargestByArea(java.util.List sizes)
Get the largest api1 {@code Camera.Size} from the list by comparing each size's area by each other using {@link SizeAreaComparator}.

param
sizes a non-{@code null} list of non-{@code null} sizes
return
a non-{@code null} size
throws
NullPointerException if {@code sizes} or any elements in it were {@code null}

        checkNotNull(sizes, "sizes must not be null");

        return Collections.max(sizes, new SizeAreaComparator());