- Reduce CheckStyle, FindBugs, and PMD output for recently changed files.

This commit is contained in:
Braids
2011-08-19 03:48:50 +00:00
parent fdb1199223
commit 664a535a47
5 changed files with 572 additions and 495 deletions

View File

@@ -37,31 +37,39 @@ import forge.view.FView;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class CardReader implements Runnable, NewConstants { public class CardReader
implements Runnable, // NOPMD by Braids on 8/18/11 10:55 PM
NewConstants
{
private static final String CARD_FILE_DOT_EXTENSION = ".txt"; // NOPMD by Braids on 8/18/11 11:04 PM
/** Default charset when loading from files. */ /** Default charset when loading from files. */
public static final String DEFAULT_CHARSET_NAME = "US-ASCII"; public static final String DEFAULT_CHARSET_NAME = "US-ASCII"; // NOPMD by Braids on 8/18/11 10:54 PM
/** Regex that matches a single hyphen (-) or space. */ /** Regex that matches a single hyphen (-) or space. */
public static final Pattern HYPHEN_OR_SPACE = Pattern.compile("[ -]"); public static final Pattern HYPHEN_OR_SPACE = Pattern.compile("[ -]");
/** Regex for punctuation that we omit from card file names. */ /** Regex for punctuation that we omit from card file names. */
public static final Pattern PUNCTUATION_TO_ZAP = Pattern.compile("[,'\"]"); public static final Pattern PUNCTUATION_TO_ZAP = Pattern.compile("[,'\"]"); // NOPMD by Braids on 8/18/11 10:54 PM
/** Regex that matches two or more underscores (_). */ /** Regex that matches two or more underscores (_). */
public static final Pattern MULTIPLE_UNDERSCORES = Pattern.compile("__+"); public static final Pattern MULTIPLE_UNDERSCORES = Pattern.compile("__+"); // NOPMD by Braids on 8/18/11 10:54 PM
/** Special value for estimatedFilesRemaining. */ /** Special value for estimatedFilesRemaining. */
protected static final int UNKNOWN_NUMBER_OF_FILES_REMAINING = -1; protected static final int UNKNOWN_NUMBER_OF_FILES_REMAINING = -1; // NOPMD by Braids on 8/18/11 10:54 PM
private Map<String, Card> mapToFill; private transient Map<String, Card> mapToFill;
private File cardsfolder; private transient File cardsfolder;
private ZipFile zip; private transient ZipFile zip;
private Charset charset; private transient Charset charset;
private Enumeration<? extends ZipEntry> zipEnum; private transient Enumeration<? extends ZipEntry> zipEnum;
private long estimatedFilesRemaining = UNKNOWN_NUMBER_OF_FILES_REMAINING;
private Iterable<File> findNonDirsIterable; private transient long estimatedFilesRemaining = // NOPMD by Braids on 8/18/11 10:56 PM
UNKNOWN_NUMBER_OF_FILES_REMAINING;
private transient Iterable<File> findNonDirsIterable; // NOPMD by Braids on 8/18/11 10:56 PM
@@ -90,17 +98,19 @@ public class CardReader implements Runnable, NewConstants {
*/ */
public CardReader(final File theCardsFolder, final Map<String, Card> theMapToFill, final boolean useZip) { public CardReader(final File theCardsFolder, final Map<String, Card> theMapToFill, final boolean useZip) {
if (theMapToFill == null) { if (theMapToFill == null) {
throw new NullPointerException("theMapToFill must not be null."); throw new NullPointerException("theMapToFill must not be null."); // NOPMD by Braids on 8/18/11 10:53 PM
} }
this.mapToFill = theMapToFill; this.mapToFill = theMapToFill;
if (!theCardsFolder.exists()) { if (!theCardsFolder.exists()) {
throw new RuntimeException("CardReader : constructor error -- file not found -- filename is " throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM
"CardReader : constructor error -- file not found -- filename is "
+ theCardsFolder.getAbsolutePath()); + theCardsFolder.getAbsolutePath());
} }
if (!theCardsFolder.isDirectory()) { if (!theCardsFolder.isDirectory()) {
throw new RuntimeException("CardReader : constructor error -- not a directory -- " throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM
"CardReader : constructor error -- not a directory -- "
+ theCardsFolder.getAbsolutePath()); + theCardsFolder.getAbsolutePath());
} }
@@ -114,7 +124,7 @@ public class CardReader implements Runnable, NewConstants {
try { try {
this.zip = new ZipFile(zipFile); this.zip = new ZipFile(zipFile);
} catch (Exception exn) { } catch (Exception exn) {
System.err.println("Error reading zip file \"" System.err.println("Error reading zip file \"" // NOPMD by Braids on 8/18/11 10:53 PM
+ zipFile.getAbsolutePath() + "\": " + exn + ". " + zipFile.getAbsolutePath() + "\": " + exn + ". "
+ "Defaulting to txt files in \"" + "Defaulting to txt files in \""
+ theCardsFolder.getAbsolutePath() + theCardsFolder.getAbsolutePath()
@@ -186,28 +196,7 @@ public class CardReader implements Runnable, NewConstants {
} }
if (zip != null) { if (zip == null) {
monitor.setTotalUnitsThisPhase(estimatedFilesRemaining);
ZipEntry entry;
// zipEnum was initialized in the constructor.
while (zipEnum.hasMoreElements()) {
entry = (ZipEntry) zipEnum.nextElement();
if (entry.isDirectory() || !entry.getName().endsWith(".txt")) {
monitor.incrementUnitsCompletedThisPhase(1L);
continue;
}
result = loadCard(entry);
monitor.incrementUnitsCompletedThisPhase(1L);
if (cardName != null && cardName.equals(result.getName())) {
break;
}
}
} else {
if (estimatedFilesRemaining == UNKNOWN_NUMBER_OF_FILES_REMAINING) { if (estimatedFilesRemaining == UNKNOWN_NUMBER_OF_FILES_REMAINING) {
final Generator<File> findNonDirsGen = new FindNonDirectoriesSkipDotDirectoriesGenerator(cardsfolder); final Generator<File> findNonDirsGen = new FindNonDirectoriesSkipDotDirectoriesGenerator(cardsfolder);
estimatedFilesRemaining = GeneratorFunctions.estimateSize(findNonDirsGen); estimatedFilesRemaining = GeneratorFunctions.estimateSize(findNonDirsGen);
@@ -217,7 +206,7 @@ public class CardReader implements Runnable, NewConstants {
monitor.setTotalUnitsThisPhase(estimatedFilesRemaining); monitor.setTotalUnitsThisPhase(estimatedFilesRemaining);
for (File cardTxtFile : findNonDirsIterable) { for (File cardTxtFile : findNonDirsIterable) {
if (!cardTxtFile.getName().endsWith(".txt")) { if (!cardTxtFile.getName().endsWith(CARD_FILE_DOT_EXTENSION)) {
monitor.incrementUnitsCompletedThisPhase(1L); monitor.incrementUnitsCompletedThisPhase(1L);
continue; continue;
} }
@@ -231,6 +220,27 @@ public class CardReader implements Runnable, NewConstants {
} //endfor } //endfor
} else {
monitor.setTotalUnitsThisPhase(estimatedFilesRemaining);
ZipEntry entry;
// zipEnum was initialized in the constructor.
while (zipEnum.hasMoreElements()) {
entry = (ZipEntry) zipEnum.nextElement();
if (entry.isDirectory() || !entry.getName().endsWith(CARD_FILE_DOT_EXTENSION)) {
monitor.incrementUnitsCompletedThisPhase(1L);
continue;
}
result = loadCard(entry);
monitor.incrementUnitsCompletedThisPhase(1L);
if (cardName != null && cardName.equals(result.getName())) {
break;
}
}
} //endif } //endif
if (monitor != null) { if (monitor != null) {
@@ -270,7 +280,7 @@ public class CardReader implements Runnable, NewConstants {
return line; return line;
} catch (Exception ex) { } catch (Exception ex) {
ErrorViewer.showError(ex); ErrorViewer.showError(ex);
throw new RuntimeException("CardReader : readLine(Card) error", ex); throw new RuntimeException("CardReader : readLine(Card) error", ex); // NOPMD by Braids on 8/18/11 10:53 PM
} }
} //readLine(BufferedReader) } //readLine(BufferedReader)
@@ -290,76 +300,88 @@ public class CardReader implements Runnable, NewConstants {
inputStreamReader = new InputStreamReader(inputStream, charset); inputStreamReader = new InputStreamReader(inputStream, charset);
reader = new BufferedReader(inputStreamReader); reader = new BufferedReader(inputStreamReader);
String s = readLine(reader); String line = readLine(reader);
while (!"End".equals(s)) { while (!"End".equals(line)) {
if (s.startsWith("#")) { if (line.charAt(0) == '#') { // NOPMD by Braids on 8/18/11 10:59 PM
//no need to do anything, this indicates a comment line //no need to do anything, this indicates a comment line
} else if (s.startsWith("Name:")) { } else if (line.startsWith("Name:")) {
String t = s.substring(5); final String value = line.substring(5);
//System.out.println(s); //System.out.println(s);
if (!mapToFill.containsKey(t)) { if (mapToFill.containsKey(value)) {
card.setName(t);
} else {
break; // this card has already been loaded. break; // this card has already been loaded.
} else {
card.setName(value);
} }
} else if (s.startsWith("ManaCost:")) { } else if (line.startsWith("ManaCost:")) {
String t = s.substring(9); final String value = line.substring(9);
//System.out.println(s); //System.out.println(s);
if (!"no cost".equals(t)) { if (!"no cost".equals(value)) {
card.setManaCost(t); card.setManaCost(value);
} }
} else if (s.startsWith("Types:")) { } else if (line.startsWith("Types:")) {
addTypes(card, s.substring(6)); addTypes(card, line.substring("Types:".length()));
} else if (s.startsWith("Text:")) { } else if (line.startsWith("Text:")) {
String t = s.substring(5); String value = line.substring("Text:".length());
// if (!t.equals("no text")); // if (!t.equals("no text"));
if ("no text".equals(t)) { if ("no text".equals(value)) {
t = ""; value = "";
} }
card.setText(t); card.setText(value);
} else if (s.startsWith("PT:")) { } else if (line.startsWith("PT:")) {
String t = s.substring(3); final String value = line.substring("PT:".length());
String[] pt = t.split("/"); final String[] powTough = value.split("/");
int att = pt[0].contains("*") ? 0 : Integer.parseInt(pt[0]); int att;
int def = pt[1].contains("*") ? 0 : Integer.parseInt(pt[1]); if (powTough[0].contains("*")) {
card.setBaseAttackString(pt[0]); att = 0;
card.setBaseDefenseString(pt[1]); } else {
card.setBaseAttack(att); att = Integer.parseInt(powTough[0]);
card.setBaseDefense(def);
} else if (s.startsWith("Loyalty:")) {
String[] splitStr = s.split(":");
int loyal = Integer.parseInt(splitStr[1]);
card.setBaseLoyalty(loyal);
} else if (s.startsWith("K:")) {
String t = s.substring(2);
card.addIntrinsicKeyword(t);
} else if (s.startsWith("SVar:")) {
String[] t = s.split(":", 3);
card.setSVar(t[1], t[2]);
} else if (s.startsWith("A:")) {
String t = s.substring(2);
card.addIntrinsicAbility(t);
} else if (s.startsWith("T:")) {
String t = s.substring(2);
card.addTrigger(TriggerHandler.parseTrigger(t, card, true));
} else if (s.startsWith("S:")) {
String t = s.substring(2);
card.addStaticAbilityString(t);
} else if (s.startsWith("SetInfo:")) {
String t = s.substring(8);
card.addSet(new SetInfo(t));
} }
s = readLine(reader); int def;
if (powTough[1].contains("*")) {
def = 0;
} else {
def = Integer.parseInt(powTough[1]);
}
card.setBaseAttackString(powTough[0]);
card.setBaseDefenseString(powTough[1]);
card.setBaseAttack(att);
card.setBaseDefense(def);
} else if (line.startsWith("Loyalty:")) {
final String[] splitStr = line.split(":");
final int loyal = Integer.parseInt(splitStr[1]);
card.setBaseLoyalty(loyal);
} else if (line.startsWith("K:")) {
final String value = line.substring(2);
card.addIntrinsicKeyword(value);
} else if (line.startsWith("SVar:")) {
final String[] value = line.split(":", 3);
card.setSVar(value[1], value[2]);
} else if (line.startsWith("A:")) {
final String value = line.substring(2);
card.addIntrinsicAbility(value);
} else if (line.startsWith("T:")) {
final String value = line.substring(2);
card.addTrigger(TriggerHandler.parseTrigger(value, card, true));
} else if (line.startsWith("S:")) {
final String value = line.substring(2);
card.addStaticAbilityString(value);
} else if (line.startsWith("SetInfo:")) {
final String value = line.substring("SetInfo:".length());
card.addSet(new SetInfo(value)); // NOPMD by Braids on 8/18/11 11:08 PM
}
line = readLine(reader);
} // while !End } // while !End
} finally { } finally {
try { try {
reader.close(); reader.close();
} catch (IOException ignored) { } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM
} }
try { try {
inputStreamReader.close(); inputStreamReader.close();
} catch (IOException ignored) { } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM
} }
} }
@@ -392,12 +414,13 @@ public class CardReader implements Runnable, NewConstants {
return loadCard(fileInputStream); return loadCard(fileInputStream);
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
ErrorViewer.showError(ex, "File \"%s\" exception", pathToTxtFile.getAbsolutePath()); ErrorViewer.showError(ex, "File \"%s\" exception", pathToTxtFile.getAbsolutePath());
throw new RuntimeException("CardReader : run error -- file exception -- filename is " throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM
"CardReader : run error -- file exception -- filename is "
+ pathToTxtFile.getPath(), ex); + pathToTxtFile.getPath(), ex);
} finally { } finally {
try { try {
fileInputStream.close(); fileInputStream.close();
} catch (IOException ignored) { } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM
} }
} }
} }
@@ -416,13 +439,13 @@ public class CardReader implements Runnable, NewConstants {
return loadCard(zipInputStream); return loadCard(zipInputStream);
} catch (IOException exn) { } catch (IOException exn) {
throw new RuntimeException(exn); throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11 10:53 PM
} finally { } finally {
try { try {
if (zipInputStream != null) { if (zipInputStream != null) {
zipInputStream.close(); zipInputStream.close();
} }
} catch (IOException ignored) { } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM
} }
} }
} }
@@ -455,14 +478,14 @@ public class CardReader implements Runnable, NewConstants {
baseFileName = PUNCTUATION_TO_ZAP.matcher(baseFileName).replaceAll(""); baseFileName = PUNCTUATION_TO_ZAP.matcher(baseFileName).replaceAll("");
// Place the file within a single-letter subdirectory. // Place the file within a single-letter subdirectory.
StringBuffer buf = new StringBuffer(1 + 1 + baseFileName.length() + ".txt".length()); final StringBuffer buf = new StringBuffer(1 + 1 + baseFileName.length() + CARD_FILE_DOT_EXTENSION.length());
buf.append(Character.toLowerCase(baseFileName.charAt(0))); buf.append(Character.toLowerCase(baseFileName.charAt(0)));
// Zip file is always created with unix-style path names. // Zip file is always created with unix-style path names.
buf.append('/'); buf.append('/');
buf.append(baseFileName.toLowerCase(Locale.ENGLISH)); buf.append(baseFileName.toLowerCase(Locale.ENGLISH));
buf.append(".txt"); buf.append(CARD_FILE_DOT_EXTENSION);
return buf.toString(); return buf.toString();
} }
@@ -474,20 +497,18 @@ public class CardReader implements Runnable, NewConstants {
* *
* @return a new Card instance having that name, or null if not found * @return a new Card instance having that name, or null if not found
*/ */
public final Card findCard(final String canonicalASCIIName) { public final Card findCard(final String canonicalASCIIName) { // NOPMD by Braids on 8/18/11 11:08 PM
UtilFunctions.checkNotNull("canonicalASCIIName", canonicalASCIIName); UtilFunctions.checkNotNull("canonicalASCIIName", canonicalASCIIName);
String cardFilePath = toMostLikelyPath(canonicalASCIIName); final String cardFilePath = toMostLikelyPath(canonicalASCIIName);
Card result = null; Card result = null;
if (zip != null) { if (zip != null) {
ZipEntry entry = zip.getEntry(cardFilePath); final ZipEntry entry = zip.getEntry(cardFilePath);
if (entry != null) { if (entry != null) {
result = loadCard(entry); result = loadCard(entry);
} else {
//System.err.println(":Could not find \"" + cardFilePath + "\" in zip file.");
} }
} }

View File

@@ -1,15 +1,13 @@
package forge.gui; package forge.gui;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JProgressBar; import javax.swing.JProgressBar;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
import forge.Gui_ProgressBarWindow;
import net.slightlymagic.braids.util.UtilFunctions; import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor; import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
import forge.Gui_ProgressBarWindow;
/** /**
* GUI Progress Monitor that displays the ETA (Estimated Time of Arrival or * GUI Progress Monitor that displays the ETA (Estimated Time of Arrival or
@@ -20,20 +18,30 @@ import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
*/ */
public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor { public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
private Gui_ProgressBarWindow dialog; private transient Gui_ProgressBarWindow dialog;
private String title; private transient String title;
/** /**
* Convenience for * Convenience for
* MultiPhaseProgressMonitorWithETA(title, numPhases, totalUnitsFirstPhase, * MultiPhaseProgressMonitorWithETA(title, numPhases, totalUnitsFirstPhase,
* minUIUpdateIntervalSec, null); * minUIUpdateIntervalSec, null).
* *
* @see #MultiPhaseProgressMonitorWithETA(String,int,long,float,float[]) * @see #MultiPhaseProgressMonitorWithETA(String,int,long,float,float[])
*
* @param neoTitle the title to give the dialog box(es)
*
* @param numPhases the total number of phases to expect
*
* @param totalUnitsFirstPhase the total number of units that will be
* processed in the first phase
*
* @param minUIUpdateIntervalSec the approximate interval at which to
* update the dialog box in seconds
*/ */
public MultiPhaseProgressMonitorWithETA(String title, int numPhases, public MultiPhaseProgressMonitorWithETA(final String neoTitle, final int numPhases,
long totalUnitsFirstPhase, float minUIUpdateIntervalSec) final long totalUnitsFirstPhase, final float minUIUpdateIntervalSec) // NOPMD by Braids on 8/18/11 11:16 PM
{ {
this(title, numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, null); this(neoTitle, numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, null);
} }
/** /**
* Create a GUI progress monitor and open its first dialog. * Create a GUI progress monitor and open its first dialog.
@@ -42,7 +50,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
* swing Event Dispatching Thread. The rest of the methods of this class * swing Event Dispatching Thread. The rest of the methods of this class
* are exempt from this requirement. * are exempt from this requirement.
* *
* @param title the title to give the dialog box(es) * @param neoTitle the title to give the dialog box(es)
* *
* @param numPhases the total number of phases to expect * @param numPhases the total number of phases to expect
* *
@@ -56,9 +64,9 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
* *
* @see BaseProgressMonitor#BaseProgressMonitor(int,long,float,float[]) * @see BaseProgressMonitor#BaseProgressMonitor(int,long,float,float[])
*/ */
public MultiPhaseProgressMonitorWithETA(String title, int numPhases, public MultiPhaseProgressMonitorWithETA(final String neoTitle, final int numPhases,
long totalUnitsFirstPhase, float minUIUpdateIntervalSec, final long totalUnitsFirstPhase, final float minUIUpdateIntervalSec, // NOPMD by Braids on 8/18/11 11:16 PM
float[] phaseWeights) final float[] phaseWeights)
{ {
super(numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, super(numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec,
phaseWeights); phaseWeights);
@@ -67,7 +75,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
throw new IllegalStateException("must be called from within an event dispatch thread"); throw new IllegalStateException("must be called from within an event dispatch thread");
} }
this.title = title; this.title = neoTitle;
if (totalUnitsFirstPhase > 0 && dialog == null) { if (totalUnitsFirstPhase > 0 && dialog == null) {
throw new IllegalStateException("dialog is null"); throw new IllegalStateException("dialog is null");
@@ -82,26 +90,26 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
System.out.println("Initializing..."); System.out.println("Initializing..."); // NOPMD by Braids on 8/18/11 11:13 PM
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:16 PM
public void run() { public void run() {
final int totalUnitsFirstPhase = 5000; final int totalUnitsFirstPhase = 5000; // NOPMD by Braids on 8/18/11 11:16 PM
final MultiPhaseProgressMonitorWithETA monitor = final MultiPhaseProgressMonitorWithETA monitor =
new MultiPhaseProgressMonitorWithETA("Testing 2 phases", 2, totalUnitsFirstPhase, 1.0f, new MultiPhaseProgressMonitorWithETA("Testing 2 phases", 2, totalUnitsFirstPhase, 1.0f,
new float[] {2, 1}); new float[] {2, 1});
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() { final SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
@Override @Override
public Object doInBackground() { public Object doInBackground() {
System.out.println("Running..."); System.out.println("Running..."); // NOPMD by Braids on 8/18/11 11:14 PM
for (int i = 0; i <= totalUnitsFirstPhase; i++) { for (int i = 0; i <= totalUnitsFirstPhase; i++) {
monitor.incrementUnitsCompletedThisPhase(1); monitor.incrementUnitsCompletedThisPhase(1);
System.out.print("\ri = " + i); System.out.print("\ri = " + i); // NOPMD by Braids on 8/18/11 11:14 PM
try { try {
Thread.sleep(1); Thread.sleep(1);
@@ -109,15 +117,15 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
// blank // blank
} }
} }
System.out.println(); System.out.println(); // NOPMD by Braids on 8/18/11 11:14 PM
final int totalUnitsSecondPhase = 2000; final int totalUnitsSecondPhase = 2000; // NOPMD by Braids on 8/18/11 11:17 PM
monitor.markCurrentPhaseAsComplete(totalUnitsSecondPhase); monitor.markCurrentPhaseAsComplete(totalUnitsSecondPhase);
for (int i = 0; i <= totalUnitsSecondPhase; i++) { for (int i = 0; i <= totalUnitsSecondPhase; i++) {
monitor.incrementUnitsCompletedThisPhase(1); monitor.incrementUnitsCompletedThisPhase(1);
System.out.print("\ri = " + i); System.out.print("\ri = " + i); // NOPMD by Braids on 8/18/11 11:14 PM
try { try {
Thread.sleep(1); Thread.sleep(1);
@@ -128,8 +136,8 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
monitor.markCurrentPhaseAsComplete(0); monitor.markCurrentPhaseAsComplete(0);
System.out.println(); System.out.println(); // NOPMD by Braids on 8/18/11 11:14 PM
System.out.println("Done!"); System.out.println("Done!"); // NOPMD by Braids on 8/18/11 11:14 PM
return null; return null;
} }
@@ -149,7 +157,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
* *
* @see net.slightlymagic.braids.util.progress_monitor.ProgressMonitor#setTotalUnitsThisPhase(long) * @see net.slightlymagic.braids.util.progress_monitor.ProgressMonitor#setTotalUnitsThisPhase(long)
*/ */
public void setTotalUnitsThisPhase(final long numUnits) { public final void setTotalUnitsThisPhase(final long numUnits) {
super.setTotalUnitsThisPhase(numUnits); super.setTotalUnitsThisPhase(numUnits);
if (numUnits > Integer.MAX_VALUE) { if (numUnits > Integer.MAX_VALUE) {
@@ -158,7 +166,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
if (numUnits > 0) { if (numUnits > 0) {
// dialog must exist before we exit this method. // dialog must exist before we exit this method.
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { // NOPMD by Braids on 8/18/11 11:17 PM
public void run() { public void run() {
// (Re)create the progress bar. // (Re)create the progress bar.
if (dialog != null) { if (dialog != null) {
@@ -171,7 +179,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
}); });
} }
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:18 PM
public void run() { public void run() {
dialog.setTitle(title); dialog.setTitle(title);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
@@ -181,7 +189,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
dialog.setProgressRange(0, (int) numUnits); dialog.setProgressRange(0, (int) numUnits);
dialog.reset(); dialog.reset();
JProgressBar bar = dialog.getProgressBar(); final JProgressBar bar = dialog.getProgressBar();
bar.setString(""); bar.setString("");
bar.setStringPainted(true); bar.setStringPainted(true);
bar.setValue(0); bar.setValue(0);
@@ -194,12 +202,12 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.ProgressMonitor#incrementUnitsCompletedThisPhase(long) * @see net.slightlymagic.braids.util.progress_monitor.ProgressMonitor#incrementUnitsCompletedThisPhase(long)
*/ */
public void incrementUnitsCompletedThisPhase(final long numUnits) { public final void incrementUnitsCompletedThisPhase(final long numUnits) {
super.incrementUnitsCompletedThisPhase(numUnits); super.incrementUnitsCompletedThisPhase(numUnits);
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:18 PM
public void run() { public void run() {
for (int i = 0 ; i < numUnits ; i++) { for (int i = 0; i < numUnits; i++) {
dialog.increment(); dialog.increment();
} }
} }
@@ -209,24 +217,24 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
if ((getNumPhases() > 1)) { if ((getNumPhases() > 1)) {
displayUpdate( displayUpdate(
"Phase " + getCurrentPhase() + ". " + "Phase " + getCurrentPhase() + ". "
//getUnitsCompletedSoFarThisPhase() + " units processed. " + //+ getUnitsCompletedSoFarThisPhase() + " units processed. "
//"Overall: " + getTotalPercentCompleteAsString() + "% complete, " + //+ "Overall: " + getTotalPercentCompleteAsString() + "% complete, "
"Overall ETA in " + getRelativeETAAsString() + "." + "Overall ETA in " + getRelativeETAAsString() + "."
); );
} }
else { else {
displayUpdate( displayUpdate(
//"Overall: " + //"Overall: " +
getUnitsCompletedSoFarThisPhase() + " units processed; " + getUnitsCompletedSoFarThisPhase() + " units processed; "
//"(" + getTotalPercentCompleteAsString() + "%); " + //+ "(" + getTotalPercentCompleteAsString() + "%); "
"ETA in " + getRelativeETAAsString() + "." + "ETA in " + getRelativeETAAsString() + "."
); );
} }
} }
if (getCurrentPhase() == getNumPhases() && if (getCurrentPhase() == getNumPhases()
getUnitsCompletedSoFarThisPhase() >= getTotalUnitsThisPhase()) && getUnitsCompletedSoFarThisPhase() >= getTotalUnitsThisPhase())
{ {
displayUpdate("Done!"); displayUpdate("Done!");
} }
@@ -238,9 +246,9 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
* *
* @param message the message to display * @param message the message to display
*/ */
public void displayUpdate(final String message) { public final void displayUpdate(final String message) {
final Runnable proc = new Runnable() { final Runnable proc = new Runnable() { // NOPMD by Braids on 8/18/11 11:18 PM
public void run() { public void run() {
// i've been having trouble getting the dialog to display its title. // i've been having trouble getting the dialog to display its title.
dialog.setTitle(title); dialog.setTitle(title);
@@ -263,7 +271,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
@Override @Override
public final void dispose() { public final void dispose() {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:18 PM
public void run() { public void run() {
getDialog().dispose(); getDialog().dispose();
} }
@@ -275,7 +283,7 @@ public class MultiPhaseProgressMonitorWithETA extends BaseProgressMonitor {
* @return the JDialog for the current phase; use this judiciously to * @return the JDialog for the current phase; use this judiciously to
* manipulate the dialog directly. * manipulate the dialog directly.
*/ */
public JDialog getDialog() { public final JDialog getDialog() {
return dialog; return dialog;
} }

View File

@@ -1,7 +1,5 @@
package forge.view.swing; package forge.view.swing;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -28,7 +26,7 @@ import forge.view.swing.OldGuiNewGame.CardStackOffsetAction;
*/ */
public class ApplicationView implements FView { public class ApplicationView implements FView {
private SplashFrame splashFrame; private transient SplashFrame splashFrame;
/** /**
* The splashFrame field is guaranteed to exist when this constructor * The splashFrame field is guaranteed to exist when this constructor
@@ -39,13 +37,13 @@ public class ApplicationView implements FView {
// We must use invokeAndWait here to fulfill the constructor's // We must use invokeAndWait here to fulfill the constructor's
// contract. // contract.
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() { // NOPMD by Braids on 8/18/11 11:37 PM
public void run() { public void run() {
splashFrame = new SplashFrame(); splashFrame = new SplashFrame();
} }
}); });
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() { // NOPMD by Braids on 8/18/11 11:37 PM
public void run() { public void run() {
splashFrame.setVisible(true); splashFrame.setVisible(true);
} }
@@ -83,7 +81,10 @@ public class ApplicationView implements FView {
OldGuiNewGame.smoothLandCheckBox.setSelected(preferences.stackAiLand); OldGuiNewGame.smoothLandCheckBox.setSelected(preferences.stackAiLand);
OldGuiNewGame.devModeCheckBox.setSelected(preferences.developerMode); OldGuiNewGame.devModeCheckBox.setSelected(preferences.developerMode);
OldGuiNewGame.cardOverlay.setSelected(preferences.cardOverlay); OldGuiNewGame.cardOverlay.setSelected(preferences.cardOverlay);
// FindBugs doesn't like the next line.
ImageCache.scaleLargerThanOriginal = preferences.scaleLargerThanOriginal; ImageCache.scaleLargerThanOriginal = preferences.scaleLargerThanOriginal;
OldGuiNewGame.cardScale.setSelected(preferences.scaleLargerThanOriginal); OldGuiNewGame.cardScale.setSelected(preferences.scaleLargerThanOriginal);
CardStackOffsetAction.set(preferences.stackOffset); CardStackOffsetAction.set(preferences.stackOffset);
CardStackAction.setVal(preferences.maxStackSize); CardStackAction.setVal(preferences.maxStackSize);

View File

@@ -11,10 +11,13 @@ import javax.swing.SwingUtilities;
* Some general-purpose functions. * Some general-purpose functions.
*/ */
public final class UtilFunctions { public final class UtilFunctions {
/** /**
* Do not instantiate. * Do not instantiate.
*/ */
private UtilFunctions() {;} private UtilFunctions() {
// empty
}
/** /**
@@ -23,22 +26,23 @@ public final class UtilFunctions {
* @param paramName the name of the parameter; may be null * @param paramName the name of the parameter; may be null
* @param param the parameter to test * @param param the parameter to test
*/ */
public static void checkNotNull(String paramName, Object param) { public static void checkNotNull(final String paramName, final Object param) {
if (param != null) return; if (param != null) {
return;
}
NullPointerException exn = null; NullPointerException exn = null;
if (paramName != null) { if (paramName == null) {
exn = new NullPointerException(paramName + " must not be null"); exn = new NullPointerException(); // NOPMD by Braids on 8/18/11 11:19 PM
} }
else { else {
// exn = new NullPointerException(paramName + " must not be null"); // NOPMD by Braids on 8/18/11 11:19 PM
exn = new NullPointerException();
} }
// Doctor the exception to appear to come from the caller. // Doctor the exception to appear to come from the caller.
StackTraceElement[] trace = exn.getStackTrace(); final StackTraceElement[] trace = exn.getStackTrace();
int len = getSliceLength(trace, 1); final int len = getSliceLength(trace, 1);
exn.setStackTrace(slice(new StackTraceElement[len], trace, 1)); exn.setStackTrace(slice(new StackTraceElement[len], trace, 1));
throw exn; throw exn;
} }
@@ -55,7 +59,7 @@ public final class UtilFunctions {
* *
* @param proc the Runnable to run * @param proc the Runnable to run
*/ */
public static void invokeInEventDispatchThreadAndWait(final Runnable proc) { public static void invokeInEventDispatchThreadAndWait(final Runnable proc) { // NOPMD by Braids on 8/18/11 11:19 PM
if (SwingUtilities.isEventDispatchThread()) { if (SwingUtilities.isEventDispatchThread()) {
// Just run in the current thread. // Just run in the current thread.
proc.run(); proc.run();
@@ -64,9 +68,9 @@ public final class UtilFunctions {
try { try {
SwingUtilities.invokeAndWait(proc); SwingUtilities.invokeAndWait(proc);
} catch (InterruptedException exn) { } catch (InterruptedException exn) {
throw new RuntimeException(exn); throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11 11:19 PM
} catch (InvocationTargetException exn) { } catch (InvocationTargetException exn) {
throw new RuntimeException(exn); throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11 11:19 PM
} }
} }
} }
@@ -77,12 +81,14 @@ public final class UtilFunctions {
* *
* Please, only use it on small iterators. * Please, only use it on small iterators.
* *
* @param <T> (inferred automatically)
*
* @param iter the iterator to traverse * @param iter the iterator to traverse
* *
* @return an array of (the rest of) the iterator's values * @return an array of (the rest of) the iterator's values
*/ */
public static <T> T[] iteratorToArray(Iterator<T> iter) { public static <T> T[] iteratorToArray(final Iterator<T> iter) {
ArrayList<T> list = new ArrayList<T>(); final ArrayList<T> list = new ArrayList<T>();
T item; T item;
while (iter.hasNext()) { while (iter.hasNext()) {
@@ -91,7 +97,7 @@ public final class UtilFunctions {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T[] result = (T[]) list.toArray(); final T[] result = (T[]) list.toArray();
return result; return result;
} }
@@ -101,9 +107,11 @@ public final class UtilFunctions {
* *
* @param <T> (inferred automatically) * @param <T> (inferred automatically)
* *
* @param dstArray the array in which to place new items
*
* @param srcArray the array to copy (shallowly) * @param srcArray the array to copy (shallowly)
* *
* @param startIndex if positive, the index (from the left) at which to * @param startIndexIn if positive, the index (from the left) at which to
* start copying; if negative, we treat this as the index from the right. * start copying; if negative, we treat this as the index from the right.
* For example, calling this with startIndex = -2 returns the last two * For example, calling this with startIndex = -2 returns the last two
* items in the array, if it has that many. * items in the array, if it has that many.
@@ -111,27 +119,31 @@ public final class UtilFunctions {
* @return a shallow copy of array starting at startIndex; this may return * @return a shallow copy of array starting at startIndex; this may return
* an empty array if the startIndex is out of bounds. * an empty array if the startIndex is out of bounds.
*/ */
public static <T extends Object> T[] slice(T[] dstArray, T[] srcArray, public static <T extends Object> T[] slice(final T[] dstArray, final T[] srcArray,
int startIndex) final int startIndexIn)
{ {
int startIndex = startIndexIn;
if (startIndex < 0) { if (startIndex < 0) {
startIndex = srcArray.length + startIndex; startIndex = srcArray.length + startIndex;
if (startIndex < 0) startIndex = 0; if (startIndex < 0) {
startIndex = 0;
}
} }
if (dstArray == null) { if (dstArray == null) {
throw new NullPointerException(); throw new NullPointerException(); // NOPMD by Braids on 8/18/11 11:19 PM
} }
if (srcArray == null) { if (srcArray == null) {
throw new NullPointerException(); throw new NullPointerException(); // NOPMD by Braids on 8/18/11 11:19 PM
} }
int resultLength = getSliceLength(srcArray, startIndex); final int resultLength = getSliceLength(srcArray, startIndex);
if (dstArray.length != resultLength) { if (dstArray.length != resultLength) {
throw new ArrayIndexOutOfBoundsException( throw new ArrayIndexOutOfBoundsException(
"First parameter must have length " + resultLength + ", but length is " + dstArray.length + "."); "First parameter must have length " + resultLength
+ ", but length is " + dstArray.length + ".");
} }
int srcIx = startIndex; int srcIx = startIndex;
@@ -155,17 +167,31 @@ public final class UtilFunctions {
* *
* @see #slice(Object[], Object[], int) * @see #slice(Object[], Object[], int)
* *
* @param <T> (inferred automatically)
*
* @param srcArray the array that would be copied (shallowly)
*
* @param startIndexIn if positive, the index (from the left) at which
* copying would start; if negative, we treat this as the index from the
* right. For example, calling this with startIndex = -2 computes the
* length if slice would return the last two items in the array, if it has
* that many.
*
* @return the length of the array that would result from calling * @return the length of the array that would result from calling
* slice(Object[], Object[], int) with the given srcArray and * slice(Object[], Object[], int) with the given srcArray and
* startIndex. * startIndex.
*/ */
public static <T> int getSliceLength(T[] srcArray, int startIndex) { public static <T> int getSliceLength(final T[] srcArray, final int startIndexIn) {
int startIndex = startIndexIn;
if (startIndex < 0) { if (startIndex < 0) {
startIndex = srcArray.length + startIndex; startIndex = srcArray.length + startIndex;
if (startIndex < 0) startIndex = 0; if (startIndex < 0) {
startIndex = 0;
}
} }
int resultLength = srcArray.length - startIndex; final int resultLength = srcArray.length - startIndex;
return resultLength; return resultLength;
} }
@@ -184,6 +210,8 @@ public final class UtilFunctions {
* } * }
* </pre> * </pre>
* *
* @param <T> (inferred automatically)
*
* @param goodInstance a non-null instance of type T; looks neater than * @param goodInstance a non-null instance of type T; looks neater than
* passing in goodInstance.getClass() * passing in goodInstance.getClass()
* *
@@ -192,23 +220,30 @@ public final class UtilFunctions {
* @return null if obj is null or not an instance of goodInstance's class; * @return null if obj is null or not an instance of goodInstance's class;
* otherwise, we return obj cast to goodInstance's type * otherwise, we return obj cast to goodInstance's type
*/ */
public static <T> T checkNullOrNotInstance(T goodInstance, Object obj) { public static <T> T checkNullOrNotInstance(final T goodInstance, final Object obj) {
if (goodInstance == null) { if (goodInstance == null) {
throw new NullPointerException("first parameter must not be null"); throw new NullPointerException("first parameter must not be null"); // NOPMD by Braids on 8/18/11 11:19 PM
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<T> classT = (Class<T>) goodInstance.getClass(); final Class<T> classT = (Class<T>) goodInstance.getClass();
boolean viable = true; boolean viable = true;
if (obj == null) viable = false; if (obj == null) {
else if (!(classT.isInstance(obj))) viable = false; viable = false;
} else if (!(classT.isInstance(obj))) {
if (viable) { viable = false;
return classT.cast(obj);
} }
return null;
T result;
if (viable) {
result = classT.cast(obj);
} else {
result = null;
}
return result;
} }
@@ -220,13 +255,17 @@ public final class UtilFunctions {
* *
* @return "null" if obj is null, obj.toString() otherwise * @return "null" if obj is null, obj.toString() otherwise
*/ */
public static String safeToString(Object obj) { public static String safeToString(final Object obj) {
String result;
if (obj == null) { if (obj == null) {
return "null"; result = "null";
} }
else { else {
return obj.toString(); result = obj.toString();
} }
return result;
} }
/** /**
@@ -243,18 +282,18 @@ public final class UtilFunctions {
* *
* Disadvantages over HashSet and TreeSet: This runs in O(n*n) time. * Disadvantages over HashSet and TreeSet: This runs in O(n*n) time.
* *
* @param <T> (inferred automatically)
*
* @param list the list to modify; this is fastest with ArrayList. * @param list the list to modify; this is fastest with ArrayList.
*/ */
public static <T> void smartRemoveDuplicatesAndNulls(List<T> list) public static <T> void smartRemoveDuplicatesAndNulls(final List<T> list) {
{
// Get rid of pesky leading nulls. // Get rid of pesky leading nulls.
smartRemoveDuplicatesAndNullsHelper(list, 0, null); smartRemoveDuplicatesAndNullsHelper(list, 0, null);
for (int earlierIx = 0; earlierIx < list.size(); earlierIx++) for (int earlierIx = 0; earlierIx < list.size(); earlierIx++) {
{
for (int laterIx = earlierIx + 1; laterIx < list.size(); laterIx++) for (int laterIx = earlierIx + 1; laterIx < list.size(); laterIx++)
{ {
T itemAtEarlierIx = list.get(earlierIx); final T itemAtEarlierIx = list.get(earlierIx);
smartRemoveDuplicatesAndNullsHelper(list, laterIx, smartRemoveDuplicatesAndNullsHelper(list, laterIx,
itemAtEarlierIx); itemAtEarlierIx);
@@ -267,6 +306,8 @@ public final class UtilFunctions {
* Helper method for smartRemoveDuplicatesAndNulls that is subject to * Helper method for smartRemoveDuplicatesAndNulls that is subject to
* change; if you call this directly, you do so at your own risk! * change; if you call this directly, you do so at your own risk!
* *
* @param <T> (inferred automatically)
*
* @param list the list to modify; if all items from startIx to the end * @param list the list to modify; if all items from startIx to the end
* are either null or equal to objSeenPreviously, then we truncate the * are either null or equal to objSeenPreviously, then we truncate the
* list just before startIx. * list just before startIx.
@@ -278,14 +319,14 @@ public final class UtilFunctions {
* may be null. * may be null.
*/ */
public static <T> void smartRemoveDuplicatesAndNullsHelper( public static <T> void smartRemoveDuplicatesAndNullsHelper(
List<T> list, int startIx, T objSeenPreviously) final List<T> list, final int startIx, final T objSeenPreviously)
{ {
while (startIx < list.size() && while (startIx < list.size()
(list.get(startIx) == null || && (list.get(startIx) == null
list.get(startIx) == objSeenPreviously || || list.get(startIx) == objSeenPreviously
list.get(startIx).equals(objSeenPreviously))) || list.get(startIx).equals(objSeenPreviously)))
{ {
int lastItemIx = list.size()-1; final int lastItemIx = list.size() - 1;
// Overwrite the item at laterIx with the one at the end, // Overwrite the item at laterIx with the one at the end,
// then delete the one at the end. // then delete the one at the end.

View File

@@ -22,11 +22,17 @@ import java.util.TreeSet;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
@Test(groups = {"UnitTest"}, timeOut = 5000) @Test(groups = {"UnitTest" }, timeOut = CardFactoryTest.DEFAULT_TEST_TIMEOUT_MS)
public class CardFactoryTest implements NewConstants { public class CardFactoryTest implements NewConstants {
private CardFactoryInterface factory; /** The default time to allow a test to run before TestNG ignores it. */
public static final int DEFAULT_TEST_TIMEOUT_MS = 5000; // NOPMD by Braids on 8/18/11 11:43 PM
private transient CardFactoryInterface factory;
/**
* Executed before each test method, as in JUnit.
*/
@BeforeMethod @BeforeMethod
public final void setUp() { public final void setUp() {
OldGuiNewGame.loadDynamicGamedata(); OldGuiNewGame.loadDynamicGamedata();
@@ -37,8 +43,8 @@ public class CardFactoryTest implements NewConstants {
* Just a quick test to see if Arc-Slogger is in the database, and if it * Just a quick test to see if Arc-Slogger is in the database, and if it
* has the correct owner. * has the correct owner.
*/ */
@Test(enabled = true, timeOut = 5000) @Test(enabled = true, timeOut = DEFAULT_TEST_TIMEOUT_MS)
public final void test_getCard_1() { public final void test_getCard_1() { // NOPMD by Braids on 8/18/11 11:39 PM
final Card card = factory.getCard("Arc-Slogger", null); final Card card = factory.getCard("Arc-Slogger", null);
Assert.assertNotNull(card, "card is not null"); Assert.assertNotNull(card, "card is not null");
Assert.assertNull(card.getOwner(), "card has correct owner"); Assert.assertNull(card.getOwner(), "card has correct owner");
@@ -47,19 +53,19 @@ public class CardFactoryTest implements NewConstants {
/** /**
* Make sure the method throws an exception when it's supposed to. * Make sure the method throws an exception when it's supposed to.
*/ */
@Test(enabled = true, timeOut = 5000) @Test(enabled = true, timeOut = DEFAULT_TEST_TIMEOUT_MS)
public final void test_getRandomCombinationWithoutRepetition_tooLarge() { public final void test_getRandomCombinationWithoutRepetition_tooLarge() { // NOPMD by Braids on 8/18/11 11:39 PM
BraidsAssertFunctions.assertThrowsException(IllegalArgumentException.class, BraidsAssertFunctions.assertThrowsException(IllegalArgumentException.class,
new ClumsyRunnable() { new ClumsyRunnable() {
public void run() throws Exception { public void run() throws Exception { // NOPMD by Braids on 8/18/11 11:40 PM
factory.getRandomCombinationWithoutRepetition(factory.size()); factory.getRandomCombinationWithoutRepetition(factory.size());
} }
}); });
BraidsAssertFunctions.assertThrowsException(IllegalArgumentException.class, BraidsAssertFunctions.assertThrowsException(IllegalArgumentException.class,
new ClumsyRunnable() { new ClumsyRunnable() {
public void run() throws Exception { public void run() throws Exception { // NOPMD by Braids on 8/18/11 11:40 PM
int largeDivisorForRandomCombo = 4; final int largeDivisorForRandomCombo = 4; // NOPMD by Braids on 8/18/11 11:41 PM
factory.getRandomCombinationWithoutRepetition(factory.size() / largeDivisorForRandomCombo); factory.getRandomCombinationWithoutRepetition(factory.size() / largeDivisorForRandomCombo);
} }
}); });
@@ -70,10 +76,10 @@ public class CardFactoryTest implements NewConstants {
* *
* This doesn't work with LazyCardFactory, so it is too slow to enable by default. * This doesn't work with LazyCardFactory, so it is too slow to enable by default.
*/ */
@Test(enabled = false, timeOut = 5000) @Test(enabled = false, timeOut = DEFAULT_TEST_TIMEOUT_MS)
public final void test_getRandomCombinationWithoutRepetition_oneTenth() { public final void test_getRandomCombinationWithoutRepetition_oneTenth() { // NOPMD by Braids on 8/18/11 11:39 PM
factory = new PreloadingCardFactory(ForgeProps.getFile(CARDSFOLDER)); factory = new PreloadingCardFactory(ForgeProps.getFile(CARDSFOLDER));
int divisor = 10; final int divisor = 10; // NOPMD by Braids on 8/18/11 11:41 PM
final CardList actual = factory.getRandomCombinationWithoutRepetition(factory.size() / divisor); final CardList actual = factory.getRandomCombinationWithoutRepetition(factory.size() / divisor);
final Set<String> cardNames = new TreeSet<String>(); final Set<String> cardNames = new TreeSet<String>();