/cpp/src/main/java/com/google/test/metric/cpp/dom/NodeList.java

http://testability-explorer.googlecode.com/ · Java · 56 lines · 31 code · 10 blank · 15 comment · 0 complexity · b4d1360840ca97387bc72403a258bffb MD5 · raw file

  1. /*
  2. * Copyright 2008 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.test.metric.cpp.dom;
  17. import java.util.ArrayList;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. public class NodeList implements Iterable<Node> {
  21. private final List<Node> nodes = new ArrayList<Node>();
  22. private final Node parent;
  23. public NodeList(Node parent) {
  24. this.parent = parent;
  25. }
  26. public void add(Node node) {
  27. nodes.add(node);
  28. node.setParent(parent);
  29. }
  30. @SuppressWarnings("unchecked")
  31. public <T> T get(int index) {
  32. return (T) nodes.get(index);
  33. }
  34. public Iterator<Node> iterator() {
  35. return nodes.iterator();
  36. }
  37. public int size() {
  38. return nodes.size();
  39. }
  40. public void remove(int index) {
  41. nodes.remove(index);
  42. }
  43. public int indexOf(Node node) {
  44. return nodes.indexOf(node);
  45. }
  46. }