/*
* KAM Navigator Plugin
*
* URLs: http://openbel.org/
* Copyright (C) 2012, Selventa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openbel.cytoscape.navigator;
import org.openbel.framework.ws.model.Kam;
import cytoscape.CyNode;
import cytoscape.Cytoscape;
import cytoscape.data.CyAttributes;
/**
* Object that represent the identity of a Kam
*
* @author James McMahon <jmcmahon@selventa.com>
*/
public class KamIdentifier {
private final String name;
// long representing the date of when the kam was compiled
private final long compiledTime;
private final String wsdlUrl;
public KamIdentifier(Kam kam, String wsdlUrl) {
this.name = kam.getName();
this.compiledTime = kam.getLastCompiled().toGregorianCalendar()
.getTimeInMillis();
this.wsdlUrl = wsdlUrl;
nullCheck();
}
public KamIdentifier(CyNode node) {
CyAttributes nodeAtt = Cytoscape.getNodeAttributes();
String cyId = node.getIdentifier();
this.name = nodeAtt.getStringAttribute(cyId,
KamNavigatorPlugin.KAM_NAME_ATTR);
// will throw an exception if the date string is null or not parsable
this.compiledTime = Long.parseLong(nodeAtt.getStringAttribute(cyId,
KamNavigatorPlugin.KAM_COMPILE_DATE_ATTR));
this.wsdlUrl = nodeAtt.getStringAttribute(cyId,
KamNavigatorPlugin.WSDL_URL_ATTR);
nullCheck();
}
public String getName() {
return name;
}
public long getCompiledTime() {
return compiledTime;
}
public String getWsdlUrl() {
return wsdlUrl;
}
// TODO review and replace autogenerated hashcode / equals
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (compiledTime ^ (compiledTime >>> 32));
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((wsdlUrl == null) ? 0 : wsdlUrl.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
KamIdentifier other = (KamIdentifier) obj;
if (compiledTime != other.compiledTime)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (wsdlUrl == null) {
if (other.wsdlUrl != null)
return false;
} else if (!wsdlUrl.equals(other.wsdlUrl))
return false;
return true;
}
private void nullCheck() {
if (name == null || wsdlUrl == null) {
throw new NullPointerException("Can't construct a Kam Identifier with null parameters");
}
}
}