improved readability

master
melvin 2011-07-04 12:49:51 +08:00
parent d843aa2adf
commit f10550078d
2 changed files with 8 additions and 14 deletions

View File

@ -57,7 +57,7 @@ public class MagicDeclareBlockersChoice extends MagicChoice {
blocker.setBlockedCreature(null); blocker.setBlockedCreature(null);
} }
attacker.permanent.removeBlockingCreatures(); attacker.permanent.removeBlockingCreatures();
result.add(creatures.toArray(new MagicCombatCreature[creatures.size()])); result.add(creatures.toArray(new MagicCombatCreature[0]));
} }
} }
} }

View File

@ -9,12 +9,10 @@ import java.util.TreeSet;
public class MagicMultipleScoreRanking implements MagicScoreRanking { public class MagicMultipleScoreRanking implements MagicScoreRanking {
private static final Comparator<MagicScoreResult> BEST_COMPARATOR=new Comparator<MagicScoreResult>() { private static final Comparator<MagicScoreResult> BEST_COMPARATOR=new Comparator<MagicScoreResult>() {
@Override @Override
public int compare(final MagicScoreResult result1,final MagicScoreResult result2) { public int compare(final MagicScoreResult result1,final MagicScoreResult result2) {
final int sdif=result2.getScore()-result1.getScore(); final int sdif=result2.getScore()-result1.getScore();
if (sdif!=0) { if (sdif != 0) {
return sdif; return sdif;
} }
return result1.getPosition()-result2.getPosition(); return result1.getPosition()-result2.getPosition();
@ -22,12 +20,10 @@ public class MagicMultipleScoreRanking implements MagicScoreRanking {
}; };
private static final Comparator<MagicScoreResult> WORST_COMPARATOR=new Comparator<MagicScoreResult>() { private static final Comparator<MagicScoreResult> WORST_COMPARATOR=new Comparator<MagicScoreResult>() {
@Override @Override
public int compare(final MagicScoreResult result1,final MagicScoreResult result2) { public int compare(final MagicScoreResult result1,final MagicScoreResult result2) {
final int sdif=result1.getScore()-result2.getScore(); final int sdif=result1.getScore()-result2.getScore();
if (sdif!=0) { if (sdif != 0) {
return sdif; return sdif;
} }
return result1.getPosition()-result2.getPosition(); return result1.getPosition()-result2.getPosition();
@ -40,19 +36,18 @@ public class MagicMultipleScoreRanking implements MagicScoreRanking {
private int worstScore; private int worstScore;
public MagicMultipleScoreRanking(final int maxSize,final boolean best) { public MagicMultipleScoreRanking(final int maxSize,final boolean best) {
this.best=best; this.best=best;
results=new TreeSet<MagicScoreResult>(best?BEST_COMPARATOR:WORST_COMPARATOR); results=new TreeSet<MagicScoreResult>(best ? BEST_COMPARATOR : WORST_COMPARATOR);
left=maxSize; left=maxSize;
} }
public boolean addScore(final int score) { public boolean addScore(final int score) {
return left == 0 ? (best ? score > worstScore
return left==0?(best?score>worstScore:score<worstScore):true; : score < worstScore)
:true;
} }
public void addScoreResult(final MagicScoreResult result) { public void addScoreResult(final MagicScoreResult result) {
results.add(result); results.add(result);
if (left==0) { if (left==0) {
results.remove(results.last()); results.remove(results.last());
@ -64,7 +59,6 @@ public class MagicMultipleScoreRanking implements MagicScoreRanking {
@Override @Override
public Collection<Object> getResults() { public Collection<Object> getResults() {
return new ArrayList<Object>(results); return new ArrayList<Object>(results);
} }
} }