Picasso's Transformation class to Crop borders from Image
To be fair, I think it is quite readable  and I do not know of a way to really improve it using Java 8 constructs. I have a tip or two anyway:


In the getXNonWhitePosition methods, I'd remove the internal check to assign the first value, assigning it before the loop:

private int getFirstNonWhitePosition(int[] horizontalMiddleArray) {
    if(horizontalMiddleArray.length == 0) {
        return -1;
    }
    int left = horizontalMiddleArray[0];
    for (int i = 1; i &lt; horizontalMiddleArray.length; i++) {
        if (left != horizontalMiddleArray[i]) {
            return i;
        }
    }
    return -1;
}

You could implement the isNegative with a Java 8 stream, e.g.:

private boolean isNegative(final int... values) {
    return IntStream.of(values).allMatch(value -&gt; value &gt; 0);
}

Why do you save mWidth and mHeight in the fields? Because it seems to me like the transformation has nothing to do with it. These values will change after each transformation application. Using them for the toString feels quite odd.


If I would really want to use Java 8 for the getXNonWhitePosition methods, I think something like the following would do:

private int getFirstNonWhitePosition(final int[] horizontalMiddleArray) {
    if(horizontalMiddleArray.length == 0) {
        return -1;
    }
    final int left = horizontalMiddleArray[0];
    return IntStream.range(1, horizontalMiddleArray.length)
            .filter(index -&gt; horizontalMiddleArray[index] != left)
            .findFirst()
            .orElse(-1);
}

private int getLastNonWhitePosition(final int[] horizontalMiddleArray) {
    if(horizontalMiddleArray.length == 0) {
        return -1;
    }
    final int right = horizontalMiddleArray[horizontalMiddleArray.length - 1];
    return IntStream.rangeClosed(2, horizontalMiddleArray.length)
            .map(index -&gt; horizontalMiddleArray.length - index)
            .filter(index -&gt; horizontalMiddleArray[index] != right)
            .findFirst()
            .orElse(-1);
}


This is not tested, though I think it works. But again, I do not think this is much of an improvement. You could technically extract to a function which receives some value to check against, and some kind of indexing stream, but that feels like over engineering to me.