Code-inspection fixes

Motivation:

Saw some code-inspection warnings

Modifications:

Fix warnings

Result:

Less code-inspection warnings
This commit is contained in:
Norman Maurer 2014-08-21 07:20:00 +02:00
parent ceaab70153
commit 16a8f8b5aa
4 changed files with 18 additions and 20 deletions

View File

@ -112,7 +112,8 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
values[index] = toInternal(value); values[index] = toInternal(value);
growSize(); growSize();
return null; return null;
} else if (keys[index] == key) { }
if (keys[index] == key) {
// Found existing entry with this key, just replace the value. // Found existing entry with this key, just replace the value.
V previousValue = values[index]; V previousValue = values[index];
values[index] = toInternal(value); values[index] = toInternal(value);
@ -246,7 +247,7 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
// of terms, only their values; since the map is an unordered collection and // of terms, only their values; since the map is an unordered collection and
// entries can end up in different positions in different maps that have the same // entries can end up in different positions in different maps that have the same
// elements, but with different history of puts/removes, due to conflicts. // elements, but with different history of puts/removes, due to conflicts.
hash = hash ^ keys[i]; hash ^= keys[i];
} }
return hash; return hash;
} }
@ -255,7 +256,8 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} else if (!(obj instanceof IntObjectMap)) { }
if (!(obj instanceof IntObjectMap)) {
return false; return false;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ -294,7 +296,8 @@ public class IntObjectHashMap<V> implements IntObjectMap<V>, Iterable<IntObjectM
if (values[index] == null) { if (values[index] == null) {
// It's available, so no chance that this value exists anywhere in the map. // It's available, so no chance that this value exists anywhere in the map.
return -1; return -1;
} else if (key == keys[index]) { }
if (key == keys[index]) {
return index; return index;
} }

View File

@ -49,7 +49,7 @@ public final class DefaultExecutorFactory implements ExecutorFactory {
InternalLoggerFactory.getInstance(DefaultExecutorFactory.class); InternalLoggerFactory.getInstance(DefaultExecutorFactory.class);
private static final AtomicInteger executorId = new AtomicInteger(); private static final AtomicInteger executorId = new AtomicInteger();
private String namePrefix; private final String namePrefix;
/** /**
* @param clazzNamePrefix the name of the class will be used to prefix the name of each * @param clazzNamePrefix the name of the class will be used to prefix the name of each
@ -69,7 +69,7 @@ public final class DefaultExecutorFactory implements ExecutorFactory {
@Override @Override
public Executor newExecutor(int parallelism) { public Executor newExecutor(int parallelism) {
ForkJoinWorkerThreadFactory threadFactory = ForkJoinWorkerThreadFactory threadFactory =
new DefaultForkJoinWorkerThreadFactory(namePrefix + "-" + executorId.getAndIncrement()); new DefaultForkJoinWorkerThreadFactory(namePrefix + '-' + executorId.getAndIncrement());
return new ForkJoinPool(parallelism, threadFactory, DefaultUncaughtExceptionHandler.INSTANCE, true); return new ForkJoinPool(parallelism, threadFactory, DefaultUncaughtExceptionHandler.INSTANCE, true);
} }
@ -119,7 +119,7 @@ public final class DefaultExecutorFactory implements ExecutorFactory {
public ForkJoinWorkerThread newThread(ForkJoinPool pool) { public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
// Note: The ForkJoinPool will create these threads as daemon threads. // Note: The ForkJoinPool will create these threads as daemon threads.
ForkJoinWorkerThread thread = new DefaultForkJoinWorkerThread(pool); ForkJoinWorkerThread thread = new DefaultForkJoinWorkerThread(pool);
thread.setName(namePrefix + "-" + idx.getAndIncrement()); thread.setName(namePrefix + '-' + idx.getAndIncrement());
thread.setPriority(Thread.MAX_PRIORITY); thread.setPriority(Thread.MAX_PRIORITY);
return thread; return thread;
} }

View File

@ -64,11 +64,6 @@ final class ScheduledFutureTask<V> extends PromiseTask<V> implements ScheduledFu
periodNanos = 0; periodNanos = 0;
} }
@Override
protected EventExecutor executor() {
return executor;
}
public long deadlineNanos() { public long deadlineNanos() {
return deadlineNanos; return deadlineNanos;
} }
@ -174,8 +169,8 @@ final class ScheduledFutureTask<V> extends PromiseTask<V> implements ScheduledFu
*/ */
private boolean needsLaterExecution() { private boolean needsLaterExecution() {
return task instanceof CallableEventExecutorAdapter && return task instanceof CallableEventExecutorAdapter &&
((CallableEventExecutorAdapter) task).executor() instanceof PausableEventExecutor && ((CallableEventExecutorAdapter<?>) task).executor() instanceof PausableEventExecutor &&
!((PausableEventExecutor) ((CallableEventExecutorAdapter) task).executor()).isAcceptingNewTasks(); !((PausableEventExecutor) ((CallableEventExecutorAdapter<?>) task).executor()).isAcceptingNewTasks();
} }
/** /**
@ -185,11 +180,11 @@ final class ScheduledFutureTask<V> extends PromiseTask<V> implements ScheduledFu
private boolean isMigrationPending() { private boolean isMigrationPending() {
return !isCancelled() && return !isCancelled() &&
task instanceof CallableEventExecutorAdapter && task instanceof CallableEventExecutorAdapter &&
executor() != ((CallableEventExecutorAdapter) task).executor().unwrap(); executor() != ((CallableEventExecutorAdapter<?>) task).executor().unwrap();
} }
private void scheduleWithNewExecutor() { private void scheduleWithNewExecutor() {
EventExecutor newExecutor = ((CallableEventExecutorAdapter) task).executor().unwrap(); EventExecutor newExecutor = ((CallableEventExecutorAdapter<?>) task).executor().unwrap();
if (newExecutor instanceof SingleThreadEventExecutor) { if (newExecutor instanceof SingleThreadEventExecutor) {
if (!newExecutor.isShutdown()) { if (!newExecutor.isShutdown()) {

View File

@ -820,15 +820,15 @@ public abstract class SingleThreadEventExecutor extends AbstractEventExecutor {
if (command instanceof RunnableEventExecutorAdapter) { if (command instanceof RunnableEventExecutorAdapter) {
return new RunnableToCallableAdapter((RunnableEventExecutorAdapter) command); return new RunnableToCallableAdapter((RunnableEventExecutorAdapter) command);
} else { } else {
return Executors.<Void>callable(command, null); return Executors.callable(command, null);
} }
} }
protected void cleanupAndTerminate(boolean success) { protected void cleanupAndTerminate(boolean success) {
for (;;) { for (;;) {
int oldState = STATE_UPDATER.get(SingleThreadEventExecutor.this); int oldState = STATE_UPDATER.get(this);
if (oldState >= ST_SHUTTING_DOWN || STATE_UPDATER.compareAndSet( if (oldState >= ST_SHUTTING_DOWN || STATE_UPDATER.compareAndSet(
SingleThreadEventExecutor.this, oldState, ST_SHUTTING_DOWN)) { this, oldState, ST_SHUTTING_DOWN)) {
break; break;
} }
} }
@ -851,7 +851,7 @@ public abstract class SingleThreadEventExecutor extends AbstractEventExecutor {
try { try {
cleanup(); cleanup();
} finally { } finally {
STATE_UPDATER.set(SingleThreadEventExecutor.this, ST_TERMINATED); STATE_UPDATER.set(this, ST_TERMINATED);
threadLock.release(); threadLock.release();
if (!taskQueue.isEmpty()) { if (!taskQueue.isEmpty()) {
logger.warn( logger.warn(