00001 /* 00002 * Created on Sep 21, 2009 00003 * 00004 * TODO To change the template for this generated file go to 00005 * Window - Preferences - Java - Code Style - Code Templates 00006 */ 00007 package edu.tum.cs.srl.taxonomy; 00008 00009 import java.util.Vector; 00010 00011 public class Concept { 00012 public String name; 00013 public Concept parent = null; 00014 public Vector<Concept> children = new java.util.Vector<Concept>(); 00015 00016 public Concept(String name) { 00017 this.name = name; 00018 } 00019 00020 public int hashCode() { 00021 return name.hashCode(); 00022 } 00023 00024 public boolean equals(Object other) { 00025 if(other instanceof Concept) 00026 return name.equals(((Concept)other).name); 00027 return false; 00028 } 00029 00034 public void setParent(Concept c) { 00035 this.parent = c; 00036 c.children.add(this); 00037 } 00038 00043 public Vector<Concept> getDescendants() { 00044 Vector<Concept> ret = new Vector<Concept>(); 00045 ret.add(this); 00046 for(int i = 0; i < ret.size(); i++) { 00047 Concept c = ret.get(i); 00048 ret.addAll(c.children); 00049 } 00050 return ret; 00051 } 00052 00057 public Vector<Concept> getAncestors() { 00058 Vector<Concept> ret = new Vector<Concept>(); 00059 Concept parent = this.parent; 00060 while(parent != null) { 00061 ret.add(parent); 00062 parent = parent.parent; 00063 } 00064 return ret; 00065 } 00066 00067 public String toString() { 00068 return name; 00069 } 00070 }