Replaced usage of SortedLinkedList with PriorityQueue and removed SortedLinkedList

This commit is contained in:
Mads Boddum
2015-11-25 17:39:15 +01:00
parent bd978c0f93
commit 786eb28de6
4 changed files with 6 additions and 143 deletions
+6 -6
View File
@@ -29,10 +29,10 @@ package network;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
import resources.SortedLinkedList;
import network.encryption.Encryption;
import network.packets.Packet;
import network.packets.soe.DataChannelA;
@@ -47,13 +47,13 @@ public class OutboundNetworkHandler {
private static final long RESEND_TIMEOUT = TimeUnit.MILLISECONDS.toMillis(3000);
private final Queue <byte []> assembleQueue;
private final SortedLinkedList <SequencedPacket> sequenced;
private final Queue <SequencedPacket> sequenced;
private short sendSequence;
private int crc;
public OutboundNetworkHandler() {
assembleQueue = new LinkedList<byte []>();
sequenced = new SortedLinkedList<SequencedPacket>();
sequenced = new PriorityQueue<SequencedPacket>();
sendSequence = 0;
crc = 0;
}
@@ -79,8 +79,8 @@ public class OutboundNetworkHandler {
public synchronized void onAcknowledge(short sequence) {
synchronized (sequenced) {
Iterator <SequencedPacket> it = sequenced.listIterator();
while (it.hasNext()) {
Iterator <SequencedPacket> it = sequenced.iterator();
while(it.hasNext()) {
SequencedPacket sp = it.next();
if (sp.getSequence() <= sequence) {
it.remove();
@@ -96,7 +96,7 @@ public class OutboundNetworkHandler {
public synchronized void onOutOfOrder(short sequence) {
synchronized (sequenced) {
Iterator <SequencedPacket> it = sequenced.listIterator();
Iterator <SequencedPacket> it = sequenced.iterator();
while (it.hasNext()) {
SequencedPacket sp = it.next();
if (sp.getSequence() > sequence) {
-77
View File
@@ -1,77 +0,0 @@
/***********************************************************************************
* Copyright (c) 2015 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* -------------------------------------------------------------------------------- *
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
* *
***********************************************************************************/
package resources;
import java.util.Collection;
import java.util.LinkedList;
import java.util.ListIterator;
public class SortedLinkedList<E extends Comparable<E>> extends LinkedList<E> {
private static final long serialVersionUID = -6776628467181994889L;
@Override
public boolean add(E e) {
ListIterator<E> iter = super.listIterator();
while (iter.hasNext()) {
if (e.compareTo(iter.next()) <= 0) {
iter.previous();
iter.add(e);
return true;
}
}
super.addLast(e);
return true;
}
@Override
public void add(int index, E element) {
throw new UnsupportedOperationException("The sorted nature of the list prohibits this action.");
}
@Override
public boolean addAll(Collection<? extends E> c) {
for (E item : c) {
add(item);
}
return true;
}
@Override
public boolean addAll(int index, Collection<? extends E> c) {
throw new UnsupportedOperationException("The sorted nature of the list prohibits this action.");
}
@Override
public E set(int index, E element) {
throw new UnsupportedOperationException("The sorted nature of the list prohibits this action.");
}
}
-1
View File
@@ -39,7 +39,6 @@ import resources.services.TestConfig;
@RunWith(Suite.class)
@SuiteClasses({
SWGListTest.class,
TestSortedLinkedList.class,
TestWeatherType.class,
TestQuadTree.class,
TestObjectDatabase.class,
-59
View File
@@ -1,59 +0,0 @@
/***********************************************************************************
* Copyright (c) 2015 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
* Our goal is to create an emulator which will provide a server for players to *
* continue playing a game similar to the one they used to play. We are basing *
* it on the final publish of the game prior to end-game events. *
* *
* This file is part of Holocore. *
* *
* -------------------------------------------------------------------------------- *
* *
* Holocore is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Holocore is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
* *
***********************************************************************************/
package resources;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.junit.Test;
public class TestSortedLinkedList {
/**
* Characters are compared by numerical value and they
* should therefore be stored in such order within the list.
*/
@Test
public void testSorting() {
SortedLinkedList<Character> list = new SortedLinkedList<>();
final char testchar1 = 'a';
final char testchar2 = 'b';
final char testchar3 = 'c';
Iterator<Character> it;
list.add(testchar2);
list.add(testchar3);
list.add(testchar1);
it = list.listIterator();
assertTrue(it.next().equals(testchar1));
assertTrue(it.next().equals(testchar2));
assertTrue(it.next().equals(testchar3));
}
}