📄 defaultentity.java
字号:
/*
* Created on 12-Apr-2005
*
* TODO All
*/
package ke.defaultimpl.core;
import java.util.HashMap;
import java.util.Set;
import ke.core.CoreException;
import ke.core.Entity;
import ke.core.ConceptType;
/**
* @author James Cunningham
* The instance of a DefaultEntity may have properties
* Each property could have multiple values
* TODO All
*/
public class DefaultEntity extends Entity {
/**
* @param id
* @param typeId
* An instance of a DefaultEntity may have property and value pairs
*/
public DefaultEntity(String id,
ConceptType type,
HashMap propertyValues) {
super(id, type);
this.propertyValues = propertyValues;
}
/**
* @param property
* @return
* @see ke.core.ConceptInstance#getPropertyValue(java.lang.String)
*/
public Object getPropertyValue(String property) {
if(!this.hasProperty(property))
return null; //TODO is this correct behaviour?
return this.propertyValues.get(property);
}
/**
* @param property
* @param value
* @return
* @see ke.core.ConceptInstance#setPropertyValue(java.lang.String, java.lang.Object)
*/
public boolean setPropertyValue(String property,
Object value) throws CoreException{
if(!this.hasProperty(property))
throw new CoreException("Error: invalid property name");
Class valueClass = this.getType().getPropertyClass(property);
if(!valueClass.isAssignableFrom(value.getClass()))
throw new CoreException("Error: value has invalid class type");
this.propertyValues.put(property, value);
return false;
}
/**
* @return
* @see ke.core.ConceptInstance#getPropertyNames()
*/
public String[] getPropertyNames() {
Set names = this.propertyValues.keySet();
return (String[])names.toArray(new String[names.size()]);
}
/**
* @param propertyName
* @return
*/
private boolean hasProperty(String propertyName) {
return this.propertyValues.keySet().contains(propertyName);
}
//------------------------------------
private HashMap propertyValues;//which is set of property name and value pairs (String,String)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -