Make first real commit: copy of CaRMetal 4.2.8
This commit is contained in:
parent
002acfc88e
commit
c312811084
1120 changed files with 226843 additions and 1 deletions
166
rene/util/list/ListClass.java
Normal file
166
rene/util/list/ListClass.java
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.util.list;
|
||||
|
||||
/**
|
||||
* A class for a list of things. The list is forward and backward chained.
|
||||
*
|
||||
* @see rene.list.ListElement
|
||||
*/
|
||||
|
||||
public class ListClass {
|
||||
ListElement First, Last; // Pointer to start and end of list.
|
||||
|
||||
/**
|
||||
* Generate an empty list.
|
||||
*/
|
||||
public ListClass() {
|
||||
First = null;
|
||||
Last = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a node to the list
|
||||
*/
|
||||
public void append(final ListElement l) {
|
||||
if (Last == null)
|
||||
init(l);
|
||||
else {
|
||||
Last.next(l);
|
||||
l.previous(Last);
|
||||
Last = l;
|
||||
l.next(null);
|
||||
l.list(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void prepend(final ListElement l)
|
||||
// prepend a node to the list
|
||||
{
|
||||
if (First == null)
|
||||
init(l);
|
||||
else {
|
||||
First.previous(l);
|
||||
l.next(First);
|
||||
First = l;
|
||||
l.previous(null);
|
||||
l.list(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @param l ListElement to be inserted.
|
||||
*
|
||||
* @param after If null, it works like prepend.
|
||||
*/
|
||||
public void insert(final ListElement l, final ListElement after) {
|
||||
if (after == Last)
|
||||
append(l);
|
||||
else if (after == null)
|
||||
prepend(l);
|
||||
else {
|
||||
after.next().previous(l);
|
||||
l.next(after.next());
|
||||
after.next(l);
|
||||
l.previous(after);
|
||||
l.list(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize the list with a single element.
|
||||
*/
|
||||
public void init(final ListElement l) {
|
||||
Last = First = l;
|
||||
l.previous(null);
|
||||
l.next(null);
|
||||
l.list(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a node from the list. The node really should be in the list, which
|
||||
* is not checked.
|
||||
*/
|
||||
public void remove(final ListElement l) {
|
||||
if (First == l) {
|
||||
First = l.next();
|
||||
if (First != null)
|
||||
First.previous(null);
|
||||
else
|
||||
Last = null;
|
||||
} else if (Last == l) {
|
||||
Last = l.previous();
|
||||
if (Last != null)
|
||||
Last.next(null);
|
||||
else
|
||||
First = null;
|
||||
} else {
|
||||
l.previous().next(l.next());
|
||||
l.next().previous(l.previous());
|
||||
}
|
||||
l.next(null);
|
||||
l.previous(null);
|
||||
l.list(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the list.
|
||||
*/
|
||||
public void removeall() {
|
||||
First = null;
|
||||
Last = null;
|
||||
}
|
||||
|
||||
/** remove everything after e */
|
||||
public void removeAfter(final ListElement e) {
|
||||
e.next(null);
|
||||
Last = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return First ListElement.
|
||||
*/
|
||||
public ListElement first() {
|
||||
return First;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Last ListElement.
|
||||
*/
|
||||
public ListElement last() {
|
||||
return Last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the class
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
ListElement e = First;
|
||||
String s = "";
|
||||
while (e != null) {
|
||||
s = s + e.content().toString() + ", ";
|
||||
e = e.next();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
79
rene/util/list/ListElement.java
Normal file
79
rene/util/list/ListElement.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.util.list;
|
||||
|
||||
/**
|
||||
* The nodes of a list.
|
||||
*
|
||||
* @see rene.list.ListClass
|
||||
*/
|
||||
|
||||
public class ListElement
|
||||
// A list node with pointers to previous and next element
|
||||
// and with a content of type Object.
|
||||
{
|
||||
ListElement Next, Previous; // the chain pointers
|
||||
Object Content; // the content of the node
|
||||
ListClass L; // Belongs to this list
|
||||
|
||||
public ListElement(final Object content)
|
||||
// get a new Element with the content and null pointers
|
||||
{
|
||||
Content = content;
|
||||
Next = Previous = null;
|
||||
L = null;
|
||||
}
|
||||
|
||||
// access methods:
|
||||
public Object content() {
|
||||
return Content;
|
||||
}
|
||||
|
||||
public ListElement next() {
|
||||
return Next;
|
||||
}
|
||||
|
||||
public ListElement previous() {
|
||||
return Previous;
|
||||
}
|
||||
|
||||
public void list(final ListClass l) {
|
||||
L = l;
|
||||
}
|
||||
|
||||
// modifying methods:
|
||||
public void content(final Object o) {
|
||||
Content = o;
|
||||
}
|
||||
|
||||
public void next(final ListElement o) {
|
||||
Next = o;
|
||||
}
|
||||
|
||||
public void previous(final ListElement o) {
|
||||
Previous = o;
|
||||
}
|
||||
|
||||
public ListClass list() {
|
||||
return L;
|
||||
}
|
||||
}
|
118
rene/util/list/Tree.java
Normal file
118
rene/util/list/Tree.java
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by Eric Hakenholz
|
||||
|
||||
This file is part of C.a.R. software.
|
||||
|
||||
C.a.R. is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
C.a.R. is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package rene.util.list;
|
||||
|
||||
/**
|
||||
* A node with a list of children trees.
|
||||
*/
|
||||
|
||||
public class Tree {
|
||||
ListClass Children; // list of children, each with Tree as content
|
||||
Object Content; // content
|
||||
ListElement Le; // the listelement containing the tree
|
||||
Tree Parent; // the parent tree
|
||||
|
||||
/** initialize with an object and no children */
|
||||
public Tree(final Object o) {
|
||||
Content = o;
|
||||
Children = new ListClass();
|
||||
Le = null;
|
||||
Parent = null;
|
||||
}
|
||||
|
||||
/** add a child tree */
|
||||
public void addchild(final Tree t) {
|
||||
final ListElement p = new ListElement(t);
|
||||
Children.append(p);
|
||||
t.Le = p;
|
||||
t.Parent = this;
|
||||
}
|
||||
|
||||
/** insert a child tree */
|
||||
public void insertchild(final Tree t) {
|
||||
if (!haschildren()) // simple case
|
||||
{
|
||||
addchild(t);
|
||||
return;
|
||||
}
|
||||
// give t my children
|
||||
t.Children = Children;
|
||||
// make t my only child
|
||||
Children = new ListClass();
|
||||
final ListElement p = new ListElement(t);
|
||||
Children.append(p);
|
||||
t.Le = p;
|
||||
t.Parent = this;
|
||||
// fix the parents of all grandchildren
|
||||
ListElement le = t.Children.first();
|
||||
while (le != null) {
|
||||
final Tree h = (Tree) (le.content());
|
||||
h.Parent = t;
|
||||
le = le.next();
|
||||
}
|
||||
}
|
||||
|
||||
/** remove the specific child tree (must be in the tree!!!) */
|
||||
public void remove(final Tree t) {
|
||||
if (t.parent() != this)
|
||||
return;
|
||||
Children.remove(t.Le);
|
||||
}
|
||||
|
||||
/** remove all children */
|
||||
public void removeall() {
|
||||
Children.removeall();
|
||||
}
|
||||
|
||||
// Access Methods:
|
||||
public boolean haschildren() {
|
||||
return Children.first() != null;
|
||||
}
|
||||
|
||||
public Tree firstchild() {
|
||||
return (Tree) Children.first().content();
|
||||
}
|
||||
|
||||
public Tree lastchild() {
|
||||
return (Tree) Children.last().content();
|
||||
}
|
||||
|
||||
public Tree parent() {
|
||||
return Parent;
|
||||
}
|
||||
|
||||
public ListClass children() {
|
||||
return Children;
|
||||
}
|
||||
|
||||
public Object content() {
|
||||
return Content;
|
||||
}
|
||||
|
||||
public void content(final Object o) {
|
||||
Content = o;
|
||||
}
|
||||
|
||||
public ListElement listelement() {
|
||||
return Le;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue