forked from real-logic/agrona
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
571 additions
and
40 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
agrona/src/main/java/org/agrona/collections/Int2NullableObjectHashMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2014-2018 Real Logic Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.agrona.collections; | ||
|
||
import org.agrona.generation.DoNotSub; | ||
|
||
/** | ||
* Variation of {@link Int2ObjectHashMap} that allows {@code null} values. | ||
* | ||
* @param <V> type of values stored in the {@link java.util.Map} | ||
*/ | ||
public class Int2NullableObjectHashMap<V> extends Int2ObjectHashMap<V> | ||
{ | ||
public Int2NullableObjectHashMap() | ||
{ | ||
} | ||
|
||
public Int2NullableObjectHashMap( | ||
@DoNotSub final int initialCapacity, | ||
final float loadFactor) | ||
{ | ||
super(initialCapacity, loadFactor); | ||
} | ||
|
||
/** | ||
* Construct a new map allowing a configuration for initial capacity and load factor. | ||
* @param initialCapacity for the backing array | ||
* @param loadFactor limit for resizing on puts | ||
* @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries. | ||
*/ | ||
public Int2NullableObjectHashMap( | ||
@DoNotSub final int initialCapacity, | ||
final float loadFactor, | ||
final boolean shouldAvoidAllocation) | ||
{ | ||
super(initialCapacity, loadFactor, shouldAvoidAllocation); | ||
} | ||
|
||
/** | ||
* Copy construct a new map from an existing one. | ||
* | ||
* @param mapToCopy for construction. | ||
*/ | ||
public Int2NullableObjectHashMap(final Int2ObjectHashMap<V> mapToCopy) | ||
{ | ||
super(mapToCopy); | ||
} | ||
|
||
@Override | ||
protected Object mapNullValue(final Object value) | ||
{ | ||
return value == null ? NullReference.INSTANCE : value; | ||
} | ||
|
||
@Override | ||
protected V unmapNullValue(final Object value) | ||
{ | ||
return value == NullReference.INSTANCE ? null : (V)value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
agrona/src/main/java/org/agrona/collections/NullReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2014-2018 Real Logic Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.agrona.collections; | ||
|
||
public final class NullReference | ||
{ | ||
public static final NullReference INSTANCE = new NullReference(); | ||
|
||
public int hashCode() | ||
{ | ||
return 0; | ||
} | ||
|
||
public boolean equals(final Object obj) | ||
{ | ||
return obj == this; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
agrona/src/main/java/org/agrona/collections/Object2NullableObjectHashMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2014-2018 Real Logic Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.agrona.collections; | ||
|
||
/** | ||
* Variation of {@link Object2ObjectHashMap} that allows {@code null} values. | ||
*/ | ||
public class Object2NullableObjectHashMap<K, V> extends Object2ObjectHashMap<K, V> | ||
{ | ||
public Object2NullableObjectHashMap() | ||
{ | ||
} | ||
|
||
public Object2NullableObjectHashMap( | ||
final int initialCapacity, | ||
final float loadFactor) | ||
{ | ||
super(initialCapacity, loadFactor); | ||
} | ||
|
||
/** | ||
* @param initialCapacity for the map to override {@link #MIN_CAPACITY} | ||
* @param loadFactor for the map to override {@link Hashing#DEFAULT_LOAD_FACTOR}. | ||
* @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries. | ||
*/ | ||
public Object2NullableObjectHashMap( | ||
final int initialCapacity, | ||
final float loadFactor, | ||
final boolean shouldAvoidAllocation) | ||
{ | ||
super(initialCapacity, loadFactor, shouldAvoidAllocation); | ||
} | ||
|
||
@Override | ||
protected Object mapNullValue(final Object value) | ||
{ | ||
return value == null ? NullReference.INSTANCE : value; | ||
} | ||
|
||
@Override | ||
protected V unmapNullValue(final Object value) | ||
{ | ||
return value == NullReference.INSTANCE ? null : (V)value; | ||
} | ||
} |
Oops, something went wrong.