Skip to content

Commit

Permalink
Merge pull request #114 from kpartlow/kpartlow/cleaning-up-warnings
Browse files Browse the repository at this point in the history
cleaning up warnings
  • Loading branch information
jdereg authored Feb 25, 2025
2 parents ed7f9f0 + 0b09e98 commit e03e5e8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/cedarsoftware/util/ClassUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
* limitations under the License.
*/
public class ClassUtilities {

private ClassUtilities() {
}

private static final Set<Class<?>> prims = new HashSet<>();
private static final Map<Class<?>, Class<?>> primitiveToWrapper = new HashMap<>(20, .8f);
private static final Map<String, Class<?>> nameToClass = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -1546,4 +1550,4 @@ private static int getDepth(Class<?> clazz) {
public static boolean haveCommonAncestor(Class<?> a, Class<?> b) {
return !findLowestCommonSupertypes(a, b).isEmpty();
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/cedarsoftware/util/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ public static AtomicBoolean convertToAtomicBoolean(Object fromInstance)
* No longer needed - use convert(localDate, long.class)
* @param localDate A Java LocalDate
* @return a long representing the localDate as epoch milliseconds (since 1970 Jan 1 at midnight)
* @deprecated replaced by convert(localDate, long.class)
*/
@Deprecated
public static long localDateToMillis(LocalDate localDate)
Expand All @@ -785,6 +786,7 @@ public static long localDateToMillis(LocalDate localDate)
* No longer needed - use convert(localDateTime, long.class)
* @param localDateTime A Java LocalDateTime
* @return a long representing the localDateTime as epoch milliseconds (since 1970 Jan 1 at midnight)
* @deprecated replaced by convert(localDateTime, long.class)
*/
@Deprecated
public static long localDateTimeToMillis(LocalDateTime localDateTime)
Expand All @@ -796,6 +798,7 @@ public static long localDateTimeToMillis(LocalDateTime localDateTime)
* No longer needed - use convert(ZonedDateTime, long.class)
* @param zonedDateTime A Java ZonedDateTime
* @return a long representing the ZonedDateTime as epoch milliseconds (since 1970 Jan 1 at midnight)
* @deprecated replaced by convert(ZonedDateTime, long.class)
*/
@Deprecated
public static long zonedDateTimeToMillis(ZonedDateTime zonedDateTime)
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/cedarsoftware/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,8 @@ public int hashCode() {
return false;
}

if (declaringClass.isAssignableFrom(Enum.class) &&
("hash".equals(fieldName) || "ordinal".equals(fieldName))) {
return false;
}

return true;
return !declaringClass.isAssignableFrom(Enum.class) ||
(!"hash".equals(fieldName) && !"ordinal".equals(fieldName));
};

/**
Expand Down Expand Up @@ -1488,4 +1484,4 @@ private static String getClassLoaderName(Class<?> c) {
// Example: "org.example.MyLoader@1a2b3c4"
return loader.getClass().getName() + '@' + Integer.toHexString(System.identityHashCode(loader));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void set2DigitYearStart(Date date)
}

public String toString() {
return _format.toString();
return _format;
}

@Override
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/cedarsoftware/util/StringUtilities.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.cedarsoftware.util;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -115,7 +117,7 @@
* limitations under the License.
*/
public final class StringUtilities {
private static char[] _hex = {
private static final char[] _hex = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
Expand Down Expand Up @@ -636,7 +638,7 @@ public static String getRandomString(Random random, int minLen, int maxLen) {

public static String getRandomChar(Random random, boolean upper) {
int r = random.nextInt(26);
return upper ? EMPTY + (char) ((int) 'A' + r) : EMPTY + (char) ((int) 'a' + r);
return upper ? EMPTY + (char) ('A' + r) : EMPTY + (char) ('a' + r);
}

/**
Expand All @@ -658,6 +660,8 @@ public static byte[] getBytes(String s, String encoding) {
}


// TODO: The following two methods are exactly the same other than the case of the method.
// TODO: deprecate one and remove next major version.
/**
* Convert a byte[] into a UTF-8 String. Preferable used when the encoding
* is one of the guaranteed Java types and you don't want to have to catch
Expand All @@ -666,7 +670,16 @@ public static byte[] getBytes(String s, String encoding) {
* @param bytes bytes to encode into a string
*/
public static String createUtf8String(byte[] bytes) {
return createString(bytes, "UTF-8");
return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
}

/**
* Convert a byte[] into a UTF-8 encoded String.
*
* @param bytes bytes to encode into a string
*/
public static String createUTF8String(byte[] bytes) {
return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8);
}

/**
Expand All @@ -675,7 +688,7 @@ public static String createUtf8String(byte[] bytes) {
* @param s string to encode into bytes
*/
public static byte[] getUTF8Bytes(String s) {
return getBytes(s, "UTF-8");
return s == null ? null : s.getBytes(StandardCharsets.UTF_8);
}

/**
Expand All @@ -696,15 +709,6 @@ public static String createString(byte[] bytes, String encoding) {
}
}

/**
* Convert a byte[] into a UTF-8 encoded String.
*
* @param bytes bytes to encode into a string
*/
public static String createUTF8String(byte[] bytes) {
return createString(bytes, "UTF-8");
}

/**
* Get the hashCode of a String, insensitive to case, without any new Strings
* being created on the heap.
Expand Down Expand Up @@ -844,4 +848,4 @@ public static Set<String> commaSeparatedStringToSet(String commaSeparatedString)
.filter(s -> !s.isEmpty())
.collect(Collectors.toSet());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public V put(K key, V value) {
cache.put(key, newNode);
addToHead(newNode);
if (cache.size() > capacity) {
Node<K, V> tail = removeTail();
cache.remove(tail.key);
Node<K, V> tailToRemove = removeTail();
cache.remove(tailToRemove.key);
}
return null;
}
Expand Down Expand Up @@ -442,4 +442,4 @@ public int hashCode() {
lock.unlock();
}
}
}
}

0 comments on commit e03e5e8

Please sign in to comment.