001/*
002 * $Id: Element.java 4128 2012-08-19 19:32:19Z kredel $
003 */
004
005package edu.jas.structure;
006
007
008import java.io.Serializable;
009
010
011/**
012 * Element interface. Basic functionality of elements, e.g. compareTo, equals,
013 * clone. 
014 * <b>Note:</b> extension of <code>Cloneable</code> removed in
015 * 2012-08-18, <code>clone()</code> is renamed to <code>copy()</code>.
016 * @param <C> element type. See the discussion in 
017 * <a href="http://www.artima.com/intv/bloch13.html">Bloch on Cloning</a>.
018 * @author Heinz Kredel
019 */
020
021public interface Element<C extends Element<C>> extends Comparable<C>, Serializable {
022
023
024    /**
025     * Clone this Element.
026     * @return Creates and returns a copy of this Element.
027     */
028    public C copy();
029
030
031    /**
032     * Test if this is equal to b.
033     * @param b
034     * @return true if this is equal to b, else false.
035     */
036    public boolean equals(Object b);
037
038
039    /**
040     * Hashcode of this Element.
041     * @return the hashCode.
042     */
043    public int hashCode();
044
045
046    /**
047     * Compare this to b. I.e. this &lt; b iff this.compareTo(b) &lt; 0.
048     * <b>Note:</b> may not be meaningful if structure has no order.
049     * @param b
050     * @return 0 if this is equal to b, -1 if this is less then b, else +1.
051     */
052    public int compareTo(C b);
053
054
055    /**
056     * Get the corresponding element factory.
057     * @return factory for this Element.
058     */
059    public ElemFactory<C> factory();
060
061
062    /**
063     * Get a scripting compatible string representation.
064     * @return script compatible representation for this Element.
065     */
066    public String toScript();
067
068
069    /**
070     * Get a scripting compatible string representation of the factory.
071     * @return script compatible representation for this ElemFactory.
072     */
073    public String toScriptFactory();
074
075}