Code cleanup

This commit is contained in:
drdev
2014-01-15 05:07:59 +00:00
parent 726084bc06
commit 03870821c5
8 changed files with 77 additions and 94 deletions

View File

@@ -28,22 +28,21 @@ import com.google.common.collect.Iterables;
import forge.util.IItemReader;
//reads and writeDeck Deck objects
/**
* <p>
* DeckManager class.
* StorageBase class.
* </p>
*
* @param <T> the generic type
* @author Forge
* @version $Id: DeckManager.java 13590 2012-01-27 20:46:27Z Max mtg $
* @version $Id: StorageBase.java 13590 2012-01-27 20:46:27Z Max mtg $
*/
public class StorageBase<T> implements IStorage<T> {
protected final Map<String, T> map;
public final static StorageBase<?> emptyMap = new StorageBase<Object>("Empty", new HashMap<String, Object>());
public final String name;
public StorageBase(final String name, final IItemReader<T> io) {
this.name = name;
this.map = io.readAll();
@@ -52,13 +51,12 @@ public class StorageBase<T> implements IStorage<T> {
public StorageBase(final String name, final Map<String, T> inMap) {
this.name = name;
this.map = inMap;
}
}
@Override
public T get(final String name) {
return this.map.get(name);
}
@Override
public final Collection<String> getItemNames() {
@@ -84,16 +82,14 @@ public class StorageBase<T> implements IStorage<T> {
public T find(Predicate<T> condition) {
return Iterables.tryFind(map.values(), condition).orNull();
}
@Override
public void add(T deck) {
public void add(T item) {
throw new UnsupportedOperationException("This is a read-only storage");
}
@Override
public void delete(String deckName) {
public void delete(String itemName) {
throw new UnsupportedOperationException("This is a read-only storage");
}

View File

@@ -34,10 +34,8 @@ import forge.util.FileUtil;
* the generic type
*/
public abstract class StorageReaderFile<T> extends StorageReaderBase<T> {
private final File file;
/**
* Instantiates a new storage reader file.
*

View File

@@ -36,7 +36,6 @@ import forge.util.FileUtil;
* the generic type
*/
public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T> {
private final File file;
public StorageReaderFileSections(final String pathname, final Function<? super T, String> keySelector0) {
@@ -46,7 +45,6 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
public StorageReaderFileSections(final File file0, final Function<? super T, String> keySelector0) {
super(keySelector0);
this.file = file0;
}
protected Map<String, T> createMap() {
@@ -136,5 +134,4 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
public String getItemKey(final T item) {
return this.keySelector.apply(item);
}
}

View File

@@ -38,7 +38,6 @@ import com.google.common.base.Function;
* @param <T> the generic type
*/
public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
/**
* @return the directory
*/
@@ -46,18 +45,17 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
return directory;
}
protected final File directory;
/**
* Instantiates a new storage reader folder.
*
* @param deckDir0 the deck dir0
* @param itemDir0 the item dir0
*/
public StorageReaderFolder(final File deckDir0, Function<? super T, String> keySelector0) {
public StorageReaderFolder(final File itemDir0, Function<? super T, String> keySelector0) {
super(keySelector0);
this.directory = deckDir0;
this.directory = itemDir0;
if (this.directory == null) {
throw new IllegalArgumentException("No directory specified");
@@ -125,7 +123,6 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
public String getItemKey(T item) {
return keySelector.apply(item);
}
// methods handling nested folders are provided. It's up to consumer whether to use these or not.
@Override