mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Cleanup usages
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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 extends Throwable> T propagateNotWrapping(
|
||||
Throwable t, Class<T> notWrappingThrowableType) throws T {
|
||||
Objects.requireNonNull(t);
|
||||
Objects.requireNonNull(notWrappingThrowableType);
|
||||
requireNonNull(t);
|
||||
requireNonNull(notWrappingThrowableType);
|
||||
if (t instanceof Error)
|
||||
throw (Error) t;
|
||||
if (t instanceof RuntimeException)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<K, V> extends ChronicleMap<K, V> {
|
||||
|
||||
|
||||
@@ -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<K, V> implements
|
||||
ChronicleHashBuilder<K, ChronicleMap<K, V>,
|
||||
ChronicleMapBuilder<K, V>> {
|
||||
ChronicleMapBuilder<K, V>> {
|
||||
|
||||
private static final int UNDEFINED_ALIGNMENT_CONFIG = -1;
|
||||
private static final int NO_ALIGNMENT = 1;
|
||||
@@ -1384,7 +1383,9 @@ public final class ChronicleMapBuilder<K, V> 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<K, V> 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);
|
||||
|
||||
+3
-2
@@ -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<K, V, R> implements MapContext<K, V, R> {
|
||||
|
||||
@@ -35,7 +36,7 @@ public abstract class WrappedValueBytesDataAccess<K, V, R> implements MapContext
|
||||
|
||||
@Override
|
||||
public Data<V> wrapValueBytesAsData(BytesStore bytesStore, long offset, long size) {
|
||||
Objects.requireNonNull(bytesStore);
|
||||
requireNonNull(bytesStore);
|
||||
checkOnEachPublicOperation.checkOnEachPublicOperation();
|
||||
WrappedValueBytesData<V> wrapped = this.wrappedValueBytesData;
|
||||
wrapped = wrapped.getUnusedWrappedValueBytesData();
|
||||
|
||||
@@ -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<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
public boolean forEachEntryWhile(Predicate<? super SetEntry<E>> predicate) {
|
||||
throwExceptionIfClosed();
|
||||
|
||||
Objects.requireNonNull(predicate);
|
||||
requireNonNull(predicate);
|
||||
return m.forEachEntryWhile(e -> predicate.test(((SetEntry<E>) e)));
|
||||
}
|
||||
|
||||
@@ -228,7 +229,7 @@ class SetFromMap<E> extends AbstractSet<E> implements ChronicleSet<E> {
|
||||
public void forEachEntry(Consumer<? super SetEntry<E>> action) {
|
||||
throwExceptionIfClosed();
|
||||
|
||||
Objects.requireNonNull(action);
|
||||
requireNonNull(action);
|
||||
m.forEachEntry(e -> action.accept(((SetEntry<E>) e)));
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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<CharSequence[]>, BytesReader<CharSequence[]>,
|
||||
ReadResolvable<CharSequenceArrayBytesMarshaller> {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user