use of jetbrains.exodus.bindings.ComparableSet in project xodus by JetBrains.
the class PropertyRangeIterable method getHandleImpl.
@Override
@NotNull
protected EntityIterableHandle getHandleImpl() {
final int entityTypeId = getEntityTypeId();
final int propertyId = getPropertyId();
return new ConstantEntityIterableHandle(getStore(), getType()) {
@NotNull
@Override
public int[] getPropertyIds() {
return new int[] { propertyId };
}
@Override
public void toString(@NotNull final StringBuilder builder) {
super.toString(builder);
builder.append(entityTypeId);
builder.append('-');
builder.append(propertyId);
builder.append('-');
builder.append(min.toString());
builder.append('-');
builder.append(max.toString());
}
@Override
public void hashCode(@NotNull final EntityIterableHandleHash hash) {
hash.apply(entityTypeId);
hash.applyDelimiter();
hash.apply(propertyId);
hash.applyDelimiter();
hash.apply(min.toString());
hash.applyDelimiter();
hash.apply(max.toString());
}
@Override
public int getEntityTypeId() {
return entityTypeId;
}
@Override
public boolean isMatchedPropertyChanged(@NotNull final EntityId id, final int propId, @Nullable final Comparable oldValue, @Nullable final Comparable newValue) {
return propertyId == propId && entityTypeId == id.getTypeId() && (isRangeAffected(oldValue) || isRangeAffected(newValue));
}
private boolean isRangeAffected(@Nullable final Comparable value) {
if (value == null) {
return false;
}
if (value instanceof ComparableSet) {
final ComparableSet set = (ComparableSet) value;
// not null set should be non-empty
return isRangeAffectedByPrimitiveValue(set.getMinimum()) || isRangeAffectedByPrimitiveValue(set.getMaximum());
}
return isRangeAffectedByPrimitiveValue(value);
}
private boolean isRangeAffectedByPrimitiveValue(@NotNull final Comparable value) {
final Comparable lowercaseValue = PropertyTypes.toLowerCase(value);
return min.compareTo(lowercaseValue) <= 0 && max.compareTo(lowercaseValue) >= 0;
}
};
}
use of jetbrains.exodus.bindings.ComparableSet in project xodus by JetBrains.
the class PropertiesTable method createSecondaryKeys.
public static ByteIterable[] createSecondaryKeys(@NotNull final PropertyTypes propertyTypes, @NotNull final ByteIterable value, @NotNull final ComparableValueType type) {
final int valueTypeId = type.getTypeId();
if (valueTypeId == ComparableValueType.STRING_VALUE_TYPE) {
final PropertyValue propValue = propertyTypes.entryToPropertyValue(value);
return new ByteIterable[] { new PropertyValue(type, ((String) propValue.getData()).toLowerCase()).dataToEntry() };
}
if (valueTypeId == ComparableValueType.COMPARABLE_SET_VALUE_TYPE) {
final PropertyValue propValue = propertyTypes.entryToPropertyValue(value);
final ComparableSet data = (ComparableSet) propValue.getData();
final Class itemClass = data.getItemClass();
final ComparableBinding itemBinding = propertyTypes.getPropertyType(itemClass).getBinding();
final ByteIterable[] result = new ByteIterable[data.size()];
// noinspection unchecked
data.forEach((item, index) -> result[index] = itemBinding.objectToEntry(PropertyTypes.toLowerCase(item)));
return result;
}
// skip property type
return new ByteIterable[] { value.subIterable(1, value.getLength() - 1) };
}
use of jetbrains.exodus.bindings.ComparableSet in project xodus by JetBrains.
the class FindTests method testFindComparableSet.
public void testFindComparableSet() {
final StoreTransaction txn = getStoreTransactionSafe();
final Entity issue = txn.newEntity("Issue");
final ComparableSet<Integer> randomSet = new ComparableSet<>();
final Random rnd = new Random();
final int setSize = 20;
for (int i = 0; i < setSize; ++i) {
randomSet.addItem(rnd.nextInt());
}
for (int i = 0; i < 1000; ++i) {
Assert.assertEquals(setSize, randomSet.size());
issue.setProperty("randomSet", randomSet);
randomSet.forEach((item, index) -> Assert.assertEquals(issue, txn.find("Issue", "randomSet", item).getFirst()));
Assert.assertTrue(randomSet.removeItem(randomSet.iterator().next()));
while (true) {
final int newItem = rnd.nextInt();
if (randomSet.addItem(newItem)) {
Assert.assertTrue(txn.find("Issue", "randomSet", newItem).isEmpty());
break;
}
}
if (i % 20 == 19) {
txn.flush();
}
}
}
Aggregations