diff --git a/src/main/java/net/openhft/chronicle/hash/impl/util/Objects.java b/src/main/java/net/openhft/chronicle/hash/impl/util/Objects.java index 4d63bae8b..0693e0b22 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/util/Objects.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/util/Objects.java @@ -16,7 +16,6 @@ package net.openhft.chronicle.hash.impl.util; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -33,15 +32,10 @@ public final class Objects { } public static boolean equal(@Nullable Object a, @Nullable Object b) { - return a != null ? a.equals(b) : b == null; - } - - public static boolean builderEquals(@NotNull Object builder, @Nullable Object o) { - return builder == o || - o != null && builder.getClass() == o.getClass() && - builder.toString().equals(o.toString()); + return java.util.Objects.equals(a, b); } + /* Used by generated code */ public static void requireNonNull(Object obj) { if (obj == null) throw new NullPointerException(); diff --git a/src/main/java/net/openhft/chronicle/hash/impl/util/Throwables.java b/src/main/java/net/openhft/chronicle/hash/impl/util/Throwables.java index 1cdfcdd71..5643cfc7c 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/util/Throwables.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/util/Throwables.java @@ -16,6 +16,8 @@ package net.openhft.chronicle.hash.impl.util; +import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; + /** * Inspired by Guava's Throwables */ @@ -37,8 +39,8 @@ public final class Throwables { public static T propagateNotWrapping( Throwable t, Class notWrappingThrowableType) throws T { - Objects.requireNonNull(t); - Objects.requireNonNull(notWrappingThrowableType); + requireNonNull(t); + requireNonNull(notWrappingThrowableType); if (t instanceof Error) throw (Error) t; if (t instanceof RuntimeException) diff --git a/src/main/java/net/openhft/chronicle/hash/serialization/impl/WrongXxHash.java b/src/main/java/net/openhft/chronicle/hash/serialization/impl/WrongXxHash.java index e2ab56f70..898fdf569 100644 --- a/src/main/java/net/openhft/chronicle/hash/serialization/impl/WrongXxHash.java +++ b/src/main/java/net/openhft/chronicle/hash/serialization/impl/WrongXxHash.java @@ -38,10 +38,10 @@ public final class WrongXxHash { // unsigned here. hash ^= input * P1; hash = Long.rotateLeft(hash, 23) * P2 + P3; - return finalize(hash); + return finish(hash); } - private static long finalize(long hash) { + private static long finish(long hash) { hash ^= hash >>> 33; hash *= P2; hash ^= hash >>> 29; diff --git a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMap.java b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMap.java index 4ab2297a5..5488ca286 100644 --- a/src/main/java/net/openhft/chronicle/map/AbstractChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/AbstractChronicleMap.java @@ -28,7 +28,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; import static java.util.Collections.emptyList; -import static net.openhft.chronicle.hash.impl.util.Objects.requireNonNull; +import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; interface AbstractChronicleMap extends ChronicleMap { diff --git a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java index 693880efb..19bb2abef 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -71,7 +71,6 @@ import static net.openhft.chronicle.hash.impl.SizePrefixedBlob.*; import static net.openhft.chronicle.hash.impl.VanillaChronicleHash.throwRecoveryOrReturnIOException; import static net.openhft.chronicle.hash.impl.util.FileIOUtils.readFully; import static net.openhft.chronicle.hash.impl.util.FileIOUtils.writeFully; -import static net.openhft.chronicle.hash.impl.util.Objects.builderEquals; import static net.openhft.chronicle.map.ChronicleHashCorruptionImpl.format; import static net.openhft.chronicle.map.ChronicleHashCorruptionImpl.report; import static net.openhft.chronicle.map.DefaultSpi.mapEntryOperations; @@ -139,7 +138,7 @@ import static net.openhft.chronicle.map.VanillaChronicleMap.alignAddr; */ public final class ChronicleMapBuilder implements ChronicleHashBuilder, - ChronicleMapBuilder> { + ChronicleMapBuilder> { private static final int UNDEFINED_ALIGNMENT_CONFIG = -1; private static final int NO_ALIGNMENT = 1; @@ -1384,7 +1383,9 @@ public final class ChronicleMapBuilder implements @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override public boolean equals(final Object o) { - return builderEquals(this, o); + return this == o || + o != null && this.getClass() == o.getClass() && + this.toString().equals(o.toString()); } @Override @@ -1704,8 +1705,8 @@ public final class ChronicleMapBuilder implements if (!canonicalFile.exists()) { if (recover) throw new FileNotFoundException("file " + canonicalFile + " should exist for recovery"); - //noinspection ResultOfMethodCallIgnored - canonicalFile.createNewFile(); + if (!canonicalFile.createNewFile()) + throw new IOException("Unable to create file " + canonicalFile + " which presumably already exists"); } final RandomAccessFile raf = CanonicalRandomAccessFiles.acquire(canonicalFile); final ChronicleHashResources resources = new PersistedChronicleHashResources(canonicalFile); diff --git a/src/main/java/net/openhft/chronicle/map/impl/stage/map/WrappedValueBytesDataAccess.java b/src/main/java/net/openhft/chronicle/map/impl/stage/map/WrappedValueBytesDataAccess.java index 259249972..3b43d67b1 100644 --- a/src/main/java/net/openhft/chronicle/map/impl/stage/map/WrappedValueBytesDataAccess.java +++ b/src/main/java/net/openhft/chronicle/map/impl/stage/map/WrappedValueBytesDataAccess.java @@ -19,12 +19,13 @@ package net.openhft.chronicle.map.impl.stage.map; import net.openhft.chronicle.bytes.BytesStore; import net.openhft.chronicle.hash.Data; import net.openhft.chronicle.hash.impl.stage.hash.CheckOnEachPublicOperation; -import net.openhft.chronicle.hash.impl.util.Objects; import net.openhft.chronicle.map.MapContext; import net.openhft.chronicle.map.impl.stage.data.bytes.WrappedValueBytesData; import net.openhft.sg.StageRef; import net.openhft.sg.Staged; +import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; + @Staged public abstract class WrappedValueBytesDataAccess implements MapContext { @@ -35,7 +36,7 @@ public abstract class WrappedValueBytesDataAccess implements MapContext @Override public Data wrapValueBytesAsData(BytesStore bytesStore, long offset, long size) { - Objects.requireNonNull(bytesStore); + requireNonNull(bytesStore); checkOnEachPublicOperation.checkOnEachPublicOperation(); WrappedValueBytesData wrapped = this.wrappedValueBytesData; wrapped = wrapped.getUnusedWrappedValueBytesData(); diff --git a/src/main/java/net/openhft/chronicle/set/SetFromMap.java b/src/main/java/net/openhft/chronicle/set/SetFromMap.java index 349958a9c..c89c65a4a 100644 --- a/src/main/java/net/openhft/chronicle/set/SetFromMap.java +++ b/src/main/java/net/openhft/chronicle/set/SetFromMap.java @@ -32,6 +32,7 @@ import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; +import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; import static net.openhft.chronicle.set.DummyValue.DUMMY_VALUE; /** @@ -220,7 +221,7 @@ class SetFromMap extends AbstractSet implements ChronicleSet { public boolean forEachEntryWhile(Predicate> predicate) { throwExceptionIfClosed(); - Objects.requireNonNull(predicate); + requireNonNull(predicate); return m.forEachEntryWhile(e -> predicate.test(((SetEntry) e))); } @@ -228,7 +229,7 @@ class SetFromMap extends AbstractSet implements ChronicleSet { public void forEachEntry(Consumer> action) { throwExceptionIfClosed(); - Objects.requireNonNull(action); + requireNonNull(action); m.forEachEntry(e -> action.accept(((SetEntry) e))); } diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArrayBytesMarshaller.java b/src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArrayBytesMarshaller.java index d2b2c2020..3eb89ffb7 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArrayBytesMarshaller.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArrayBytesMarshaller.java @@ -18,7 +18,6 @@ package net.openhft.chronicle.map.fromdocs; import net.openhft.chronicle.bytes.Bytes; import net.openhft.chronicle.core.util.ReadResolvable; -import net.openhft.chronicle.hash.impl.util.Objects; import net.openhft.chronicle.hash.serialization.BytesReader; import net.openhft.chronicle.hash.serialization.BytesWriter; import net.openhft.chronicle.wire.WireIn; @@ -28,6 +27,8 @@ import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; + public final class CharSequenceArrayBytesMarshaller implements BytesWriter, BytesReader, ReadResolvable { @@ -45,7 +46,7 @@ public final class CharSequenceArrayBytesMarshaller out.writeInt(toWrite.length); for (CharSequence cs : toWrite) { // Assume elements non-null for simplicity - Objects.requireNonNull(cs); + requireNonNull(cs); out.writeUtf8(cs); } }