📄 valuemapimpl.java
字号:
// The MIT License
//
// Copyright (c) 2004 Evren Sirin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
/*
* Created on Dec 28, 2003
*
*/
package org.mindswap.owls.process.impl;
import java.util.Hashtable;
import java.util.Map;
import org.mindswap.owls.process.DataFlow;
import org.mindswap.owls.process.DataFlowElement;
import org.mindswap.owls.process.Parameter;
import org.mindswap.owls.process.ParameterList;
import org.mindswap.owls.process.ValueMap;
import org.mindswap.owls.process.ValueRewriter;
/**
* @author Evren Sirin
*
*/
public class ValueMapImpl extends Hashtable implements ValueMap {
/**
*
*/
public ValueMapImpl() {
super();
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#setValue(org.mindswap.owls.process.Parameter)
*/
public void setValue(Parameter p, Object value) {
if(p == null) throw new NullPointerException("ValueMap cannot set a value for null parameter");
if(value == null) throw new NullPointerException("Value of parameter '" + p + "' cannot be set to null");
put(p, value);
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#getValue(org.mindswap.owls.process.Parameter)
*/
public Object getValue(Parameter p) {
return get(p);
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#hasValue(org.mindswap.owls.process.Parameter)
*/
public boolean hasValue(Parameter p) {
return containsKey(p);
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#clearValue(org.mindswap.owls.process.Parameter)
*/
public void clearValue(Parameter p) {
remove(p);
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#addMap(org.mindswap.owls.process.ValueMap)
*/
public void addMap(ValueMap valueMap) {
putAll(valueMap);
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#applyDataFlow(org.mindswap.owls.process.DataFlow)
*/
public void applyDataFlow(DataFlow dataFlow) {
applyDataFlow(dataFlow, null);
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#applyDataFlow(org.mindswap.owls.process.DataFlow, org.mindswap.owls.process.ValueRewriter)
*/
public void applyDataFlow(DataFlow dataFlow, ValueRewriter rewriter) {
Map.Entry[] entries = new Map.Entry[size()];
entrySet().toArray(entries);
for(int i = 0; i < entries.length; i++) {
Map.Entry entry = entries[i];
Parameter p = (Parameter) entry.getKey();
Object value = entry.getValue();
DataFlowElement dfe = dataFlow.getDFE(p);
if(dfe == null) continue;
for(int j = 0; j < dfe.size(); j++) {
Parameter x = dfe.parameterAt(j);
Object exists = getValue(x);
if(exists != null) {
if(!value.equals(exists))
System.err.println("Warning: Two different values are assigned to " + p);
}
else {
if(rewriter != null)
value = rewriter.rewrite(value.toString(), p.getType().getURI(), x.getType().getURI());
setValue(x, value);
}
}
}
}
/* (non-Javadoc)
* @see org.mindswap.owls.process.ValueMap#retianValues(org.mindswap.owls.process.ParameterList)
*/
public void retainValues(ParameterList params) {
Map.Entry[] entries = new Map.Entry[size()];
entrySet().toArray(entries);
for(int i = 0; i < entries.length; i++) {
Map.Entry entry = entries[i];
Parameter p = (Parameter) entry.getKey();
if(!params.contains(p))
clearValue(p);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -