All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jsimpledb.JListFieldInfo Maven / Gradle / Ivy


/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package org.jsimpledb;

import com.google.common.base.Converter;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;

import java.util.List;

import org.jsimpledb.change.ListFieldAdd;
import org.jsimpledb.change.ListFieldClear;
import org.jsimpledb.change.ListFieldRemove;
import org.jsimpledb.change.ListFieldReplace;
import org.jsimpledb.core.ObjId;
import org.jsimpledb.core.Transaction;

class JListFieldInfo extends JCollectionFieldInfo {

    private static final int LIST_INDEX_ENTRY_QUERY = 1;

    JListFieldInfo(JListField jfield) {
        super(jfield);
    }

    @Override
    public TypeToken getTypeToken(Class context) {
        return this.buildTypeToken(this.getElementFieldInfo().getTypeToken(context).wrap());
    }

    // This method exists solely to bind the generic type parameters
    @SuppressWarnings("serial")
    private  TypeToken> buildTypeToken(TypeToken elementType) {
        return new TypeToken>() { }.where(new TypeParameter() { }, elementType);
    }

    @Override
    void registerChangeListener(Transaction tx, int[] path, Iterable types, AllChangesListener listener) {
        tx.addListFieldChangeListener(this.storageId, path, types, listener);
    }

    @Override
     void addChangeParameterTypes(List> types, Class targetType) {
        this.addChangeParameterTypes(types, targetType, this.getElementFieldInfo().getTypeToken(targetType));
    }

    // This method exists solely to bind the generic type parameters
    @SuppressWarnings("serial")
    private  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()));
        types.add(new TypeToken>() { }
          .where(new TypeParameter() { }, targetType)
          .where(new TypeParameter() { }, elementType.wrap()));
    }

    @Override
    public ListConverter getConverter(JTransaction jtx) {
        final Converter elementConverter = this.getElementFieldInfo().getConverter(jtx);
        return elementConverter != null ? this.createConverter(elementConverter) : null;
    }

    // This method exists solely to bind the generic type parameters
    private  ListConverter createConverter(Converter elementConverter) {
        return new ListConverter(elementConverter);
    }

    @Override
    public void copyRecurse(CopyState copyState, JTransaction srcTx, JTransaction dstTx,
      ObjId id, int storageId, int fieldIndex, int[] fields) {
        assert storageId == this.getElementFieldInfo().storageId;
        this.copyRecurse(copyState, srcTx, dstTx, srcTx.tx.readListField(id, this.storageId, false), fieldIndex, fields);
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy