1 /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">http://www.qedeq.org 2 * 3 * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. 4 * 5 * "Hilbert II" is free software; you can redistribute 6 * it and/or modify it under the terms of the GNU General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 */ 15 16 package org.qedeq.kernel.se.base.list; 17 18 19 /** 20 * An element is either a list or an atom. Each list has an operator and 21 * contains elements which are also elements. A list has a size and their 22 * elements can be accessed by their position. An atom carries textual 23 * data, has no operator and no size in the previous sense. 24 * 25 * @author Michael Meyling 26 */ 27 public interface Element { 28 29 /** 30 * Is this an atom? 31 * 32 * @return <code>true</code> if this is an instance of {@link Atom}. 33 */ 34 public boolean isAtom(); 35 36 /** 37 * Return this element as an {@link Atom}. 38 * 39 * @return This is an instance of {@link Atom}. 40 * @throws ClassCastException This is no instance of {@link Atom}. 41 */ 42 public Atom getAtom(); 43 44 /** 45 * Is this an {@link ElementList}? 46 * 47 * @return <code>true</code> if this is an instance of {@link ElementList}. 48 */ 49 public boolean isList(); 50 51 /** 52 * Return this element as an ElementList. 53 * 54 * @return This as an instance of {@link ElementList}. 55 * @throws ClassCastException This is no instance of {@link ElementList}. 56 */ 57 public ElementList getList(); 58 59 /** 60 * Is this object equal to the given one? 61 * 62 * @param object to compare with 63 * @return Is <code>object</code> equal to this one? 64 */ 65 public boolean equals(Object object); 66 67 /** 68 * Calculates the hash code. 69 * 70 * @return Hash code of this object 71 */ 72 public int hashCode(); 73 74 /** 75 * Returns an identical object. This is a deep copy so later changes of 76 * the original element (or its sub parts) are not reflected in the copy. 77 * 78 * @return Copy of this object. 79 */ 80 public Element copy(); 81 82 /** 83 * Creates and returns a copy of this object, but 84 * replaces anything that {@link #equals} <code>argument</code> 85 * with a {@link #copy} of <code>replacement</code>. 86 * 87 * @param search Check for occurrence of this. 88 * @param replacement Replace with this. 89 * @return Copy with replacements. 90 */ 91 public Element replace(Element search, Element replacement); 92 93 /** 94 * Get show this in <code>String</code> form. 95 * 96 * @return Readable list. 97 */ 98 public String toString(); 99 100 }