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

com.kenshoo.pl.entity.CurrentEntityMutableState Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
package com.kenshoo.pl.entity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Collections.emptyList;


public class CurrentEntityMutableState implements CurrentEntityState {

    private final Map, Object> fields = new HashMap<>(1);
    private Map> manyByType;

    public boolean containsField(EntityField field) {
        return fields.containsKey(field);
    }

    @Override
    public  T get(EntityField field) {
        //noinspection unchecked
        T value = (T) fields.get(field);
        if (value == null && !fields.containsKey(field)) {
            throw new IllegalArgumentException("Field " + field + " of entity \"" + field.getEntityType().getName() + "\" is not fetched");
        }
        return value;
    }

    @Override
    public > List> getMany(E type) {
        return manyByType == null ? emptyList() : (List) manyByType.get(type);
    }

    public  void set(EntityField field, T value) {
        fields.put(field, value);
    }

    synchronized
    public > void add(E entityType, List> fieldsValueMaps) {
        if (manyByType == null) {
            manyByType = new HashMap<>();
        }
        manyByType.put(entityType, (List) fieldsValueMaps);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy