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

brooklyn.entity.rebind.dto.BasicPolicyMemento Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.entity.rebind.dto;

import java.io.Serializable;
import java.util.Map;

import brooklyn.mementos.PolicyMemento;

import com.google.common.collect.Maps;

/**
 * The persisted state of a location.
 * 
 * @author aled
 */
public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento, Serializable {

    private static final long serialVersionUID = -4025337943126838761L;
    
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder extends AbstractMemento.Builder {
        protected Map flags = Maps.newLinkedHashMap();
        
        public Builder from(PolicyMemento other) {
            super.from(other);
            flags.putAll(other.getFlags());
            return this;
        }
        public Builder flags(Map vals) {
            flags.putAll(vals); return this;
        }
        public PolicyMemento build() {
            return new BasicPolicyMemento(this);
        }
    }
    
	private Map flags;
    private Map fields;

    // Trusts the builder to not mess around with mutability after calling build()
	protected BasicPolicyMemento(Builder builder) {
	    flags = toPersistedMap(builder.flags);
	}
	
    protected void setCustomFields(Map fields) {
        this.fields = toPersistedMap(fields);
    }
    
    public Map getCustomFields() {
        return fromPersistedMap(fields);
    }

    @Override
    public Map getFlags() {
		return fromPersistedMap(flags);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy