Use lambda expressions in CollisionMatrix.

This commit is contained in:
Major-
2015-03-02 07:27:05 +00:00
parent 2d7a3033c2
commit caf4cc6d96
@@ -15,6 +15,16 @@ import com.google.common.base.Preconditions;
*/ */
public final class CollisionMatrix { public final class CollisionMatrix {
/**
* Indicates that all types of traversal are allowed.
*/
private static final byte ALL_ALLOWED = 0b0000_0000;
/**
* Indicates that no types of traversal are allowed.
*/
private static final byte ALL_BLOCKED = (byte) 0b1111_1111;
/** /**
* Creates an array of CollisionMatrix objects, all of the specified width and length. * Creates an array of CollisionMatrix objects, all of the specified width and length.
* *
@@ -29,16 +39,6 @@ public final class CollisionMatrix {
return matrices; return matrices;
} }
/**
* Indicates that all types of traversal are allowed.
*/
private static final byte ALL_ALLOWED = 0b0000_0000;
/**
* Indicates that no types of traversal are allowed.
*/
private static final byte ALL_BLOCKED = (byte) 0b1111_1111;
/** /**
* The length of the matrix. * The length of the matrix.
*/ */
@@ -76,13 +76,7 @@ public final class CollisionMatrix {
* @return {@code true} if all of the CollisionFlags are set, otherwise {@code false}. * @return {@code true} if all of the CollisionFlags are set, otherwise {@code false}.
*/ */
public boolean all(int x, int y, CollisionFlag... flags) { public boolean all(int x, int y, CollisionFlag... flags) {
for (CollisionFlag flag : flags) { return Arrays.stream(flags).allMatch(flag -> (get(x, y) & flag.asByte()) != 0);
if ((get(x, y) & flag.asByte()) == 0) {
return false;
}
}
return true;
} }
/** /**
@@ -95,13 +89,7 @@ public final class CollisionMatrix {
* @return {@code true} if any of the CollisionFlags are set, otherwise {@code false}. * @return {@code true} if any of the CollisionFlags are set, otherwise {@code false}.
*/ */
public boolean any(int x, int y, CollisionFlag... flags) { public boolean any(int x, int y, CollisionFlag... flags) {
for (CollisionFlag flag : flags) { return Arrays.stream(flags).anyMatch(flag -> (get(x, y) & flag.asByte()) != 0);
if ((get(x, y) & flag.asByte()) != 0) {
return true;
}
}
return false;
} }
/** /**