Skip to content

Commit

Permalink
Update code style (#1121)
Browse files Browse the repository at this point in the history
* Update style guide

* Reapply style guide

This reverts commit 8a5099f.

* Fix test after code style update
  • Loading branch information
devinrsmith authored Aug 25, 2021
1 parent a7a0454 commit 86319e2
Show file tree
Hide file tree
Showing 2,426 changed files with 63,787 additions and 82,644 deletions.
36 changes: 14 additions & 22 deletions Base/src/main/java/io/deephaven/base/ArrayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public static <T> T[] deleteArrayPos(int i, T[] a) {
assert a != null && i < a.length;
T[] new_a = null;
if (a.length > 1) {
new_a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(),
a.length - 1);
new_a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), a.length - 1);
System.arraycopy(a, 0, new_a, 0, i);
System.arraycopy(a, i + 1, new_a, i, a.length - (i + 1));
}
Expand Down Expand Up @@ -182,8 +181,7 @@ public static <T> boolean replaceInArray(T e, T[] a) {
return false;
}

public static <T> T[] addUnless(T[] a, Class<T> c, Predicate.Unary<T> pred,
Function.Nullary<T> factory) {
public static <T> T[] addUnless(T[] a, Class<T> c, Predicate.Unary<T> pred, Function.Nullary<T> factory) {
if (a != null) {
for (int i = 0; i < a.length; ++i) {
if (pred.call(a[i])) {
Expand All @@ -194,8 +192,8 @@ public static <T> T[] addUnless(T[] a, Class<T> c, Predicate.Unary<T> pred,
return pushArray(factory.call(), a, c);
}

public static <T, A> T[] addUnless(T[] a, Class<T> c, Predicate.Binary<T, A> pred,
Function.Unary<T, A> factory, A arg) {
public static <T, A> T[] addUnless(T[] a, Class<T> c, Predicate.Binary<T, A> pred, Function.Unary<T, A> factory,
A arg) {
if (a != null) {
for (int i = 0; i < a.length; ++i) {
if (pred.call(a[i], arg)) {
Expand All @@ -206,8 +204,8 @@ public static <T, A> T[] addUnless(T[] a, Class<T> c, Predicate.Binary<T, A> pre
return pushArray(factory.call(arg), a, c);
}

public static <T, A> T[] replaceOrAdd(T[] a, Class<T> c, Predicate.Binary<T, A> pred,
Function.Unary<T, A> factory, A arg) {
public static <T, A> T[] replaceOrAdd(T[] a, Class<T> c, Predicate.Binary<T, A> pred, Function.Unary<T, A> factory,
A arg) {
if (a != null) {
for (int i = 0; i < a.length; ++i) {
if (pred.call(a[i], arg)) {
Expand Down Expand Up @@ -663,18 +661,15 @@ public static <T> T[] insert(T[] a, int i, T v, Class<? extends T> c) {
return newArray;
}

public static <T> T[] insert(T[] a, int insertionPoint, int numElements, T v,
Class<? extends T> c) {
public static <T> T[] insert(T[] a, int insertionPoint, int numElements, T v, Class<? extends T> c) {
if (a.length < numElements + 1) {
T[] a2 = extendNoCopy(a, numElements, c);
System.arraycopy(a, 0, a2, 0, insertionPoint);
a2[insertionPoint] = v;
System.arraycopy(a, insertionPoint, a2, insertionPoint + 1,
numElements - insertionPoint);
System.arraycopy(a, insertionPoint, a2, insertionPoint + 1, numElements - insertionPoint);
return a2;
} else {
System.arraycopy(a, insertionPoint, a, insertionPoint + 1,
numElements - insertionPoint);
System.arraycopy(a, insertionPoint, a, insertionPoint + 1, numElements - insertionPoint);
a[insertionPoint] = v;
return a;
}
Expand Down Expand Up @@ -1281,8 +1276,7 @@ public static int hashCodeAnyOrderAnySign(double a[], int min, int length) {
return result;
}

public static <K, V> Map<K, V> mapFromArray(Class<K> keyType, Class<V> valueType,
Object... data) {
public static <K, V> Map<K, V> mapFromArray(Class<K> keyType, Class<V> valueType, Object... data) {
Map<K, V> map = new HashMap<K, V>(data.length);
for (int nIndex = 0; nIndex < data.length; nIndex += 2) {
Object key = data[nIndex];
Expand Down Expand Up @@ -1332,8 +1326,7 @@ public static String toString(long[] longs, int nOffset, int nLength) {
}
}

public static StringBuilder appendIntArray(final StringBuilder sb, final int[] vs,
final boolean compact) {
public static StringBuilder appendIntArray(final StringBuilder sb, final int[] vs, final boolean compact) {
for (int i = 0; i < vs.length; ++i) {
if (i != 0) {
if (compact) {
Expand Down Expand Up @@ -1446,13 +1439,12 @@ public static boolean isSorted(double[] doubles) {
public static <T extends Comparable<? super T>> boolean isSorted(T[] objects) {
if (objects != null && objects.length >= 2) {
for (int i = 1; i < objects.length; i++) {
// if the previous one is null it's either smaller or equal to the next 'null' and
// therefore sorted
// if the previous one is null it's either smaller or equal to the next 'null' and therefore sorted
if ((objects[i - 1] == null)) {
continue;
}
// if the later element is null (previous one cannot be) then its out of order,
// otherwise compare values (o1 < o2 == negative integer)
// if the later element is null (previous one cannot be) then its out of order, otherwise compare values
// (o1 < o2 == negative integer)
if (objects[i] == null || objects[i].compareTo(objects[i - 1]) < 0) {
return false;
}
Expand Down
41 changes: 19 additions & 22 deletions Base/src/main/java/io/deephaven/base/Base64.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static String byteArrayToBase64(byte[] a) {
}

/**
* Translates the specified byte array into an "alternate representation" Base64 string. This
* non-standard variant uses an alphabet that does not contain the uppercase alphabetic
* characters, which makes it suitable for use in situations where case-folding occurs.
* Translates the specified byte array into an "alternate representation" Base64 string. This non-standard variant
* uses an alphabet that does not contain the uppercase alphabetic characters, which makes it suitable for use in
* situations where case-folding occurs.
*/
static String byteArrayToAltBase64(byte[] a) {
return byteArrayToBase64(a, true);
Expand Down Expand Up @@ -63,8 +63,8 @@ private static String byteArrayToBase64(byte[] a, boolean alternate) {
}

/**
* This array is a lookup table that translates 6-bit positive integer index values into their
* "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045.
* This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet"
* equivalents as specified in Table 1 of RFC 2045.
*/
private static final char intToBase64[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
Expand All @@ -75,10 +75,9 @@ private static String byteArrayToBase64(byte[] a, boolean alternate) {
};

/**
* This array is a lookup table that translates 6-bit positive integer index values into their
* "Alternate Base64 Alphabet" equivalents. This is NOT the real Base64 Alphabet as per in Table
* 1 of RFC 2045. This alternate alphabet does not use the capital letters. It is designed for
* use in environments where "case folding" occurs.
* This array is a lookup table that translates 6-bit positive integer index values into their "Alternate Base64
* Alphabet" equivalents. This is NOT the real Base64 Alphabet as per in Table 1 of RFC 2045. This alternate
* alphabet does not use the capital letters. It is designed for use in environments where "case folding" occurs.
*/
private static final char intToAltBase64[] = {
'!', '"', '#', '$', '%', '&', '\'', '(', ')', ',', '-', '.', ':',
Expand All @@ -100,8 +99,8 @@ public static byte[] base64ToByteArray(String s) {
/**
* Translates the specified "alternate representation" Base64 string into a byte array.
*
* @throw IllegalArgumentException or ArrayOutOfBoundsException if <tt>s</tt> is not a valid
* alternate representation Base64 string.
* @throw IllegalArgumentException or ArrayOutOfBoundsException if <tt>s</tt> is not a valid alternate
* representation Base64 string.
*/
public static byte[] altBase64ToByteArray(String s) {
return base64ToByteArray(s, true);
Expand All @@ -113,7 +112,7 @@ private static byte[] base64ToByteArray(String s, boolean alternate) {
int numGroups = sLen / 4;
if (4 * numGroups != sLen)
throw new IllegalArgumentException(
"String length must be a multiple of four.");
"String length must be a multiple of four.");
int missingBytesInLastGroup = 0;
int numFullGroups = numGroups;
if (sLen != 0) {
Expand Down Expand Up @@ -155,11 +154,10 @@ private static byte[] base64ToByteArray(String s, boolean alternate) {
}

/**
* Translates the specified character, which is assumed to be in the "Base 64 Alphabet" into its
* equivalent 6-bit positive integer.
* Translates the specified character, which is assumed to be in the "Base 64 Alphabet" into its equivalent 6-bit
* positive integer.
*
* @throw IllegalArgumentException or ArrayOutOfBoundsException if c is not in the Base64
* Alphabet.
* @throw IllegalArgumentException or ArrayOutOfBoundsException if c is not in the Base64 Alphabet.
*/
private static int base64toInt(char c, byte[] alphaToInt) {
int result = alphaToInt[c];
Expand All @@ -169,10 +167,9 @@ private static int base64toInt(char c, byte[] alphaToInt) {
}

/**
* This array is a lookup table that translates unicode characters drawn from the "Base64
* Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer
* equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the
* array are translated to -1.
* This array is a lookup table that translates unicode characters drawn from the "Base64 Alphabet" (as specified in
* Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64
* alphabet but fall within the bounds of the array are translated to -1.
*/
private static final byte base64ToInt[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Expand All @@ -185,8 +182,8 @@ private static int base64toInt(char c, byte[] alphaToInt) {
};

/**
* This array is the analogue of base64ToInt, but for the nonstandard variant that avoids the
* use of uppercase alphabetic characters.
* This array is the analogue of base64ToInt, but for the nonstandard variant that avoids the use of uppercase
* alphabetic characters.
*/
private static final byte altBase64ToInt[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Expand Down
6 changes: 3 additions & 3 deletions Base/src/main/java/io/deephaven/base/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static void dumpFinals(final Logger log, final String prefix, final Objec
final String name = f.getName();
final Object value = f.get(p);
log.info(prefix
+ tName
+ " " + name
+ " = " + value.toString());
+ tName
+ " " + name
+ " = " + value.toString());
} catch (Exception ignored) {
}
}
Expand Down
38 changes: 18 additions & 20 deletions Base/src/main/java/io/deephaven/base/CompareUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public static boolean equals(Object data1, Object data2) {
}

/**
* Returns true if the given objects are both null, or equal by the first object's
* {@link #equals} method.
* Returns true if the given objects are both null, or equal by the first object's {@link #equals} method.
*/
public static boolean nullSafeEquals(Object left, Object right) {
if (null == left) {
Expand All @@ -72,13 +71,12 @@ public static boolean nullSafeEquals(Object left, Object right) {
}

/**
* You can't do double1 == double2 because floating point numbers are not exact values. Just
* make sure that x-y is less than some allowable error factor.
* You can't do double1 == double2 because floating point numbers are not exact values. Just make sure that x-y is
* less than some allowable error factor.
*
* @param x
* @param y
* @return True if the two doubles are equal to each other (or so close that we don't care that
* they are different).
* @return True if the two doubles are equal to each other (or so close that we don't care that they are different).
*/
public static boolean EQ(double x, double y) {
return doubleEquals(x, y);
Expand All @@ -93,13 +91,13 @@ public static boolean doubleEqualsZero(double x) {
}

/**
* You can't do double1 == double2 because floating point numbers are not exact values. Just
* make sure that x-y is less than some allowable error factor.
* You can't do double1 == double2 because floating point numbers are not exact values. Just make sure that x-y is
* less than some allowable error factor.
*
* @param x
* @param y
* @return True if the two doubles are equal to each other (or so close that we don't care that
* they are different). Also true if both are NaN.
* @return True if the two doubles are equal to each other (or so close that we don't care that they are different).
* Also true if both are NaN.
*/
public static boolean doubleEquals(double x, double y, double tolerance) {
return (Double.isNaN(x) && Double.isNaN(y)) || (Math.abs(x - y) < tolerance);
Expand All @@ -119,17 +117,17 @@ public static boolean doubleEquals2(double x, double y) {

public static boolean doubleEquals2(double x, double y, double tolerance) {
return Double.compare(x, y) == 0 ||
Math.abs(x - y) < tolerance;
Math.abs(x - y) < tolerance;
}

/**
* Since logical comparison of double values considerig error is effectively a three-value
* logic, you can't really do !equals when you mean notEquals.
* Since logical comparison of double values considerig error is effectively a three-value logic, you can't really
* do !equals when you mean notEquals.
*
* @param x
* @param y
* @return True if two doubles are apart from each other enough that we consider them different.
* False if both of them are NaN
* @return True if two doubles are apart from each other enough that we consider them different. False if both of
* them are NaN
*/
public static boolean NE(double x, double y) {
return doubleNotEquals(x, y);
Expand Down Expand Up @@ -158,12 +156,12 @@ public static boolean doubleNotEquals2(double x, double y) {

public static boolean doubleNotEquals2(double x, double y, double tolerance) {
return Double.compare(x, y) != 0 &&
!(Math.abs(x - y) < tolerance);
!(Math.abs(x - y) < tolerance);
}

/**
* You can't do double1 > double2 because floating point numbers are not exact values. Just make
* sure that x-y is greater than some allowable error factor for equality
* You can't do double1 > double2 because floating point numbers are not exact values. Just make sure that x-y is
* greater than some allowable error factor for equality
*
* @param x
* @param y
Expand Down Expand Up @@ -194,8 +192,8 @@ public static boolean doubleGreaterEqual(double x, double y, double tolerance) {
}

/**
* You can't do double1 < double2 because floating point numbers are not exact values. Just make
* sure that y - x is greater than some allowable error factor for equality
* You can't do double1 < double2 because floating point numbers are not exact values. Just make sure that y - x is
* greater than some allowable error factor for equality
*
* @param x
* @param y
Expand Down
4 changes: 2 additions & 2 deletions Base/src/main/java/io/deephaven/base/Encodeable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.io.IOException;

/**
* This interface is a slightly weaker version of java.io.Externalizable, in that it only allows the
* use of the DataInput and -Output interfaces for reading and writing, not ObjectInput and -Output.
* This interface is a slightly weaker version of java.io.Externalizable, in that it only allows the use of the
* DataInput and -Output interfaces for reading and writing, not ObjectInput and -Output.
*/
public interface Encodeable {
public void encode(DataOutput out) throws IOException;
Expand Down
11 changes: 5 additions & 6 deletions Base/src/main/java/io/deephaven/base/FIFOMutex.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public void lock() {
}
int spins = 0;
boolean peekNotMe = true;
while ((peekNotMe && (peekNotMe = (threads.peek() != me))) || // once we've peeked ourselves
// once, we don't need to do
// it again!
!leader.compareAndSet(null, me)) {
while ((peekNotMe && (peekNotMe = (threads.peek() != me))) || // once we've peeked ourselves once, we don't need
// to do it again!
!leader.compareAndSet(null, me)) {
if ((++spins % 1000) == 0) {
LockSupport.park(this);

Expand All @@ -62,15 +61,15 @@ public void lock() {
if (debugName != null) {
lastLeadChange = System.nanoTime();
log.info("FIFOMutex: " + debugName + ": thread " + me.getName() + " leading after "
+ ((lastLeadChange - t0 + 500) / 1000) + " micros");
+ ((lastLeadChange - t0 + 500) / 1000) + " micros");
}
}

public void unlock() {
Thread me = Thread.currentThread();
if (debugName != null) {
log.info("FIFOMutex: " + debugName + ": thread " + me.getName() + " handing off after "
+ ((System.nanoTime() - lastLeadChange + 500) / 1000) + " micros");
+ ((System.nanoTime() - lastLeadChange + 500) / 1000) + " micros");
}
if (!leader.compareAndSet(me, null)) {
throw new IllegalStateException("wrong thread called handoff");
Expand Down
7 changes: 3 additions & 4 deletions Base/src/main/java/io/deephaven/base/FIFOSemaphore.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ private void acquire(int toAcquire, boolean doUnpark) {
int spins = 0;
int resourcesAvailable;
boolean peekNotMe = true;
while ((peekNotMe && (peekNotMe = (threads.peek() != me))) || // once we've peeked ourselves
// once, we don't need to do
// it again!
(resourcesAvailable = getAndDecreaseIfCan(toAcquire)) < toAcquire) {
while ((peekNotMe && (peekNotMe = (threads.peek() != me))) || // once we've peeked ourselves once, we don't need
// to do it again!
(resourcesAvailable = getAndDecreaseIfCan(toAcquire)) < toAcquire) {
if ((++spins % spinsUntilPark) == 0) {
LockSupport.park(this);

Expand Down
Loading

0 comments on commit 86319e2

Please sign in to comment.