Search in sources :

Example 1 with ListModification

use of lombok.core.configuration.ConfigurationSource.ListModification in project lombok by rzwitserloot.

the class BubblingConfigurationResolver method resolve.

@SuppressWarnings("unchecked")
@Override
public <T> T resolve(ConfigurationKey<T> key) {
    boolean isList = key.getType().isList();
    List<List<ListModification>> listModificationsList = null;
    for (ConfigurationSource source : sources) {
        Result result = source.resolve(key);
        if (result == null)
            continue;
        if (isList) {
            if (listModificationsList == null)
                listModificationsList = new ArrayList<List<ListModification>>();
            listModificationsList.add((List<ListModification>) result.getValue());
        }
        if (result.isAuthoritative()) {
            if (isList)
                break;
            return (T) result.getValue();
        }
    }
    if (!isList)
        return null;
    if (listModificationsList == null)
        return (T) Collections.emptyList();
    List<Object> listValues = new ArrayList<Object>();
    Collections.reverse(listModificationsList);
    for (List<ListModification> listModifications : listModificationsList) {
        if (listModifications != null)
            for (ListModification modification : listModifications) {
                listValues.remove(modification.getValue());
                if (modification.isAdded())
                    listValues.add(modification.getValue());
            }
    }
    return (T) listValues;
}
Also used : ListModification(lombok.core.configuration.ConfigurationSource.ListModification) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Result(lombok.core.configuration.ConfigurationSource.Result)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListModification (lombok.core.configuration.ConfigurationSource.ListModification)1 Result (lombok.core.configuration.ConfigurationSource.Result)1