[minor] removed redundant modifiers

This commit is contained in:
North 2013-03-02 15:46:55 +02:00
parent f50dcdb8da
commit cdd5c3f2d3
5 changed files with 71 additions and 31 deletions

View file

@ -82,8 +82,8 @@ public final class Constants {
public static final String BASE_SOUND_PATH = "plugins" + File.separator + "sounds" + File.separator;
public interface IO {
public static final String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
public static final String IMAGE_PROPERTIES_FILE = "image.url.properties";
String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
String IMAGE_PROPERTIES_FILE = "image.url.properties";
}
public enum DeckEditorMode {

View file

@ -20,8 +20,8 @@ public class Constants {
public static final int TOOLTIP_BORDER_WIDTH = 80;
public interface IO {
public static final String imageBaseDir = "plugins" + File.separator + "images";
public static final String IMAGE_PROPERTIES_FILE = "image.url.properties";
String imageBaseDir = "plugins" + File.separator + "images";
String IMAGE_PROPERTIES_FILE = "image.url.properties";
}
public static final String CARD_IMAGE_PATH_TEMPLATE = "." + File.separator + "plugins" + File.separator + "images/{set}/{name}.{collector}.full.jpg";

View file

@ -52,8 +52,11 @@ public class DownloadJob extends AbstractLaternaBean {
* Sets the job's state. If the state is {@link State#ABORTED}, it instead sets the error to "ABORTED"
*/
public void setState(State state) {
if(state == State.ABORTED) setError("ABORTED");
else this.state.setValue(state);
if (state == State.ABORTED) {
setError("ABORTED");
} else {
this.state.setValue(state);
}
}
/**
@ -77,7 +80,9 @@ public class DownloadJob extends AbstractLaternaBean {
* given message and exception.
*/
public void setError(String message, Exception error) {
if(message == null) message = error.toString();
if (message == null) {
message = error.toString();
}
log.warn(message, error);
this.state.setValue(State.ABORTED);
this.error.setValue(error);
@ -133,7 +138,9 @@ public class DownloadJob extends AbstractLaternaBean {
private URLConnection c;
public URLConnection getConnection() throws IOException {
if(c == null) c = proxy == null? new URL(url).openConnection():new URL(url).openConnection(proxy);
if (c == null) {
c = proxy == null ? new URL(url).openConnection() : new URL(url).openConnection(proxy);
}
return c;
}
@ -154,7 +161,9 @@ public class DownloadJob extends AbstractLaternaBean {
private URLConnection c;
public URLConnection getConnection() throws IOException {
if(c == null) c = proxy == null? url.openConnection():url.openConnection(proxy);
if (c == null) {
c = proxy == null ? url.openConnection() : url.openConnection(proxy);
}
return c;
}
@ -180,8 +189,9 @@ public class DownloadJob extends AbstractLaternaBean {
public OutputStream open() throws IOException {
File parent = file.getAbsoluteFile().getParentFile();
//Trying to create the directory before checking it exists makes it threadsafe
if(!parent.mkdirs() && !parent.exists()) throw new IOException(parent
+ ": directory could not be created");
if (!parent.mkdirs() && !parent.exists()) {
throw new IOException(parent + ": directory could not be created");
}
return new FileOutputStream(file);
}
@ -192,22 +202,24 @@ public class DownloadJob extends AbstractLaternaBean {
@Override
public void delete() throws IOException {
if(file.exists() && !file.delete()) throw new IOException(file + " couldn't be deleted");
if (file.exists() && !file.delete()) {
throw new IOException(file + " couldn't be deleted");
}
}
};
}
public static interface Source {
public InputStream open() throws IOException;
public interface Source {
InputStream open() throws IOException;
public int length() throws IOException;
int length() throws IOException;
}
public static interface Destination {
public OutputStream open() throws IOException;
public interface Destination {
OutputStream open() throws IOException;
public boolean exists() throws IOException;
boolean exists() throws IOException;
public void delete() throws IOException;
void delete() throws IOException;
}
}

View file

@ -33,8 +33,11 @@ public final class ListenableCollections {
private ListenableCollections() {}
public static <E> List<E> listenableList(List<E> list, ListListener<E> listener) {
if(list instanceof RandomAccess) return new ListenableList<E>(list, listener);
else return new ListenableSequentialList<E>(list, listener);
if (list instanceof RandomAccess) {
return new ListenableList<E>(list, listener);
} else {
return new ListenableSequentialList<E>(list, listener);
}
}
public static <E> Set<E> listenableSet(Set<E> set, SetListener<E> listener) {
@ -45,21 +48,21 @@ public final class ListenableCollections {
return new ListenableMap<K, V>(map, listener);
}
public static interface ListListener<E> extends Serializable {
public interface ListListener<E> extends Serializable {
/**
* Notified after a value was added to the list.
*/
public void add(int index, E newValue);
void add(int index, E newValue);
/**
* Notified after a value in the list was changed.
*/
public void set(int index, E oldValue, E newValue);
void set(int index, E oldValue, E newValue);
/**
* Notified after a value was removed from the list.
*/
public void remove(int index, E oldValue);
void remove(int index, E oldValue);
}
private static class ListenableList<E> extends AbstractList<E> implements RandomAccess, Serializable {
@ -122,44 +125,53 @@ public final class ListenableCollections {
private int lastIndex;
private E lastValue;
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public boolean hasPrevious() {
return it.hasPrevious();
}
@Override
public E next() {
lastIndex = it.nextIndex();
lastValue = it.next();
return lastValue;
}
@Override
public int nextIndex() {
return it.nextIndex();
}
@Override
public E previous() {
lastIndex = it.previousIndex();
lastValue = it.previous();
return lastValue;
}
@Override
public int previousIndex() {
return it.previousIndex();
}
@Override
public void add(E o) {
it.add(o);
listener.add(previousIndex(), o);
}
@Override
public void set(E o) {
it.set(o);
listener.set(lastIndex, lastValue, o);
}
@Override
public void remove() {
it.remove();
listener.remove(lastIndex, lastValue);
@ -204,7 +216,9 @@ public final class ListenableCollections {
@Override
public boolean add(E o) {
boolean b = delegate.add(o);
if(b) listener.add(o);
if (b) {
listener.add(o);
}
return b;
};
@ -212,7 +226,9 @@ public final class ListenableCollections {
@Override
public boolean remove(Object o) {
boolean b = delegate.remove(o);
if(b) listener.remove((E) o);
if (b) {
listener.remove((E) o);
}
return b;
}
@ -223,18 +239,23 @@ public final class ListenableCollections {
private boolean hasLast;
private E last;
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public E next() {
last = it.next();
hasLast = true;
return last;
}
@Override
public void remove() {
if(!hasLast) throw new IllegalStateException();
if(!hasLast) {
throw new IllegalStateException();
}
it.remove();
listener.remove(last);
}
@ -298,7 +319,9 @@ public final class ListenableCollections {
V old = delegate.remove(key);
listener.remove((K) key, old);
return old;
} else return null;
} else {
return null;
}
}
@Override
@ -337,18 +360,23 @@ public final class ListenableCollections {
private boolean hasLast;
private Entry<K, V> last;
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public Entry<K, V> next() {
last = it.next();
hasLast = true;
return last;
}
@Override
public void remove() {
if(!hasLast) throw new IllegalStateException();
if(!hasLast) {
throw new IllegalStateException();
}
hasLast = false;
it.remove();
listener.remove(last.getKey(), last.getValue());

View file

@ -48,5 +48,5 @@ public interface Watcher<T extends Watcher<T>> extends Serializable {
boolean conditionMet();
void reset();
abstract T copy();
T copy();
}