mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 02:08:00 +00:00
More code cleanup
This commit is contained in:
@@ -31,7 +31,7 @@ import forge.util.IHasName;
|
||||
public interface IStorage<T> extends Iterable<T>, IHasName {
|
||||
|
||||
T get(final String name);
|
||||
|
||||
|
||||
T find(final Predicate<T> condition);
|
||||
// todo: find(final Predicate<T> condition, boolean recursive).
|
||||
|
||||
@@ -40,10 +40,10 @@ public interface IStorage<T> extends Iterable<T>, IHasName {
|
||||
boolean contains(final String name);
|
||||
|
||||
int size();
|
||||
|
||||
|
||||
void add(final T deck);
|
||||
|
||||
void delete(final String deckName);
|
||||
|
||||
|
||||
IStorage<IStorage<T>> getFolders();
|
||||
}
|
||||
@@ -18,21 +18,21 @@ public class StorageNestedFolders<T> extends StorageBase<IStorage<T>> {
|
||||
}
|
||||
|
||||
// need code implementations for folder create/delete operations
|
||||
|
||||
|
||||
@Override
|
||||
public void add(IStorage<T> item) {
|
||||
File subdir = new File(thisFolder, item.getName());
|
||||
subdir.mkdir();
|
||||
|
||||
// TODO: save recursivelly the passed IStorage
|
||||
|
||||
// TODO: save recursivelly the passed IStorage
|
||||
throw new UnsupportedOperationException("method is not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(String itemName) {
|
||||
File subdir = new File(thisFolder, itemName);
|
||||
IStorage<T> f = map.remove(itemName);
|
||||
|
||||
|
||||
// TODO: Clear all that files from disk
|
||||
if (f != null) {
|
||||
subdir.delete(); // won't work if not empty;
|
||||
|
||||
@@ -78,9 +78,9 @@ public abstract class StorageReaderFile<T> extends StorageReaderBase<T> {
|
||||
|
||||
idx++;
|
||||
String newKey = keySelector.apply(item);
|
||||
if( result.containsKey(newKey))
|
||||
if (result.containsKey(newKey)) {
|
||||
System.err.println("StorageReader: Overwriting an object with key " + newKey);
|
||||
|
||||
}
|
||||
result.put(newKey, item);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public abstract class StorageReaderFile<T> extends StorageReaderBase<T> {
|
||||
* @param line
|
||||
* the line
|
||||
* @return the t
|
||||
*/
|
||||
*/
|
||||
protected abstract T read(String line, int idx);
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,10 +60,10 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
|
||||
|
||||
int idx = 0;
|
||||
Iterable<String> file = FileUtil.readFile(this.file);
|
||||
|
||||
|
||||
List<String> accumulator = new ArrayList<String>();
|
||||
String header = null;
|
||||
|
||||
|
||||
for (final String s : file) {
|
||||
if (!this.lineContainsObject(s)) {
|
||||
continue;
|
||||
@@ -92,7 +92,7 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
|
||||
String newKey = keySelector.apply(item);
|
||||
if( result.containsKey(newKey))
|
||||
System.err.println("StorageReader: Overwriting an object with key " + newKey);
|
||||
|
||||
|
||||
result.put(newKey, item);
|
||||
}
|
||||
}
|
||||
@@ -102,18 +102,18 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
|
||||
private final T readItem(String header, Iterable<String> accumulator, int idx) {
|
||||
final T item = this.read(header, accumulator, idx);
|
||||
if (null != item) return item;
|
||||
|
||||
|
||||
final String msg = "An object stored in " + this.file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file attached.";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*
|
||||
* @param line
|
||||
* the line
|
||||
* @return the t
|
||||
*/
|
||||
*/
|
||||
protected abstract T read(String title, Iterable<String> body, int idx);
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
|
||||
*/
|
||||
public StorageReaderFolder(final File itemDir0, Function<? super T, String> keySelector0) {
|
||||
super(keySelector0);
|
||||
|
||||
|
||||
this.directory = itemDir0;
|
||||
|
||||
if (this.directory == null) {
|
||||
@@ -75,7 +75,7 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
|
||||
}
|
||||
|
||||
public final List<String> objectsThatFailedToLoad = new ArrayList<String>();
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.util.IItemReader#readAll()
|
||||
*/
|
||||
@@ -92,9 +92,9 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
String newKey = keySelector.apply(newDeck);
|
||||
if( result.containsKey(newKey))
|
||||
if (result.containsKey(newKey)) {
|
||||
System.err.println("StorageReader: Overwriting an object with key " + newKey);
|
||||
|
||||
}
|
||||
result.put(newKey, newDeck);
|
||||
} catch (final NoSuchElementException ex) {
|
||||
final String message = String.format("%s failed to load because ---- %s", file.getName(), ex.getMessage());
|
||||
@@ -128,7 +128,6 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
|
||||
@Override
|
||||
public Iterable<File> getSubFolders() {
|
||||
File[] list = this.directory.listFiles(new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
return file.isDirectory() && !file.isHidden();
|
||||
|
||||
Reference in New Issue
Block a user