net.openhft.collect.impl.hash.QHashObjSetFactorySO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hftc-impl-jdk8 Show documentation
Show all versions of hftc-impl-jdk8 Show documentation
Trove of primitive collections with Apache 2.0 license, built for Java Java 8
The newest version!
/*
* Copyright 2014 the original author or authors.
*
* 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 net.openhft.collect.impl.hash;
import net.openhft.collect.*;
import net.openhft.collect.hash.*;
import net.openhft.collect.impl.*;
import net.openhft.collect.set.ObjSet;
import net.openhft.collect.set.hash.HashObjSetFactory;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Set;
public abstract class QHashObjSetFactorySO extends ObjHashFactorySO
implements HashObjSetFactory {
QHashObjSetFactorySO(HashConfig hashConf, int defaultExpectedSize, boolean isNullAllowed) {
super(hashConf, defaultExpectedSize, isNullAllowed);
}
String keySpecialString() {
return ",equivalence=" + getEquivalence() +
",nullKeyAllowed=" + isNullKeyAllowed();
}
boolean keySpecialEquals(HashObjSetFactory> other) {
return NullableObjects.equals(getEquivalence(), other.getEquivalence()) &&
isNullKeyAllowed() == other.isNullKeyAllowed();
}
@Nullable
@Override
public Equivalence getEquivalence() {
return null;
}
MutableQHashObjSetGO uninitializedMutableSet() {
return new MutableQHashObjSet();
}
UpdatableQHashObjSetGO uninitializedUpdatableSet() {
return new UpdatableQHashObjSet();
}
ImmutableQHashObjSetGO uninitializedImmutableSet() {
return new ImmutableQHashObjSet();
}
@Override
public MutableQHashObjSetGO newMutableSet(int expectedSize) {
MutableQHashObjSetGO set = uninitializedMutableSet();
set.init(configWrapper, expectedSize);
return set;
}
@Override
public UpdatableQHashObjSetGO newUpdatableSet(int expectedSize) {
UpdatableQHashObjSetGO set = uninitializedUpdatableSet();
set.init(configWrapper, expectedSize);
return set;
}
@Override
public UpdatableQHashObjSetGO newUpdatableSet(Iterable extends E2> elements,
int expectedSize) {
if (elements instanceof ObjCollection) {
int size;
if (elements instanceof ObjSet) {
ObjSet elemSet = (ObjSet) elements;
if (elements instanceof SeparateKVObjQHash) {
SeparateKVObjQHash hash = (SeparateKVObjQHash) elements;
if (hash.hashConfig().equals(hashConf) &&
NullableObjects.equals(
elemSet.equivalence(), getEquivalence())) {
UpdatableQHashObjSetGO set = uninitializedUpdatableSet();
set.copy(hash);
return set;
}
}
if (NullableObjects.equals(elemSet.equivalence(), getEquivalence())) {
size = elemSet.size();
} else {
size = expectedSize;
}
} else {
size = expectedSize;
}
UpdatableQHashObjSetGO set = newUpdatableSet(size);
// noinspection unchecked
set.addAll((Collection extends E2>) elements);
return set;
} else {
int size = getEquivalence() == null && elements instanceof Set ?
((Set) elements).size() :
expectedSize;
UpdatableQHashObjSetGO set = newUpdatableSet(size);
for (E2 e : elements) {
set.add(e);
}
return set;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy