All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jharks.workflow.WorkFlowKey Maven / Gradle / Ivy

package org.jharks.workflow;

import java.lang.InstantiationException;

public class WorkFlowKey {

    private String type;
    
    private String className;
    
    public WorkFlowKey(String type, String className) {
        if (type == null || className == null) 
            throw new IllegalArgumentException(
                    "type or name argument is null.");
        this.type = type;
        this.className = className;
    }

    /**
     * @return the className
     */
    public String getClassName() {
        return className;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }
    
    public int compareTo(Object arg0)
    {
        //TODO: decide whether to actually build out compare
        //method passed on some sequence while building the 
        //AnswerContext.
        return 0;
    }
    
    /**
     * @see java.lang.Object#clone()
     */
    public Object clone()
    {
        try
        {
            WorkFlowKey key =
                (WorkFlowKey) this.getClass().newInstance();
            key.type = type;
            key.className = className;
  
            return key;
        }
        catch (InstantiationException e)
        {
            return null;
        }
        catch (IllegalAccessException e)
        {
            return null;
        }
    }
    
    /**
     * Determines if the  objects are equal by comparing type within key
     *
     * @return true if types are the same (ignore case) or both are null.
     */
    public boolean equals(Object o)
    {
        if (!(o instanceof WorkFlowKey)) return false;
        if (this == o) return true;
        WorkFlowKey wfk = (WorkFlowKey) o;
        
        String s1 = getType(); 
        String s2 = wfk.getType();
        return s1 == null ? s2 == null : s1.equalsIgnoreCase(s2);
    }
    
    /**
     * Returns a hash code for the workflowkey. Bases the hash
     * code on the type string hash.
     */
    public int hashCode()
    {
        int result = 17;
        String type = getType();
        result = result * 37 + (type == null ? 0 : type.hashCode());
       
        return result;
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy