remove warnings, use FileUtil to read text files

This commit is contained in:
Maxmtg
2012-10-08 12:05:28 +00:00
parent c59d1307d7
commit dd2e082b49
7 changed files with 64 additions and 92 deletions

View File

@@ -22,8 +22,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Set;
import com.google.common.base.Supplier;
import forge.Card;
import forge.Command;

View File

@@ -805,7 +805,7 @@ public class ComputerUtilAttack {
for (int i = 0; i < attackersLeft.size(); i++) {
final Card attacker = attackersLeft.get(i);
if (this.aiAggression < 5 && !attacker.hasFirstStrike() && !attacker.hasDoubleStrike()
&& CombatUtil.getTotalFirstStrikeBlockPower(attacker, AllZone.getHumanPlayer())
&& CombatUtil.getTotalFirstStrikeBlockPower(attacker, ai.getOpponent())
>= attacker.getKillDamage()) {
continue;
}

View File

@@ -957,7 +957,7 @@ public class MagicStack extends MyObservable {
AllZone.getInputControl().setInput(target);
} else {
// AI choosing what to haunt
final List<Card> oppCreats = CardLists.filterControlledBy(creats, AllZone.getHumanPlayer());
final List<Card> oppCreats = CardLists.filterControlledBy(creats, source.getController().getOpponent());
if (oppCreats.size() != 0) {
haunterDiesWork.setTargetCard(CardFactoryUtil.getWorstCreatureAI(oppCreats));
} else {

View File

@@ -17,27 +17,24 @@
*/
package forge.properties;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.io.Files;
import forge.Constant;
import forge.Constant.Preferences;
import forge.gui.home.EMenuItem;
import forge.gui.match.VMatchUI;
import forge.gui.match.nonsingleton.VField;
import forge.gui.match.views.VDev;
import forge.util.FileUtil;
/**
* Holds default preference values in an enum.
@@ -165,25 +162,16 @@ public class ForgePreferences {
// This code is here temporarily to facilitate this transfer.
// After a while, this can be deleted. Doublestrike 21-5-12
final File oldFile = new File("forge.preferences");
if (oldFile.exists()) {
final File newFile = new File(NewConstants.PREFS_GLOBAL_FILE);
final InputStream in = new FileInputStream(oldFile);
final OutputStream out = new FileOutputStream(newFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
Files.copy(oldFile, newFile);
oldFile.delete();
} // END TEMPORARY CONSOLIDATION FACILITATION
final BufferedReader input = new BufferedReader(new FileReader(NewConstants.PREFS_GLOBAL_FILE));
String line = null;
while ((line = input.readLine()) != null) {
List<String> lines = FileUtil.readFile(NewConstants.PREFS_GLOBAL_FILE);
for( String line :lines ) {
if (line.startsWith("#") || (line.length() == 0)) {
continue;
}

View File

@@ -17,18 +17,18 @@
*/
package forge.quest.data;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import forge.properties.ForgeProps;
import forge.properties.NewConstants.Quest;
import forge.util.FileUtil;
/**
* Holds default preference values in an enum. Loads preferred values when
@@ -226,24 +226,19 @@ public class QuestPreferences implements Serializable {
/** Instantiates a QuestPreferences object. */
public QuestPreferences() {
this.preferenceValues = new HashMap<QPref, String>();
try {
final BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(Quest.PREFS)));
String line = null;
while ((line = input.readLine()) != null) {
if (line.startsWith("#") || (line.length() == 0)) {
continue;
}
final String[] split = line.split("=");
if (split.length == 2) {
this.setPreference(split[0], split[1]);
}
List<String> lines = FileUtil.readFile(ForgeProps.getFile(Quest.PREFS));
for (String line : lines ) {
if (line.startsWith("#") || (line.length() == 0)) {
continue;
}
final String[] split = line.split("=");
if (split.length == 2) {
this.setPreference(split[0], split[1]);
}
} catch (final FileNotFoundException ex) {
// ex.printStackTrace();
} catch (final IOException ex) {
// ex.printStackTrace();
}
}

View File

@@ -17,18 +17,17 @@
*/
package forge.quest.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import com.esotericsoftware.minlog.Log;
import forge.error.ErrorViewer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.util.FileUtil;
import forge.util.MyRandom;
/**
@@ -76,61 +75,52 @@ public class ReadPriceList {
* @return a {@link java.util.HashMap} object.
*/
private HashMap<String, Integer> readFile(final File file) {
BufferedReader in;
final HashMap<String, Integer> map = new HashMap<String, Integer>();
final Random r = MyRandom.getRandom();
try {
List<String> lines = FileUtil.readFile(file);
for (String line : lines) {
if ( line.trim().length() == 0 ) break;
if (line.startsWith(ReadPriceList.COMMENT))
continue;
final String[] s = line.split("=");
final String name = s[0].trim();
final String price = s[1].trim();
in = new BufferedReader(new FileReader(file));
String line = in.readLine();
// System.out.println("Name: " + name + ", Price: " +
// price);
// stop reading if end of file or blank line is read
while ((line != null) && (line.trim().length() != 0)) {
if (!line.startsWith(ReadPriceList.COMMENT)) {
final String[] s = line.split("=");
final String name = s[0].trim();
final String price = s[1].trim();
try {
int val = Integer.parseInt(price.trim());
// System.out.println("Name: " + name + ", Price: " +
// price);
if (!(name.equals("Plains") || name.equals("Island") || name.equals("Swamp")
|| name.equals("Mountain") || name.equals("Forest")
|| name.equals("Snow-Covered Plains") || name.equals("Snow-Covered Island")
|| name.equals("Snow-Covered Swamp") || name.equals("Snow-Covered Mountain") || name
.equals("Snow-Covered Forest"))) {
float ff = 0;
if (r.nextInt(100) < 90) {
ff = r.nextInt(10) * (float) .01;
} else {
// +/- 50%
ff = r.nextInt(50) * (float) .01;
}
try {
int val = Integer.parseInt(price.trim());
if (!(name.equals("Plains") || name.equals("Island") || name.equals("Swamp")
|| name.equals("Mountain") || name.equals("Forest")
|| name.equals("Snow-Covered Plains") || name.equals("Snow-Covered Island")
|| name.equals("Snow-Covered Swamp") || name.equals("Snow-Covered Mountain") || name
.equals("Snow-Covered Forest"))) {
float ff = 0;
if (r.nextInt(100) < 90) {
ff = r.nextInt(10) * (float) .01;
} else {
// +/- 50%
ff = r.nextInt(50) * (float) .01;
}
if (r.nextInt(100) < 50) {
val = (int) (val * (1 - ff));
} else {
// +ff%
val = (int) (val * (1 + ff));
}
}
map.put(name, val);
} catch (final NumberFormatException nfe) {
Log.warn("NumberFormatException: " + nfe.getMessage());
if (r.nextInt(100) < 50) {
val = (int) (val * (1 - ff));
} else {
// +ff%
val = (int) (val * (1 + ff));
}
}
line = in.readLine();
} // if
} catch (final Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("ReadPriceList : readFile error, " + ex);
}
map.put(name, val);
} catch (final NumberFormatException nfe) {
Log.warn("NumberFormatException: " + nfe.getMessage());
}
}
return map;
} // readFile()

View File

@@ -108,6 +108,7 @@ public class HttpUtil {
httpOut.write(bufferBytesRead);
httpOut.flush();
}
uploadFileReader.close();
} catch (final IOException e) {
return;
}