Element.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2011,  Michael Meyling <mime@qedeq.org>.
004  *
005  * "Hilbert II" is free software; you can redistribute
006  * it and/or modify it under the terms of the GNU General Public
007  * License as published by the Free Software Foundation; either
008  * version 2 of the License, or (at your option) any later version.
009  *
010  * This program is distributed in the hope that it will be useful,
011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013  * GNU General Public License for more details.
014  */
015 
016 package org.qedeq.kernel.se.base.list;
017 
018 
019 /**
020  * An element is either a list or an atom. Each list has an operator and
021  * contains elements which are also elements. A list has a size and their
022  * elements can be accessed by their position. An atom carries textual
023  * data, has no operator and no size in the previous sense.
024  *
025  @author  Michael Meyling
026  */
027 public interface Element {
028 
029     /**
030      * Is this an atom?
031      *
032      @return  <code>true</code> if this is an instance of {@link Atom}.
033      */
034     public boolean isAtom();
035 
036     /**
037      * Return this element as an {@link Atom}.
038      *
039      @return  This is an instance of {@link Atom}.
040      @throws  ClassCastException  This is no instance of {@link Atom}.
041      */
042     public Atom getAtom();
043 
044     /**
045      * Is this an {@link ElementList}?
046      *
047      @return  <code>true</code> if this is an instance of {@link ElementList}.
048      */
049     public boolean isList();
050 
051     /**
052      * Return this element as an ElementList.
053      *
054      @return  This as an instance of {@link ElementList}.
055      @throws  ClassCastException  This is no instance of {@link ElementList}.
056      */
057     public ElementList getList();
058 
059     /**
060      * Is this object equal to the given one?
061      *
062      @param   object     to compare with
063      @return  Is <code>object</code> equal to this one?
064      */
065     public boolean equals(Object object);
066 
067     /**
068      * Calculates the hash code.
069      *
070      @return  Hash code of this object
071      */
072     public int hashCode();
073 
074     /**
075      * Returns an identical object. This is a deep copy so later changes of
076      * the original element (or its sub parts) are not reflected in the copy.
077      *
078      @return Copy of this object.
079      */
080     public Element copy();
081 
082     /**
083      * Creates and returns a copy of this object, but
084      * replaces anything that {@link #equals} <code>argument</code>
085      * with a {@link #copy} of <code>replacement</code>.
086      *
087      @param   search      Check for occurrence of this.
088      @param   replacement Replace with this.
089      @return  Copy with replacements.
090      */
091     public Element replace(Element search, Element replacement);
092 
093     /**
094      * Get show this in <code>String</code> form.
095      *
096      @return  Readable list.
097      */
098     public String toString();
099 
100 }