edu.stanford.protege.widgetmap.shared.node.NodeProperties Maven / Gradle / Ivy
package edu.stanford.protege.widgetmap.shared.node;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.gwt.user.client.rpc.IsSerializable;
import java.util.*;
/**
* Author: Matthew Horridge
* Stanford University
* Bio-Medical Informatics Research Group
* Date: 05/12/2013
*/
public class NodeProperties implements IsSerializable {
private static final NodeProperties EMPTY_NODE_PROPERTIES = new NodeProperties();
// Cannot be final because of GWT serialization
private Map properties = new LinkedHashMap();
private NodeProperties() {
}
private NodeProperties(Map properties) {
this.properties.putAll(properties);
}
public static Builder builder() {
return new Builder();
}
public static NodeProperties emptyNodeProperties() {
return EMPTY_NODE_PROPERTIES;
}
public String getPropertyValue(String propertyName, String defaultValue) {
String value = properties.get(propertyName);
if (value == null) {
return defaultValue;
}
return value;
}
public List getProperties() {
return new ArrayList(properties.keySet());
}
public static class Builder {
private Map propertiesMap = new LinkedHashMap();
public Builder setValue(String property, String value) {
propertiesMap.put(property, value);
return this;
}
public NodeProperties build() {
if(propertiesMap.isEmpty()) {
return EMPTY_NODE_PROPERTIES;
}
else {
return new NodeProperties(new LinkedHashMap(propertiesMap));
}
}
}
@Override
public String toString() {
MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper("NodeProperties");
for(String property : properties.keySet()) {
helper.add(property, properties.get(property));
}
return helper.toString();
}
}