Skip to content
Snippets Groups Projects
Commit 11065816 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

removed some more pmd issues

parent ee0a3e8a
No related branches found
No related tags found
No related merge requests found
Showing
with 72 additions and 73 deletions
......@@ -82,8 +82,8 @@ public final class CipherStage extends AbstractConsumerStage<byte[]> {
@Override
protected void execute(final byte[] element) {
try {
byte[] output = this.cipher.doFinal(element);
this.outputPort.send(output);
byte[] outputBytes = this.cipher.doFinal(element);
this.outputPort.send(outputBytes);
} catch (IllegalBlockSizeException e) {
throw new IllegalStateException(e);
} catch (BadPaddingException e) {
......
......@@ -45,17 +45,17 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> {
@Override
protected void execute(final byte[] element) {
byte[] cache = null;
byte[] streamBytes = null;
try {
if (mode == ZipMode.COMP) {
cache = compress(element);
streamBytes = compress(element);
} else {
cache = decompress(element);
streamBytes = decompress(element);
}
} catch (Exception e) {
e.printStackTrace();
}
outputPort.send(cache);
outputPort.send(streamBytes);
}
private byte[] compress(final byte[] data) throws IOException {
......@@ -65,17 +65,17 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
deflater.finish();
byte[] buffer = new byte[1024];
byte[] buffer = new byte[1024]; // NOPMD
while (!deflater.finished()) {
int count = deflater.deflate(buffer); // returns the generated code... index
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte[] output = outputStream.toByteArray();
byte[] outputBytes = outputStream.toByteArray();
deflater.end();
return output;
return outputBytes;
}
private byte[] decompress(final byte[] data) throws IOException, DataFormatException {
......@@ -83,17 +83,17 @@ public final class ZipByteArray extends AbstractConsumerStage<byte[]> {
inflater.setInput(data);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
byte[] buffer = new byte[1024];
byte[] buffer = new byte[1024]; // NOPMD
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte[] output = outputStream.toByteArray();
byte[] outputBytes = outputStream.toByteArray();
inflater.end();
return output;
return outputBytes;
}
public OutputPort<? extends byte[]> getOutputPort() {
......
......@@ -44,6 +44,10 @@ public final class CyclicListIterator<T> implements Iterator<T> {
@Override
public T next() {
this.currentIndex = this.getCurrentIndex();
final T element = this.elements.get(this.currentIndex);
this.currentIndex++;
return element;
// if (!this.iterator.hasNext()) {
// this.iterator = this.list.iterator();
// }
......@@ -52,17 +56,13 @@ public final class CyclicListIterator<T> implements Iterator<T> {
// the size of the list could have been changed due to
// <li>an index overflow (then restart from index 0), or
// <li>an add() or a remove(), so update the index
this.currentIndex = this.getCurrentIndex();
final T element = this.elements.get(this.currentIndex);
this.currentIndex++;
return element;
}
@Override
public void remove() {
// this.iterator.remove();
this.currentIndex = this.getCurrentIndex();
this.elements.remove(this.currentIndex);
// this.iterator.remove();
}
private int getCurrentIndex() {
......
......@@ -30,12 +30,12 @@ public final class FileSearcher {
}
public static List<URL> loadResources(final String name) throws IOException {
final List<URL> list = new ArrayList<URL>();
final List<URL> urls = new ArrayList<URL>();
final Enumeration<URL> systemRes = CLASS_LOADER.getResources(name);
while (systemRes.hasMoreElements()) {
list.add(systemRes.nextElement());
urls.add(systemRes.nextElement());
}
return list;
return urls;
}
}
......@@ -26,9 +26,9 @@ public final class SCParkTakeStrategy<E> implements TakeStrategy<E> {
private final AtomicReference<Thread> t = new AtomicReference<Thread>(null);
@Override
// Make sure the offer is visible before unpark
public void signal()
{
// Make sure the offer is visible before unpark
storeFence = 1; // store barrier
LockSupport.unpark(t.get()); // t.get() load barrier
......
......@@ -59,6 +59,7 @@ public final class CircularWorkStealingDequeWithSentinel<T> {
private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE);
private boolean casTop(final long oldVal, final long newVal) {
return this.top.compareAndSet(oldVal, newVal);
// boolean preCond;
// synchronized (this) {
// preCond = (this.top == oldVal);
......@@ -67,7 +68,6 @@ public final class CircularWorkStealingDequeWithSentinel<T> {
// }
// }
// return preCond;
return this.top.compareAndSet(oldVal, newVal);
}
public void pushBottom(final T o) {
......
......@@ -71,6 +71,7 @@ public final class CircularWorkStealingDequeWithThreadLocalSentinel<T> {
}
private boolean casTop(final long oldVal, final long newVal) {
return this.top.compareAndSet(oldVal, newVal);
// boolean preCond;
// synchronized (this) {
// preCond = (this.top == oldVal);
......@@ -79,7 +80,6 @@ public final class CircularWorkStealingDequeWithThreadLocalSentinel<T> {
// }
// }
// return preCond;
return this.top.compareAndSet(oldVal, newVal);
}
public void pushBottom(final T o) {
......
......@@ -43,6 +43,7 @@ public final class ExceptionalCircularWorkStealingDeque<T> {
private volatile CircularArray<T> activeArray = new CircularArray<T>(LOG_INITIAL_SIZE);
private boolean casTop(final long oldVal, final long newVal) {
return this.top.compareAndSet(oldVal, newVal);
// boolean preCond;
// synchronized (this) {
// preCond = (this.top == oldVal);
......@@ -51,7 +52,6 @@ public final class ExceptionalCircularWorkStealingDeque<T> {
// }
// }
// return preCond;
return this.top.compareAndSet(oldVal, newVal);
}
public void pushBottom(final T o) {
......
......@@ -39,6 +39,7 @@ public final class UntypedCircularWorkStealingDeque {
private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE);
private boolean casTop(final long oldVal, final long newVal) {
return this.top.compareAndSet(oldVal, newVal);
// boolean preCond;
// synchronized (this) {
// preCond = (this.top == oldVal);
......@@ -47,7 +48,6 @@ public final class UntypedCircularWorkStealingDeque {
// }
// }
// return preCond;
return this.top.compareAndSet(oldVal, newVal);
}
public void pushBottom(final Object o) {
......
......@@ -44,6 +44,7 @@ public final class UntypedExceptionalCircularWorkStealingDeque {
private volatile CircularArray<Object> activeArray = new CircularArray<Object>(LOG_INITIAL_SIZE);
private boolean casTop(final long oldVal, final long newVal) {
return this.top.compareAndSet(oldVal, newVal);
// boolean preCond;
// synchronized (this) {
// preCond = (this.top == oldVal);
......@@ -52,7 +53,6 @@ public final class UntypedExceptionalCircularWorkStealingDeque {
// }
// }
// return preCond;
return this.top.compareAndSet(oldVal, newVal);
}
public void pushBottom(final Object o) {
......
......@@ -51,16 +51,16 @@ public final class CommittableResizableArrayQueue<T> implements CommittableQueue
@Override
public T removeFromHeadUncommitted() {
T element = this.get(--this.lastFreeIndexUncommitted);
// if (this.capacity() > this.MIN_CAPACITY && this.lastFreeIndexUncommitted < this.capacity() / 2) { // TODO uncomment
// this.shrink();
// }
T element = this.get(--this.lastFreeIndexUncommitted);
return element;
}
@Override
// TODO set elements to null to help the gc
public void commit() {
// TODO set elements to null to help the gc
this.lastFreeIndex = this.lastFreeIndexUncommitted;
}
......@@ -109,10 +109,10 @@ public final class CommittableResizableArrayQueue<T> implements CommittableQueue
}
private final void copyArray(final T[] elements, final T[] newElements) {
System.arraycopy(elements, 0, newElements, 0, this.lastFreeIndexUncommitted + 1);
// for (int i = 0; i < this.lastFreeIndexUncommitted; i++) {
// newElements[i] = elements[i];
// }
System.arraycopy(elements, 0, newElements, 0, this.lastFreeIndexUncommitted + 1);
}
private final void put(final int index, final T element) {
......
......@@ -20,7 +20,7 @@ import java.util.List;
public final class ListContainerPool<T> implements ObjectPool<ListContainer<T>> {
private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>();
private final List<ListContainer<T>> pool = new ArrayList<ListContainer<T>>(); // NOPMD
public ListContainerPool(int initialPoolSize) {
while (initialPoolSize-- > 0) {
......
......@@ -38,8 +38,7 @@ public class TokenizerTest {
@Test
public void executeTest() throws IOException {
// Encrypted lorem ipsum
final String inputFile = "src/test/resources/data/cipherInput.txt";
final String inputFile = "src/test/resources/data/cipherInput.txt"; // Encrypted lorem ipsum
final String password = "Password";
final TokenizerConfiguration configuration = new TokenizerConfiguration(inputFile, password);
......
......@@ -41,11 +41,11 @@ public class TraversorTest {
public void traverse() {
TestConfiguration tc = new TestConfiguration();
traversor.traverse(tc.init);
Set<Stage> comparingSet = new HashSet<Stage>();
comparingSet.add(tc.init);
comparingSet.add(tc.f2b);
comparingSet.add(tc.distributor);
assertTrue(comparingSet.equals(traversor.getVisitedStage()));
Set<Stage> comparingStages = new HashSet<Stage>();
comparingStages.add(tc.init);
comparingStages.add(tc.f2b);
comparingStages.add(tc.distributor);
assertTrue(comparingStages.equals(traversor.getVisitedStage()));
}
// WordCounterConfiguration
......
......@@ -35,15 +35,15 @@ public class PipeFactoryLoaderTest {
@Test
public void emptyConfig() throws IOException {
final List<IPipeFactory> list = PipeFactoryLoader.loadPipeFactoriesFromClasspath("data/empty-test.conf");
Assert.assertEquals(true, list.isEmpty());
final List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadPipeFactoriesFromClasspath("data/empty-test.conf");
Assert.assertEquals(true, pipeFactories.isEmpty());
}
@Test
public void singleConfig() throws IOException {
final List<IPipeFactory> list = PipeFactoryLoader.loadPipeFactoriesFromClasspath("pipe-factories.conf");
final List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadPipeFactoriesFromClasspath("pipe-factories.conf");
final int lines = Files.readLines(new File("target/classes/pipe-factories.conf"), Charsets.UTF_8).size();
Assert.assertEquals(lines, list.size());
Assert.assertEquals(lines, pipeFactories.size());
}
@Test
......
......@@ -36,14 +36,14 @@ public class CipherStageTest {
final CipherStage encryptStage = new CipherStage("somePassword", CipherMode.ENCRYPT);
final CipherStage decryptStage = new CipherStage("somePassword", CipherMode.DECRYPT);
final byte[] input = new byte[] { 1, 2, 3, 4, 5 };
final List<byte[]> encryptedResult = new ArrayList<byte[]>();
final List<byte[]> decryptedResult = new ArrayList<byte[]>();
final byte[] inputBytes = new byte[] { 1, 2, 3, 4, 5 };
final List<byte[]> encryptedBytes = new ArrayList<byte[]>();
final List<byte[]> decryptedBytes = new ArrayList<byte[]>();
test(encryptStage).and().send(input).to(encryptStage.getInputPort()).and().receive(encryptedResult).from(encryptStage.getOutputPort()).start();
test(decryptStage).and().send(encryptedResult).to(decryptStage.getInputPort()).and().receive(decryptedResult).from(decryptStage.getOutputPort()).start();
test(encryptStage).and().send(inputBytes).to(encryptStage.getInputPort()).and().receive(encryptedBytes).from(encryptStage.getOutputPort()).start();
test(decryptStage).and().send(encryptedBytes).to(decryptStage.getInputPort()).and().receive(decryptedBytes).from(decryptStage.getOutputPort()).start();
assertThat(decryptedResult, contains(input));
assertThat(decryptedBytes, contains(inputBytes));
}
}
......@@ -87,11 +87,11 @@ public class InitialElementProducerTest {
@Test
public void instantiateWithIterable() {
List<Integer> test = new ArrayList<Integer>();
test.add(1);
test.add(2);
test.add(3);
producer = new InitialElementProducer<Integer>(test);
List<Integer> testIntegers = new ArrayList<Integer>();
testIntegers.add(1);
testIntegers.add(2);
testIntegers.add(3);
producer = new InitialElementProducer<Integer>(testIntegers);
List<Integer> results = new ArrayList<Integer>();
test(producer).and().receive(results).from(producer.getOutputPort()).start();
......
......@@ -66,15 +66,15 @@ public class InstanceCounterTest {
@Test
public void filterShouldWorkWithMultipleInput() {
final List<Object> input = new ArrayList<Object>();
final List<Object> inputObjects = new ArrayList<Object>();
input.add(new Object());
input.add(new Clazz());
input.add(new Object());
input.add(new SubClazz());
input.add(new Object());
inputObjects.add(new Object());
inputObjects.add(new Clazz());
inputObjects.add(new Object());
inputObjects.add(new SubClazz());
inputObjects.add(new Object());
test(this.filter).and().send(input).to(this.filter.getInputPort()).start();
test(this.filter).and().send(inputObjects).to(this.filter.getInputPort()).start();
assertThat(this.filter.getCounter(), is(2));
}
......
......@@ -88,16 +88,16 @@ public class InstanceOfFilterTest {
@Test
public void filterShouldWorkWithMultipleInput() {
final List<Clazz> results = new ArrayList<InstanceOfFilterTest.Clazz>();
final List<Object> input = new ArrayList<Object>();
final List<Object> inputObjects = new ArrayList<Object>();
input.add(new Object());
input.add(new Clazz());
input.add(new Object());
input.add(new SubClazz());
input.add(new Object());
inputObjects.add(new Object());
inputObjects.add(new Clazz());
inputObjects.add(new Object());
inputObjects.add(new SubClazz());
inputObjects.add(new Object());
test(filter)
.and().send(input).to(filter.getInputPort())
.and().send(inputObjects).to(filter.getInputPort())
.and().receive(results).from(filter.getMatchedOutputPort())
.start();
......
......@@ -39,24 +39,24 @@ public class MultipleInstanceOfFilterTest {
@SuppressWarnings("unchecked")
public void filteringForSingleTypeShouldWork() {
final MultipleInstanceOfFilter<Object> filter = new MultipleInstanceOfFilter<Object>();
final List<Object> input = new ArrayList<Object>(Arrays.asList("1", 1.5f, "2", 2.5f, "3", 3.5f));
final List<String> result = new ArrayList<String>();
final List<Object> inputObjects = new ArrayList<Object>(Arrays.asList("1", 1.5f, "2", 2.5f, "3", 3.5f));
final List<String> receivedStrings = new ArrayList<String>();
StageTester.test(filter).and().send(input).to(filter.getInputPort()).and().receive(result).from(filter.getOutputPortForType(String.class)).start();
StageTester.test(filter).and().send(inputObjects).to(filter.getInputPort()).and().receive(receivedStrings).from(filter.getOutputPortForType(String.class)).start();
assertThat(result, is(not(empty())));
assertThat(result, contains("1", "2", "3"));
assertThat(receivedStrings, is(not(empty())));
assertThat(receivedStrings, contains("1", "2", "3"));
}
@Test
@SuppressWarnings("unchecked")
public void filteringForMultipleTypesShouldWork() {
final MultipleInstanceOfFilter<Number> filter = new MultipleInstanceOfFilter<Number>();
final List<Number> input = new ArrayList<Number>(Arrays.asList(1, 1.5f, 2, 2.5f, 3, 3.5f));
final List<Number> inputObjects = new ArrayList<Number>(Arrays.asList(1, 1.5f, 2, 2.5f, 3, 3.5f));
final List<Integer> integers = new ArrayList<Integer>();
final List<Float> floats = new ArrayList<Float>();
StageTester.test(filter).and().send(input).to(filter.getInputPort()).and().receive(integers).from(filter.getOutputPortForType(Integer.class)).and()
StageTester.test(filter).and().send(inputObjects).to(filter.getInputPort()).and().receive(integers).from(filter.getOutputPortForType(Integer.class)).and()
.receive(floats).from(filter.getOutputPortForType(Float.class)).start();
assertThat(integers, contains(1, 2, 3));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment