From 1ae85dc1b48a66850520b086eac71a4d76dd80e1 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 30 May 2014 18:39:32 +0200 Subject: [PATCH] Some minor formatting. --- .../main/java/mage/client/chat/ChatPanel.java | 7 +- Mage/src/mage/util/CircularList.java | 66 +++++++++++++------ 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java index b055535cad..cae00371dc 100644 --- a/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java +++ b/Mage.Client/src/main/java/mage/client/chat/ChatPanel.java @@ -61,7 +61,7 @@ public class ChatPanel extends javax.swing.JPanel { private UUID chatId; private Session session; - private List players = new ArrayList(); + private final List players = new ArrayList(); private final TableModel tableModel; /** * Chat message color for opponents. @@ -121,7 +121,7 @@ public class ChatPanel extends javax.swing.JPanel { /** * Maps message colors to {@link Color}. */ - private static final Map colorMap = new EnumMap(MessageColor.class); + private static final Map colorMap = new EnumMap<>(MessageColor.class); static { colorMap.put(MessageColor.BLACK, Color.black); @@ -144,6 +144,7 @@ public class ChatPanel extends javax.swing.JPanel { */ /** * Creates new form ChatPanel + * @param addPlayersTab */ public ChatPanel(boolean addPlayersTab) { tableModel = new TableModel(); @@ -299,7 +300,7 @@ public class ChatPanel extends javax.swing.JPanel { class TableModel extends AbstractTableModel { - private String[] columnNames = new String[]{"Players", "Info", "Games"}; + private final String[] columnNames = new String[]{"Players", "Info", "Games"}; private UsersView[] players = new UsersView[0]; public void loadData(Collection players) throws MageRemoteException { diff --git a/Mage/src/mage/util/CircularList.java b/Mage/src/mage/util/CircularList.java index 25cfb0d82d..3b0c66234f 100644 --- a/Mage/src/mage/util/CircularList.java +++ b/Mage/src/mage/util/CircularList.java @@ -41,11 +41,12 @@ import java.util.concurrent.locks.ReentrantLock; * a thread-safe circular list * * @author BetaSteward_at_googlemail.com + * @param */ public class CircularList implements List, Iterable, Serializable { //TODO: might have to make E extend Copyable - protected List list = new ArrayList(); + protected List list = new ArrayList<>(); protected final ReentrantLock lock = new ReentrantLock(); @@ -63,11 +64,13 @@ public class CircularList implements List, Iterable, Serializable { } public CircularList copy() { - return new CircularList(this); + return new CircularList<>(this); } /** * Inserts an element into the current position + * @param e + * @return */ @Override public boolean add(E e) { @@ -102,6 +105,7 @@ public class CircularList implements List, Iterable, Serializable { /** * Retrieves the element at the current position + * @return */ public E get() { return list.get(this.index); @@ -182,8 +186,9 @@ public class CircularList implements List, Iterable, Serializable { private int incrementListPointer(int index) { index++; - if (index >= list.size()) + if (index >= list.size()) { index = 0; + } return index; } @@ -200,8 +205,9 @@ public class CircularList implements List, Iterable, Serializable { private int decrementListPointer(int index) { index--; - if (index < 0) + if (index < 0) { index = list.size() - 1; + } return index; } @@ -213,8 +219,9 @@ public class CircularList implements List, Iterable, Serializable { if (index > list.size()) { index = list.size() - 1; } - else if (index < 0) + else if (index < 0) { index = 0; + } return index; } @@ -343,17 +350,17 @@ public class CircularList implements List, Iterable, Serializable { @Override public Iterator iterator() { - return new CircularIterator(); + return new CircularIterator<>(); } @Override public ListIterator listIterator() { - return new CircularListIterator(); + return new CircularListIterator<>(); } @Override public ListIterator listIterator(int index) { - return new CircularListIterator(index); + return new CircularListIterator<>(index); } private class CircularIterator implements Iterator { @@ -371,23 +378,27 @@ public class CircularList implements List, Iterable, Serializable { @Override public boolean hasNext() { - if (!hasMoved && size() > 0) + if (!hasMoved && size() > 0) { return true; + } return cursor != lastIndex; } @Override public E next() { - if (!this.hasNext()) + if (!this.hasNext()) { throw new IllegalStateException(); - if (curModCount != modCount) + } + if (curModCount != modCount) { throw new ConcurrentModificationException(); + } E data = (E) list.get(cursor); cursor = incrementListPointer(cursor); hasMoved = true; return data; } + @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } @@ -412,59 +423,76 @@ public class CircularList implements List, Iterable, Serializable { lastIndex = index; } + @Override public boolean hasNext() { - if (!hasMoved && size() > 0) + if (!hasMoved && size() > 0) { return true; + } return cursor != lastIndex; } + @Override public E next() { - if (!this.hasNext()) + if (!this.hasNext()) { throw new IllegalStateException(); - if (curModCount != modCount) + } + if (curModCount != modCount) { throw new ConcurrentModificationException(); + } E data = (E) list.get(cursor); cursor = incrementListPointer(cursor); hasMoved = true; return data; } + @Override public boolean hasPrevious() { - if (!hasMoved && size() > 0) + if (!hasMoved && size() > 0) { return true; + } return cursor != firstIndex; } + @Override public E previous() { - if (!this.hasPrevious()) + if (!this.hasPrevious()) { throw new IllegalStateException(); - if (curModCount != modCount) + } + if (curModCount != modCount) { throw new ConcurrentModificationException(); + } cursor = decrementListPointer(cursor); hasMoved = true; return (E) list.get(cursor); } + @Override public int nextIndex() { - if (this.hasNext()) + if (this.hasNext()) { return incrementListPointer(cursor); + } return list.size(); } + @Override public int previousIndex() { - if (this.hasPrevious()) + if (this.hasPrevious()) { return decrementListPointer(cursor); + } return -1; } + @Override public void remove() { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void set(E arg0) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void add(E arg0) { throw new UnsupportedOperationException("Not supported yet."); }