- CheckStyle.

This commit is contained in:
Chris
2012-12-01 22:26:36 +00:00
parent f9848822be
commit 3e2cf5907c
5 changed files with 56 additions and 52 deletions

View File

@@ -13,47 +13,47 @@ import com.google.common.base.Function;
*/ */
public class Aggregates { public class Aggregates {
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns. // Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
public final static <T> Integer max(final Iterable<T> source, final Function<T, Integer> valueAccessor) { public static final <T> Integer max(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; } if (source == null) { return null; }
int max = Integer.MIN_VALUE; int max = Integer.MIN_VALUE;
for (final T c : source) { for (final T c : source) {
int value = valueAccessor.apply(c); int value = valueAccessor.apply(c);
if ( value > max ) { if (value > max) {
max = value; max = value;
} }
} }
return max; return max;
} }
public final static <T> Integer min(final Iterable<T> source, final Function<T, Integer> valueAccessor) { public static final <T> Integer min(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; } if (source == null) { return null; }
int max = Integer.MAX_VALUE; int max = Integer.MAX_VALUE;
for (final T c : source) { for (final T c : source) {
int value = valueAccessor.apply(c); int value = valueAccessor.apply(c);
if ( value < max ) { if (value < max) {
max = value; max = value;
} }
} }
return max; return max;
} }
public final static <T> T itemWithMax(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; } public static final <T> T itemWithMax(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; }
int max = Integer.MIN_VALUE; int max = Integer.MIN_VALUE;
T result = null; T result = null;
for (final T c : source) { for (final T c : source) {
int value = valueAccessor.apply(c); int value = valueAccessor.apply(c);
if ( value > max ) { if (value > max) {
max = value; max = value;
result = c; result = c;
} }
} }
return result; return result;
} }
public final static <T> int sum(final Iterable<T> source, final Function<T, Integer> valueAccessor) { public static final <T> int sum(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
int result = 0; int result = 0;
if (source != null) { if (source != null) {
for (final T c : source) { for (final T c : source) {
@@ -72,7 +72,7 @@ public class Aggregates {
* the source * the source
* @return the t * @return the t
*/ */
public final static <T> T random(final Iterable<T> source) { public static final <T> T random(final Iterable<T> source) {
int n = 0; int n = 0;
T candidate = null; T candidate = null;
for (final T item : source) { for (final T item : source) {
@@ -85,7 +85,7 @@ public class Aggregates {
// Get several random values // Get several random values
// should improve to make 1 pass over source and track N candidates at once // should improve to make 1 pass over source and track N candidates at once
public final static <T> List<T> random(final Iterable<T> source, final int count) { public static final <T> List<T> random(final Iterable<T> source, final int count) {
final List<T> result = new ArrayList<T>(); final List<T> result = new ArrayList<T>();
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
final T toAdd = Aggregates.random(source); final T toAdd = Aggregates.random(source);
@@ -96,7 +96,7 @@ public class Aggregates {
} }
return result; return result;
} }
public static final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Function<U, K> fnUniqueKey) { // this might be exotic public static final <K, U> Iterable<U> uniqueByLast(final Iterable<U> source, final Function<U, K> fnUniqueKey) { // this might be exotic
final Map<K, U> uniques = new Hashtable<K, U>(); final Map<K, U> uniques = new Hashtable<K, U>();
for (final U c : source) { for (final U c : source) {
@@ -107,12 +107,12 @@ public class Aggregates {
public static <T> T itemWithMin(final Iterable<T> source, final Function<T, Integer> valueAccessor) { public static <T> T itemWithMin(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
if (source == null) { return null; } if (source == null) { return null; }
int max = Integer.MAX_VALUE; int max = Integer.MAX_VALUE;
T result = null; T result = null;
for (final T c : source) { for (final T c : source) {
int value = valueAccessor.apply(c); int value = valueAccessor.apply(c);
if ( value < max ) { if (value < max) {
max = value; max = value;
result = c; result = c;
} }
@@ -122,17 +122,21 @@ public class Aggregates {
public static <TItem, TField> TItem firstFieldEquals(List<TItem> source, Function<TItem, TField> valueAccessor, TField valueEquals) { public static <TItem, TField> TItem firstFieldEquals(List<TItem> source, Function<TItem, TField> valueAccessor, TField valueEquals) {
if (source == null) { return null; } if (source == null) { return null; }
if( valueEquals == null ) { if (valueEquals == null) {
for (final TItem c : source) for (final TItem c : source) {
if ( null == valueAccessor.apply(c) ) if (null == valueAccessor.apply(c)) {
return c; return c;
}
}
} else { } else {
for (final TItem c : source) for (final TItem c : source) {
if ( valueEquals.equals(valueAccessor.apply(c)) ) if (valueEquals.equals(valueAccessor.apply(c))) {
return c; return c;
}
}
} }
return null; return null;
} }
} }

View File

@@ -14,7 +14,7 @@ public class BinaryUtil {
} }
return c; return c;
} // bit count } // bit count
public static int bitCount(final byte num) { public static int bitCount(final byte num) {
byte v = num; byte v = num;
int c = 0; int c = 0;
@@ -23,7 +23,7 @@ public class BinaryUtil {
} }
return c; return c;
} // bit count } // bit count
public static int bitCount(final short num) { public static int bitCount(final short num) {
short v = num; short v = num;
int c = 0; int c = 0;
@@ -31,5 +31,5 @@ public class BinaryUtil {
v &= v - 1; v &= v - 1;
} }
return c; return c;
} // bit count } // bit count
} }

View File

@@ -83,38 +83,38 @@ public abstract class PredicateString<T> implements Predicate<T> {
public StringOp getOperator() { public StringOp getOperator() {
return operator; return operator;
} }
public static PredicateString<String> contains(final String what) { public static PredicateString<String> contains(final String what) {
return new PredicateString<String>(StringOp.CONTAINS) { return new PredicateString<String>(StringOp.CONTAINS) {
@Override @Override
public boolean apply(String subject) { public boolean apply(String subject) {
return op(subject, what); return op(subject, what);
} }
}; };
} }
public static PredicateString<String> containsIgnoreCase(final String what) { public static PredicateString<String> containsIgnoreCase(final String what) {
return new PredicateString<String>(StringOp.CONTAINS_IC) { return new PredicateString<String>(StringOp.CONTAINS_IC) {
@Override @Override
public boolean apply(String subject) { public boolean apply(String subject) {
return op(subject, what); return op(subject, what);
} }
}; };
} }
public static PredicateString<String> equals(final String what) { public static PredicateString<String> equals(final String what) {
return new PredicateString<String>(StringOp.EQUALS) { return new PredicateString<String>(StringOp.EQUALS) {
@Override @Override
public boolean apply(String subject) { public boolean apply(String subject) {
return op(subject, what); return op(subject, what);
} }
}; };
} }
public static PredicateString<String> equalsIgnoreCase(final String what) { public static PredicateString<String> equalsIgnoreCase(final String what) {
return new PredicateString<String>(StringOp.EQUALS_IC) { return new PredicateString<String>(StringOp.EQUALS_IC) {
@Override @Override
public boolean apply(String subject) { public boolean apply(String subject) {
return op(subject, what); return op(subject, what);
} }
}; };
} }
} }

View File

@@ -111,8 +111,8 @@ import java.util.Set;
* @author Clemens Koza * @author Clemens Koza
* @version V0.0 19.08.2009 * @version V0.0 19.08.2009
* @see Properties * @see Properties
*/ */
public class TreeProperties /* implements Iterable<PropertyElement> */{ public class TreeProperties /* implements Iterable<PropertyElement> */ {
/** Constant <code>suffixes</code>. */ /** Constant <code>suffixes</code>. */
private static final Map<String, PropertyType<?>> SUFFIXES; private static final Map<String, PropertyType<?>> SUFFIXES;
/** Constant <code>types</code>. */ /** Constant <code>types</code>. */
@@ -451,8 +451,8 @@ public class TreeProperties /* implements Iterable<PropertyElement> */{
* @return a T object. * @return a T object.
*/ */
T toObject(TreeProperties p, String s); T toObject(TreeProperties p, String s);
} }
public static class FileType implements PropertyType<File> { public static class FileType implements PropertyType<File> {
/** Constant <code>suffix="file"</code>. */ /** Constant <code>suffix="file"</code>. */
public static final String SUFFIX = "file"; public static final String SUFFIX = "file";

View File

@@ -129,8 +129,8 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
} }
return allLands; return allLands;
} }
private final CardStackRow collectAllTokens() { private final CardStackRow collectAllTokens() {
final CardStackRow allTokens = new CardStackRow(); final CardStackRow allTokens = new CardStackRow();
outerLoop: outerLoop:
@@ -179,7 +179,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
} }
return allTokens; return allTokens;
} }
@Override @Override
public final CardPanel addCard(final Card card) { public final CardPanel addCard(final Card card) {
final CardPanel placeholder = new CardPanel(card); final CardPanel placeholder = new CardPanel(card);
@@ -254,13 +254,13 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
this.revalidate(); this.revalidate();
positionAllCards(); positionAllCards();
} }
private void positionAllCards() private void positionAllCards() {
{
// Position all card panels. // Position all card panels.
int x = 0; int x = 0;
int y = PlayArea.GUTTER_Y; int y = PlayArea.GUTTER_Y;
for (final CardStackRow row : this.rows) { for (final CardStackRow row : this.rows) {
int rowBottom = 0; int rowBottom = 0;
x = PlayArea.GUTTER_X; x = PlayArea.GUTTER_X;
@@ -298,7 +298,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
this.stackSpacingY = Math.round(this.cardHeight * PlayArea.STACK_SPACING_Y); this.stackSpacingY = Math.round(this.cardHeight * PlayArea.STACK_SPACING_Y);
int afterFirstRow; int afterFirstRow;
if (this.mirror) { if (this.mirror) {
// Wrap all creatures and lands. // Wrap all creatures and lands.
this.wrap(lands, this.rows, -1); this.wrap(lands, this.rows, -1);
@@ -342,7 +342,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
// If that still doesn't fit, scale down. // If that still doesn't fit, scale down.
return creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty(); return creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty();
} }
/** /**
* <p> * <p>
* wrap. * wrap.