mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
- CheckStyle.
This commit is contained in:
@@ -13,47 +13,47 @@ import com.google.common.base.Function;
|
||||
*/
|
||||
public class Aggregates {
|
||||
|
||||
// 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) {
|
||||
if (source == null) { return null; }
|
||||
// Returns the value matching predicate conditions with the maximum value of whatever valueAccessor returns.
|
||||
public static final <T> Integer max(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (final T c : source) {
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value > max ) {
|
||||
if (value > max) {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public final static <T> Integer min(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
|
||||
public static final <T> Integer min(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MAX_VALUE;
|
||||
for (final T c : source) {
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value < max ) {
|
||||
if (value < max) {
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
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;
|
||||
T result = null;
|
||||
for (final T c : source) {
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value > max ) {
|
||||
if (value > max) {
|
||||
max = value;
|
||||
result = c;
|
||||
}
|
||||
}
|
||||
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;
|
||||
if (source != null) {
|
||||
for (final T c : source) {
|
||||
@@ -72,7 +72,7 @@ public class Aggregates {
|
||||
* the source
|
||||
* @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;
|
||||
T candidate = null;
|
||||
for (final T item : source) {
|
||||
@@ -85,7 +85,7 @@ public class Aggregates {
|
||||
|
||||
// Get several random values
|
||||
// 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>();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
final T toAdd = Aggregates.random(source);
|
||||
@@ -96,7 +96,7 @@ public class Aggregates {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
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>();
|
||||
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) {
|
||||
if (source == null) { return null; }
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MAX_VALUE;
|
||||
T result = null;
|
||||
for (final T c : source) {
|
||||
int value = valueAccessor.apply(c);
|
||||
if ( value < max ) {
|
||||
if (value < max) {
|
||||
max = value;
|
||||
result = c;
|
||||
}
|
||||
@@ -122,17 +122,21 @@ public class Aggregates {
|
||||
|
||||
|
||||
public static <TItem, TField> TItem firstFieldEquals(List<TItem> source, Function<TItem, TField> valueAccessor, TField valueEquals) {
|
||||
if (source == null) { return null; }
|
||||
if( valueEquals == null ) {
|
||||
for (final TItem c : source)
|
||||
if ( null == valueAccessor.apply(c) )
|
||||
if (source == null) { return null; }
|
||||
if (valueEquals == null) {
|
||||
for (final TItem c : source) {
|
||||
if (null == valueAccessor.apply(c)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final TItem c : source)
|
||||
if ( valueEquals.equals(valueAccessor.apply(c)) )
|
||||
for (final TItem c : source) {
|
||||
if (valueEquals.equals(valueAccessor.apply(c))) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class BinaryUtil {
|
||||
}
|
||||
return c;
|
||||
} // bit count
|
||||
|
||||
|
||||
public static int bitCount(final byte num) {
|
||||
byte v = num;
|
||||
int c = 0;
|
||||
@@ -23,7 +23,7 @@ public class BinaryUtil {
|
||||
}
|
||||
return c;
|
||||
} // bit count
|
||||
|
||||
|
||||
public static int bitCount(final short num) {
|
||||
short v = num;
|
||||
int c = 0;
|
||||
@@ -31,5 +31,5 @@ public class BinaryUtil {
|
||||
v &= v - 1;
|
||||
}
|
||||
return c;
|
||||
} // bit count
|
||||
} // bit count
|
||||
}
|
||||
|
||||
@@ -83,38 +83,38 @@ public abstract class PredicateString<T> implements Predicate<T> {
|
||||
public StringOp getOperator() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
public static PredicateString<String> contains(final String what) {
|
||||
|
||||
public static PredicateString<String> contains(final String what) {
|
||||
return new PredicateString<String>(StringOp.CONTAINS) {
|
||||
@Override
|
||||
public boolean apply(String subject) {
|
||||
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) {
|
||||
@Override
|
||||
public boolean apply(String subject) {
|
||||
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) {
|
||||
@Override
|
||||
public boolean apply(String subject) {
|
||||
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) {
|
||||
@Override
|
||||
public boolean apply(String subject) {
|
||||
return op(subject, what);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -111,8 +111,8 @@ import java.util.Set;
|
||||
* @author Clemens Koza
|
||||
* @version V0.0 19.08.2009
|
||||
* @see Properties
|
||||
*/
|
||||
public class TreeProperties /* implements Iterable<PropertyElement> */{
|
||||
*/
|
||||
public class TreeProperties /* implements Iterable<PropertyElement> */ {
|
||||
/** Constant <code>suffixes</code>. */
|
||||
private static final Map<String, PropertyType<?>> SUFFIXES;
|
||||
/** Constant <code>types</code>. */
|
||||
@@ -451,8 +451,8 @@ public class TreeProperties /* implements Iterable<PropertyElement> */{
|
||||
* @return a T object.
|
||||
*/
|
||||
T toObject(TreeProperties p, String s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class FileType implements PropertyType<File> {
|
||||
/** Constant <code>suffix="file"</code>. */
|
||||
public static final String SUFFIX = "file";
|
||||
|
||||
@@ -129,8 +129,8 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
return allLands;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private final CardStackRow collectAllTokens() {
|
||||
final CardStackRow allTokens = new CardStackRow();
|
||||
outerLoop:
|
||||
@@ -179,7 +179,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
return allTokens;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final CardPanel addCard(final Card card) {
|
||||
final CardPanel placeholder = new CardPanel(card);
|
||||
@@ -254,13 +254,13 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
this.revalidate();
|
||||
positionAllCards();
|
||||
}
|
||||
|
||||
private void positionAllCards()
|
||||
{
|
||||
|
||||
private void positionAllCards() {
|
||||
|
||||
// Position all card panels.
|
||||
int x = 0;
|
||||
int y = PlayArea.GUTTER_Y;
|
||||
|
||||
|
||||
for (final CardStackRow row : this.rows) {
|
||||
int rowBottom = 0;
|
||||
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);
|
||||
|
||||
int afterFirstRow;
|
||||
|
||||
|
||||
if (this.mirror) {
|
||||
// Wrap all creatures and lands.
|
||||
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.
|
||||
return creatures.isEmpty() && tokens.isEmpty() && lands.isEmpty() && others.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* wrap.
|
||||
|
||||
Reference in New Issue
Block a user