io.permazen.JSetField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-main Show documentation
Show all versions of permazen-main Show documentation
Permazen classes that map Java model classes onto the core API.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen;
import com.google.common.base.Converter;
import com.google.common.base.Preconditions;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;
import io.permazen.change.SetFieldAdd;
import io.permazen.change.SetFieldClear;
import io.permazen.change.SetFieldRemove;
import io.permazen.core.ObjId;
import io.permazen.core.Transaction;
import io.permazen.schema.SetSchemaField;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentSkipListSet;
/**
* Represents a set field in a {@link JClass}.
*/
public class JSetField extends JCollectionField {
JSetField(Permazen jdb, String name, int storageId,
io.permazen.annotation.JSetField annotation, JSimpleField elementField, String description, Method getter) {
super(jdb, name, storageId, annotation, elementField, description, getter);
}
@Override
public io.permazen.annotation.JSetField getDeclaringAnnotation() {
return (io.permazen.annotation.JSetField)super.getDeclaringAnnotation();
}
@Override
public NavigableSet> getValue(JObject jobj) {
Preconditions.checkArgument(jobj != null, "null jobj");
return jobj.getTransaction().readSetField(jobj.getObjId(), this.storageId, false);
}
@Override
public R visit(JFieldSwitch target) {
return target.caseJSetField(this);
}
@Override
SetSchemaField toSchemaItem(Permazen jdb) {
final SetSchemaField schemaField = new SetSchemaField();
super.initialize(jdb, schemaField);
return schemaField;
}
@Override
SetElementIndexInfo toIndexInfo(JSimpleField subField) {
assert subField == this.elementField;
return new SetElementIndexInfo(this);
}
@Override
@SuppressWarnings("serial")
TypeToken> buildTypeToken(TypeToken elementType) {
return new TypeToken>() { }.where(new TypeParameter() { }, elementType);
}
// This method exists solely to bind the generic type parameters
@Override
@SuppressWarnings("serial")
void addChangeParameterTypes(List> types, Class targetType, TypeToken elementType) {
types.add(new TypeToken>() { }
.where(new TypeParameter() { }, targetType)
.where(new TypeParameter() { }, elementType.wrap()));
types.add(new TypeToken>() { }
.where(new TypeParameter() { }, targetType));
types.add(new TypeToken>() { }
.where(new TypeParameter() { }, targetType)
.where(new TypeParameter() { }, elementType.wrap()));
}
@Override
public NavigableSetConverter, ?> getConverter(JTransaction jtx) {
final Converter, ?> elementConverter = this.elementField.getConverter(jtx);
return elementConverter != null ? this.createConverter(elementConverter) : null;
}
// This method exists solely to bind the generic type parameters
private NavigableSetConverter createConverter(Converter elementConverter) {
return new NavigableSetConverter<>(elementConverter);
}
// POJO import/export
@Override
Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy