001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2005-2006 Robert Grimm
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * version 2 as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017: * USA.
018: */
019: package xtc.parser;
020:
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import xtc.tree.Node;
025:
026: /**
027: * A list of module names as a node.
028: *
029: * @author Robert Grimm
030: * @version $Revision: 1.12 $
031: */
032: public class ModuleList extends Node {
033:
034: /** The list of {@link ModuleName module names}. */
035: public List<ModuleName> names;
036:
037: /**
038: * Create a new module list.
039: *
040: * @param names The list of names.
041: */
042: public ModuleList(List<ModuleName> names) {
043: this .names = names;
044: }
045:
046: public int hashCode() {
047: return names.hashCode();
048: }
049:
050: public boolean equals(Object o) {
051: if (this == o)
052: return true;
053: if (!(o instanceof ModuleList))
054: return false;
055: return names.equals(((ModuleList) o).names);
056: }
057:
058: /**
059: * Determine whether this module list is empty.
060: *
061: * @return <code>true</code> if this is an empty module list.
062: */
063: public boolean isEmpty() {
064: return names.isEmpty();
065: }
066:
067: /**
068: * Get the size of this module list.
069: *
070: * @return The size.
071: */
072: public int size() {
073: return names.size();
074: }
075:
076: /**
077: * Get the module name at the specified index.
078: *
079: * @param idx The index.
080: * @return The module name at that position.
081: * @throws IndexOutOfBoundsException
082: * Signals that the index is out of range.
083: */
084: public ModuleName get(int idx) {
085: return names.get(idx);
086: }
087:
088: /**
089: * Rename this module list. This method {@link
090: * ModuleName#rename(ModuleMap) renames} all module names in this
091: * module list using the specified module map.
092: *
093: * @param renaming The module map.
094: * @return This list.
095: */
096: public ModuleList rename(ModuleMap renaming) {
097: final int length = names.size();
098: for (int i = 0; i < length; i++) {
099: names.set(i, names.get(i).rename(renaming));
100: }
101: return this ;
102: }
103:
104: public String toString() {
105: StringBuilder buf = new StringBuilder();
106: Iterator<?> iter = names.iterator();
107: buf.append('(');
108: while (iter.hasNext()) {
109: buf.append(iter.next().toString());
110: if (iter.hasNext()) {
111: buf.append(", ");
112: }
113: }
114: buf.append(')');
115: return buf.toString();
116: }
117:
118: }
|