org.drools.impl.adapters.NodeAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of knowledge-api Show documentation
Show all versions of knowledge-api Show documentation
The Drools and jBPM public API which is backwards compatible between releases.
The newest version!
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.drools.impl.adapters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.drools.definition.process.Connection;
import org.drools.definition.process.NodeContainer;
import org.kie.api.definition.process.Node;
public class NodeAdapter implements org.drools.definition.process.Node {
public Node delegate;
public NodeAdapter(Node delegate) {
this.delegate = delegate;
}
public Node getDelegate() {
return delegate;
}
public long getId() {
return delegate.getId();
}
public String getName() {
return delegate.getName();
}
public Map> getIncomingConnections() {
return adaptConnectionMap(delegate.getIncomingConnections());
}
public Map> getOutgoingConnections() {
return adaptConnectionMap(delegate.getOutgoingConnections());
}
public List getIncomingConnections(String type) {
return adaptConnectionList(delegate.getIncomingConnections(type));
}
public List getOutgoingConnections(String type) {
return adaptConnectionList(delegate.getOutgoingConnections(type));
}
public NodeContainer getNodeContainer() {
return new NodeContainerAdapter(delegate.getNodeContainer());
}
public Map getMetaData() {
return delegate.getMetaData();
}
public Object getMetaData(String name) {
return delegate.getMetaData().get(name);
}
private Map> adaptConnectionMap(Map> connections) {
if (connections == null) {
return null;
}
Map> result = new HashMap>();
for (Map.Entry> entry: connections.entrySet()) {
result.put(entry.getKey(), adaptConnectionList(entry.getValue()));
}
return result;
}
private List adaptConnectionList(List connections) {
if (connections == null) {
return null;
}
List result = new ArrayList(connections.size());
for (org.kie.api.definition.process.Connection connection: connections) {
result.add(new ConnectionAdapter(connection));
}
return result;
}
@Override
public int hashCode() {
return delegate.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof NodeAdapter && delegate.equals(((NodeAdapter)obj).delegate);
}
}