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