Skip to content

Commit

Permalink
[Java] Remove Serializable from Agrona collections and mutable wrappe…
Browse files Browse the repository at this point in the history
…r classes. (#250)
  • Loading branch information
vyazelenko committed Nov 17, 2021
1 parent eb93120 commit 5b784ed
Show file tree
Hide file tree
Showing 42 changed files with 152 additions and 252 deletions.
2 changes: 1 addition & 1 deletion agrona/src/main/java/org/agrona/MarkFile.java
Expand Up @@ -234,7 +234,7 @@ public boolean isClosed()
}

/**
* {@inheritDoc}
* {@inheritDoc}
*/
public void close()
{
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package org.agrona.collections;

import java.io.Serializable;
import java.util.Arrays;
import java.util.function.Consumer;

Expand All @@ -28,11 +27,8 @@
*
* @param <V> type of the object stored in the map.
*/
@SuppressWarnings("serial")
public class BiInt2ObjectMap<V> implements Serializable
public class BiInt2ObjectMap<V>
{
private static final long serialVersionUID = -4306301811303037776L;

/**
* Handler for a map entry
*
Expand Down Expand Up @@ -351,7 +347,7 @@ public boolean isEmpty()
}

/**
* {@inheritDoc}
* {@inheritDoc}
*/
public String toString()
{
Expand Down
Expand Up @@ -17,7 +17,6 @@

import org.agrona.generation.DoNotSub;

import java.io.Serializable;
import java.util.Arrays;
import java.util.function.IntUnaryOperator;

Expand All @@ -28,10 +27,9 @@
* An open-addressing with linear probing hash map specialised for primitive key and counter pairs. A counter map views
* counters which hit {@link #initialValue} as deleted. This means that changing a counter may impact {@link #size()}.
*/
public class Int2IntCounterMap implements Serializable
public class Int2IntCounterMap
{
@DoNotSub private static final int MIN_CAPACITY = 8;
private static final long serialVersionUID = -3044319458317497461L;

@DoNotSub private final float loadFactor;
private final int initialValue;
Expand Down
28 changes: 8 additions & 20 deletions agrona/src/main/java/org/agrona/collections/Int2IntHashMap.java
Expand Up @@ -17,7 +17,6 @@

import org.agrona.generation.DoNotSub;

import java.io.Serializable;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
Expand All @@ -29,10 +28,9 @@
/**
* An open-addressing with linear probing hash map specialised for primitive key and value pairs.
*/
public class Int2IntHashMap implements Map<Integer, Integer>, Serializable
public class Int2IntHashMap implements Map<Integer, Integer>
{
@DoNotSub static final int MIN_CAPACITY = 8;
private static final long serialVersionUID = -690554872053575793L;

private final float loadFactor;
private final int missingValue;
Expand Down Expand Up @@ -688,9 +686,8 @@ private Integer valOrNull(final int value)
/**
* Base iterator implementation.
*/
abstract class AbstractIterator implements Serializable
abstract class AbstractIterator
{
private static final long serialVersionUID = 5262459454112462433L;
/**
* Is current position valid.
*/
Expand Down Expand Up @@ -811,10 +808,8 @@ public void remove()
/**
* Iterator over keys which supports access to unboxed keys via {@link #nextValue()}.
*/
public final class KeyIterator extends AbstractIterator implements Iterator<Integer>, Serializable
public final class KeyIterator extends AbstractIterator implements Iterator<Integer>
{
private static final long serialVersionUID = 9151493609653852972L;

/**
* {@inheritDoc}
*/
Expand All @@ -838,10 +833,8 @@ public int nextValue()
/**
* Iterator over values which supports access to unboxed values.
*/
public final class ValueIterator extends AbstractIterator implements Iterator<Integer>, Serializable
public final class ValueIterator extends AbstractIterator implements Iterator<Integer>
{
private static final long serialVersionUID = -5670291734793552927L;

/**
* {@inheritDoc}
*/
Expand All @@ -867,10 +860,8 @@ public int nextValue()
*/
public final class EntryIterator
extends AbstractIterator
implements Iterator<Entry<Integer, Integer>>, Entry<Integer, Integer>, Serializable
implements Iterator<Entry<Integer, Integer>>, Entry<Integer, Integer>
{
private static final long serialVersionUID = 1744408438593481051L;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1067,9 +1058,8 @@ public String toString()
/**
* Set of keys which supports optional cached iterators to avoid allocation.
*/
public final class KeySet extends AbstractSet<Integer> implements Serializable
public final class KeySet extends AbstractSet<Integer>
{
private static final long serialVersionUID = -7645453993079742625L;
private final KeyIterator keyIterator = shouldAvoidAllocation ? new KeyIterator() : null;

/**
Expand Down Expand Up @@ -1135,9 +1125,8 @@ public boolean contains(final int key)
/**
* Collection of values which supports optionally cached iterators to avoid allocation.
*/
public final class ValueCollection extends AbstractCollection<Integer> implements Serializable
public final class ValueCollection extends AbstractCollection<Integer>
{
private static final long serialVersionUID = -8925598924781601919L;
private final ValueIterator valueIterator = shouldAvoidAllocation ? new ValueIterator() : null;

/**
Expand Down Expand Up @@ -1187,9 +1176,8 @@ public boolean contains(final int value)
/**
* Set of entries which supports optionally cached iterators to avoid allocation.
*/
public final class EntrySet extends AbstractSet<Map.Entry<Integer, Integer>> implements Serializable
public final class EntrySet extends AbstractSet<Map.Entry<Integer, Integer>>
{
private static final long serialVersionUID = 63641283589916174L;
private final EntryIterator entryIterator = shouldAvoidAllocation ? new EntryIterator() : null;

/**
Expand Down
Expand Up @@ -24,8 +24,6 @@
*/
public class Int2NullableObjectHashMap<V> extends Int2ObjectHashMap<V>
{
private static final long serialVersionUID = -7081946803848112161L;

/**
* Constructs map with default settings.
*/
Expand Down
Expand Up @@ -17,7 +17,6 @@

import org.agrona.generation.DoNotSub;

import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntFunction;
Expand All @@ -40,8 +39,7 @@
*
* @param <V> type of values stored in the {@link Map}
*/
public class Int2ObjectCache<V>
implements Map<Integer, V>
public class Int2ObjectCache<V> implements Map<Integer, V>
{
private long cachePuts = 0;
private long cacheHits = 0;
Expand Down Expand Up @@ -643,10 +641,8 @@ public void clear()
/**
* Collection of values which supports cached iterator to avoid allocation.
*/
@SuppressWarnings("serial")
public final class ValueCollection extends AbstractCollection<V> implements Serializable
public final class ValueCollection extends AbstractCollection<V>
{
private static final long serialVersionUID = 4345278262685013239L;
private final ValueIterator iterator = new ValueIterator();

/**
Expand Down
35 changes: 10 additions & 25 deletions agrona/src/main/java/org/agrona/collections/Int2ObjectHashMap.java
Expand Up @@ -17,7 +17,6 @@

import org.agrona.generation.DoNotSub;

import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntFunction;
Expand All @@ -32,12 +31,9 @@
*
* @param <V> type of values stored in the {@link java.util.Map}
*/
@SuppressWarnings("serial")
public class Int2ObjectHashMap<V>
implements Map<Integer, V>, Serializable
public class Int2ObjectHashMap<V> implements Map<Integer, V>
{
@DoNotSub static final int MIN_CAPACITY = 8;
private static final long serialVersionUID = -87577678740521569L;

private final float loadFactor;
@DoNotSub private int resizeThreshold;
Expand Down Expand Up @@ -678,9 +674,8 @@ private void compactChain(@DoNotSub int deleteIndex)
/**
* Set of keys which supports optionally cached iterators to avoid allocation.
*/
public final class KeySet extends AbstractSet<Integer> implements Serializable
public final class KeySet extends AbstractSet<Integer>
{
private static final long serialVersionUID = 174654887531298424L;
private final KeyIterator keyIterator = shouldAvoidAllocation ? new KeyIterator() : null;

/**
Expand Down Expand Up @@ -756,9 +751,8 @@ public void clear()
/**
* Collection of values which supports optionally cached iterators to avoid allocation.
*/
public final class ValueCollection extends AbstractCollection<V> implements Serializable
public final class ValueCollection extends AbstractCollection<V>
{
private static final long serialVersionUID = 6851282235497568109L;
private final ValueIterator valueIterator = shouldAvoidAllocation ? new ValueIterator() : null;

/**
Expand Down Expand Up @@ -822,9 +816,8 @@ public void forEach(final Consumer<? super V> action)
/**
* Set of entries which supports access via an optionally cached iterator to avoid allocation.
*/
public final class EntrySet extends AbstractSet<Map.Entry<Integer, V>> implements Serializable
public final class EntrySet extends AbstractSet<Map.Entry<Integer, V>>
{
private static final long serialVersionUID = 6797969139720339177L;
private final EntryIterator entryIterator = shouldAvoidAllocation ? new EntryIterator() : null;

/**
Expand Down Expand Up @@ -919,9 +912,8 @@ public <T> T[] toArray(final T[] a)
*
* @param <T> type of elements.
*/
abstract class AbstractIterator<T> implements Iterator<T>, Serializable
abstract class AbstractIterator<T> implements Iterator<T>
{
private static final long serialVersionUID = 7955640333577513200L;
@DoNotSub private int posCounter;
@DoNotSub private int stopCounter;
@DoNotSub private int remaining;
Expand Down Expand Up @@ -1039,10 +1031,8 @@ final void reset()
/**
* Iterator over values.
*/
public class ValueIterator extends AbstractIterator<V> implements Serializable
public final class ValueIterator extends AbstractIterator<V>
{
private static final long serialVersionUID = -410109102792377049L;

/**
* {@inheritDoc}
*/
Expand All @@ -1057,10 +1047,8 @@ public V next()
/**
* Iterator over keys which supports access to unboxed keys via {@link #nextInt()}.
*/
public class KeyIterator extends AbstractIterator<Integer> implements Serializable
public final class KeyIterator extends AbstractIterator<Integer>
{
private static final long serialVersionUID = -4905479491707153377L;

/**
* {@inheritDoc}
*/
Expand All @@ -1085,12 +1073,10 @@ public int nextInt()
/**
* Iterator over entries which supports access to unboxed keys via {@link #getIntKey()}.
*/
public class EntryIterator
public final class EntryIterator
extends AbstractIterator<Entry<Integer, V>>
implements Entry<Integer, V>, Serializable
implements Entry<Integer, V>
{
private static final long serialVersionUID = 2227334666048171527L;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1160,9 +1146,8 @@ public V setValue(final V value)
/**
* An {@link java.util.Map.Entry} implementation.
*/
public final class MapEntry implements Entry<Integer, V>, Serializable
public final class MapEntry implements Entry<Integer, V>
{
private static final long serialVersionUID = -6648311124347304211L;
private final int k;
private final V v;

Expand Down
Expand Up @@ -17,7 +17,6 @@

import org.agrona.generation.DoNotSub;

import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
Expand All @@ -26,7 +25,7 @@
/**
* A {@link List} implementation that stores int values with the ability to not have them boxed.
*/
public class IntArrayList extends AbstractList<Integer> implements List<Integer>, RandomAccess, Serializable
public class IntArrayList extends AbstractList<Integer> implements List<Integer>, RandomAccess
{
/**
* The default value that will be used in place of null for an element.
Expand All @@ -37,7 +36,6 @@ public class IntArrayList extends AbstractList<Integer> implements List<Integer>
* Initial capacity to which the array will be sized.
*/
@DoNotSub public static final int INITIAL_CAPACITY = 10;
private static final long serialVersionUID = -2257879229511649624L;

private final int nullValue;
@DoNotSub private int size = 0;
Expand Down
Expand Up @@ -18,7 +18,6 @@
import org.agrona.BitUtil;
import org.agrona.generation.DoNotSub;

import java.io.Serializable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
Expand All @@ -30,7 +29,7 @@
* <p>
* <b>Note:</b> This class is not threadsafe.
*/
public class IntArrayQueue extends AbstractQueue<Integer> implements Serializable
public class IntArrayQueue extends AbstractQueue<Integer>
{
/**
* Default representation of null for an element.
Expand All @@ -41,7 +40,6 @@ public class IntArrayQueue extends AbstractQueue<Integer> implements Serializabl
* Minimum capacity for the queue which must also be a power of 2.
*/
@DoNotSub public static final int MIN_CAPACITY = 8;
private static final long serialVersionUID = 8043508567156267834L;

private final boolean shouldAvoidAllocation;
@DoNotSub private int head;
Expand Down Expand Up @@ -416,9 +414,8 @@ private void increaseCapacity()
/**
* Specialised {@link Iterator} from which the value can be retrieved without boxing via {@link #nextValue()}.
*/
public final class IntIterator implements Iterator<Integer>, Serializable
public final class IntIterator implements Iterator<Integer>
{
private static final long serialVersionUID = -7596692870537894897L;
@DoNotSub private int index;

IntIterator reset()
Expand Down

0 comments on commit 5b784ed

Please sign in to comment.