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 0693e0b22..4d63bae8b 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,6 +16,7 @@ package net.openhft.chronicle.hash.impl.util; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -32,10 +33,15 @@ public final class Objects { } public static boolean equal(@Nullable Object a, @Nullable Object b) { - return java.util.Objects.equals(a, 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()); } - /* 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 5643cfc7c..1cdfcdd71 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,8 +16,6 @@ package net.openhft.chronicle.hash.impl.util; -import static net.openhft.chronicle.core.util.ObjectUtils.requireNonNull; - /** * Inspired by Guava's Throwables */ @@ -39,8 +37,8 @@ public final class Throwables { public static T propagateNotWrapping( Throwable t, Class notWrappingThrowableType) throws T { - requireNonNull(t); - requireNonNull(notWrappingThrowableType); + Objects.requireNonNull(t); + Objects.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 898fdf569..e2ab56f70 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 finish(hash); + return finalize(hash); } - private static long finish(long hash) { + private static long finalize(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 5488ca286..4ab2297a5 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.core.util.ObjectUtils.requireNonNull; +import static net.openhft.chronicle.hash.impl.util.Objects.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 19bb2abef..693880efb 100644 --- a/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java +++ b/src/main/java/net/openhft/chronicle/map/ChronicleMapBuilder.java @@ -71,6 +71,7 @@ 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; @@ -138,7 +139,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; @@ -1383,9 +1384,7 @@ public final class ChronicleMapBuilder implements @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override public boolean equals(final Object o) { - return this == o || - o != null && this.getClass() == o.getClass() && - this.toString().equals(o.toString()); + return builderEquals(this, o); } @Override @@ -1705,8 +1704,8 @@ public final class ChronicleMapBuilder implements if (!canonicalFile.exists()) { if (recover) throw new FileNotFoundException("file " + canonicalFile + " should exist for recovery"); - if (!canonicalFile.createNewFile()) - throw new IOException("Unable to create file " + canonicalFile + " which presumably already exists"); + //noinspection ResultOfMethodCallIgnored + canonicalFile.createNewFile(); } 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 3b43d67b1..259249972 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,13 +19,12 @@ 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 { @@ -36,7 +35,7 @@ public abstract class WrappedValueBytesDataAccess implements MapContext @Override public Data wrapValueBytesAsData(BytesStore bytesStore, long offset, long size) { - requireNonNull(bytesStore); + Objects.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 c89c65a4a..349958a9c 100644 --- a/src/main/java/net/openhft/chronicle/set/SetFromMap.java +++ b/src/main/java/net/openhft/chronicle/set/SetFromMap.java @@ -32,7 +32,6 @@ 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; /** @@ -221,7 +220,7 @@ class SetFromMap extends AbstractSet implements ChronicleSet { public boolean forEachEntryWhile(Predicate> predicate) { throwExceptionIfClosed(); - requireNonNull(predicate); + Objects.requireNonNull(predicate); return m.forEachEntryWhile(e -> predicate.test(((SetEntry) e))); } @@ -229,7 +228,7 @@ class SetFromMap extends AbstractSet implements ChronicleSet { public void forEachEntry(Consumer> action) { throwExceptionIfClosed(); - requireNonNull(action); + Objects.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 3eb89ffb7..d2b2c2020 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArrayBytesMarshaller.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/CharSequenceArrayBytesMarshaller.java @@ -18,6 +18,7 @@ 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; @@ -27,8 +28,6 @@ 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 { @@ -46,7 +45,7 @@ public final class CharSequenceArrayBytesMarshaller out.writeInt(toWrite.length); for (CharSequence cs : toWrite) { // Assume elements non-null for simplicity - requireNonNull(cs); + Objects.requireNonNull(cs); out.writeUtf8(cs); } }