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

SizeAreaComparator

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

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

Fields Summary
Constructors Summary
Methods Summary
public intcompare(android.util.Size size, android.util.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.getWidth();
        long width2 = size2.getWidth();
        long area = width * size.getHeight();
        long area2 = width2 * size2.getHeight();

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

        return (area > area2) ? 1 : -1;
    
public static android.util.SizefindLargestByArea(java.util.List sizes)
Get the largest {@code 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());