com.memority.citadel.shared.api.context.SimpleAttributeValues Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of citadel-api Show documentation
Show all versions of citadel-api Show documentation
This artifact provides the API classes that are necessary to implement general configuration Rules on the Memority IM platform.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Citadel API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.citadel.shared.api.context;
import org.apache.commons.lang3.Validate;
import com.memority.toolkit.core.api.changetracking.ChangeTrackingMap;
import com.memority.citadel.shared.api.im.AttributeValue;
import com.memority.citadel.shared.api.im.HasAttributeValuesMapLike;
import com.memority.citadel.shared.api.im.HasMutableAttributeValues;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A simple implementation of a mutable {@link HasAttributeValuesMapLike}, to serve as a basis
* for other implementations if needed.
*/
public class SimpleAttributeValues implements HasMutableAttributeValues {
@SuppressWarnings("WeakerAccess")
protected final ChangeTrackingMap> map;
protected SimpleAttributeValues(Map> map) {
Validate.notNull(map);
this.map = new ChangeTrackingMap<>(map);
}
public SimpleAttributeValues(List> attributeValues) {
Validate.notNull(attributeValues);
this.map = new ChangeTrackingMap<>(new HashMap<>());
initAttributes(attributeValues);
}
protected void initAttributes(List> attributeValues) {
// Set each attribute value
attributeValues.forEach(this::setAttributeValue);
resetChanged(); // initial state
}
public boolean hasChanged() {
return map.hasChanged();
}
public void resetChanged() {
map.resetChanged();
}
@Override
public Map> attributeValueMap() {
return this.map;
}
}