From e053e3af9505d330c37b9223dd8381e0dacff127 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 1 Mar 2017 00:25:08 +0100 Subject: [PATCH] Minor changes - Reorder modifiers - Private constructor to avoid instantiation Change-Id: I201648759962387c40e8f62960db16e530612e70 Signed-off-by: David --- .../aaa/AuthenticationManager.java | 4 ++-- .../java/org/opendaylight/aaa/EqualUtil.java | 18 +++++++++++------- .../org/opendaylight/aaa/HashCodeUtil.java | 9 ++++++--- .../aaa/SecureBlockingQueueTest.java | 15 ++++++++------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/aaa-authn/src/main/java/org/opendaylight/aaa/AuthenticationManager.java b/aaa-authn/src/main/java/org/opendaylight/aaa/AuthenticationManager.java index 5f6420a3d..8b7e133e7 100644 --- a/aaa-authn/src/main/java/org/opendaylight/aaa/AuthenticationManager.java +++ b/aaa-authn/src/main/java/org/opendaylight/aaa/AuthenticationManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. and others. All rights reserved. + * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -31,7 +31,7 @@ public class AuthenticationManager implements AuthenticationService, ManagedServ // In non-Karaf environments, authEnabled is set to false by default private static volatile boolean authEnabled = false; - private final static AuthenticationManager am = new AuthenticationManager(); + private static final AuthenticationManager am = new AuthenticationManager(); private final ThreadLocal auth = new InheritableThreadLocal<>(); private AuthenticationManager() { diff --git a/aaa-authn/src/main/java/org/opendaylight/aaa/EqualUtil.java b/aaa-authn/src/main/java/org/opendaylight/aaa/EqualUtil.java index 17204d0e3..4c6ff1044 100644 --- a/aaa-authn/src/main/java/org/opendaylight/aaa/EqualUtil.java +++ b/aaa-authn/src/main/java/org/opendaylight/aaa/EqualUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. and others. All rights reserved. + * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -16,27 +16,31 @@ package org.opendaylight.aaa; * Arrays.equals methods should be used for array fields. */ public final class EqualUtil { - static public boolean areEqual(boolean aThis, boolean aThat) { + + private EqualUtil () { + } + + public static boolean areEqual(boolean aThis, boolean aThat) { return aThis == aThat; } - static public boolean areEqual(char aThis, char aThat) { + public static boolean areEqual(char aThis, char aThat) { return aThis == aThat; } - static public boolean areEqual(long aThis, long aThat) { + public static boolean areEqual(long aThis, long aThat) { return aThis == aThat; } - static public boolean areEqual(float aThis, float aThat) { + public static boolean areEqual(float aThis, float aThat) { return Float.floatToIntBits(aThis) == Float.floatToIntBits(aThat); } - static public boolean areEqual(double aThis, double aThat) { + public static boolean areEqual(double aThis, double aThat) { return Double.doubleToLongBits(aThis) == Double.doubleToLongBits(aThat); } - static public boolean areEqual(Object aThis, Object aThat) { + public static boolean areEqual(Object aThis, Object aThat) { return aThis == null ? aThat == null : aThis.equals(aThat); } } diff --git a/aaa-authn/src/main/java/org/opendaylight/aaa/HashCodeUtil.java b/aaa-authn/src/main/java/org/opendaylight/aaa/HashCodeUtil.java index c295b3ed2..bb4311834 100644 --- a/aaa-authn/src/main/java/org/opendaylight/aaa/HashCodeUtil.java +++ b/aaa-authn/src/main/java/org/opendaylight/aaa/HashCodeUtil.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. and others. All rights reserved. + * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -35,6 +35,9 @@ public final class HashCodeUtil { */ public static final int SEED = 23; + private HashCodeUtil() { + } + /** booleans. */ public static int hash(int aSeed, boolean aBoolean) { return firstTerm(aSeed) + (aBoolean ? 1 : 0); @@ -52,7 +55,7 @@ public final class HashCodeUtil { /** longs. */ public static int hash(int aSeed, long aLong) { - return firstTerm(aSeed) + (int) (aLong ^ (aLong >>> 32)); + return firstTerm(aSeed) + (int) (aLong ^ aLong >>> 32); } /** floats. */ @@ -101,4 +104,4 @@ public final class HashCodeUtil { private static boolean isArray(Object aObject) { return aObject.getClass().isArray(); } -} \ No newline at end of file +} diff --git a/aaa-authn/src/test/java/org/opendaylight/aaa/SecureBlockingQueueTest.java b/aaa-authn/src/test/java/org/opendaylight/aaa/SecureBlockingQueueTest.java index 16627d9f2..3655983b0 100644 --- a/aaa-authn/src/test/java/org/opendaylight/aaa/SecureBlockingQueueTest.java +++ b/aaa-authn/src/test/java/org/opendaylight/aaa/SecureBlockingQueueTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved. + * Copyright (c) 2014, 2017 Hewlett-Packard Development Company, L.P. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -30,7 +30,7 @@ import org.opendaylight.aaa.SecureBlockingQueue.SecureData; import org.opendaylight.aaa.api.Authentication; public class SecureBlockingQueueTest { - private final int MAX_TASKS = 100; + private static final int MAX_TASKS = 100; @Before public void setup() { @@ -53,7 +53,7 @@ public class SecureBlockingQueueTest { @Test public void testNormalThreadPoolExecutor() throws InterruptedException, ExecutionException { - BlockingQueue queue = new ArrayBlockingQueue(10); + BlockingQueue queue = new ArrayBlockingQueue<>(10); ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 500, TimeUnit.MILLISECONDS, queue); executor.prestartAllCoreThreads(); @@ -84,11 +84,13 @@ public class SecureBlockingQueueTest { public void testCollectionOps() throws InterruptedException, ExecutionException { BlockingQueue queue = new SecureBlockingQueue<>( new ArrayBlockingQueue>(6)); - for (int i = 1; i <= 3; i++) + for (int i = 1; i <= 3; i++) { queue.add("User" + i); + } Iterator it = queue.iterator(); - while (it.hasNext()) + while (it.hasNext()) { assertTrue(it.next().startsWith("User")); + } assertEquals(3, queue.toArray().length); List actual = Arrays.asList(queue.toArray(new String[0])); assertEquals("User1", actual.iterator().next()); @@ -184,8 +186,7 @@ public class SecureBlockingQueueTest { public String call() { queue.remove(); Authentication auth = AuthenticationManager.instance().get(); - return (auth == null) ? null : auth.user(); + return auth == null ? null : auth.user(); } } - } -- 2.36.6