1. /*
  2. * Copyright 2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of 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,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.collections.iterators;
  17. import java.util.NoSuchElementException;
  18. /**
  19. * Provides an implementation of an empty iterator.
  20. *
  21. * @since Commons Collections 3.1
  22. * @version $Revision: 1.2 $ $Date: 2004/05/26 20:57:43 $
  23. *
  24. * @author Stephen Colebourne
  25. */
  26. abstract class AbstractEmptyIterator {
  27. /**
  28. * Constructor.
  29. */
  30. protected AbstractEmptyIterator() {
  31. super();
  32. }
  33. public boolean hasNext() {
  34. return false;
  35. }
  36. public Object next() {
  37. throw new NoSuchElementException("Iterator contains no elements");
  38. }
  39. public boolean hasPrevious() {
  40. return false;
  41. }
  42. public Object previous() {
  43. throw new NoSuchElementException("Iterator contains no elements");
  44. }
  45. public int nextIndex() {
  46. return 0;
  47. }
  48. public int previousIndex() {
  49. return -1;
  50. }
  51. public void add(Object obj) {
  52. throw new UnsupportedOperationException("add() not supported for empty Iterator");
  53. }
  54. public void set(Object obj) {
  55. throw new IllegalStateException("Iterator contains no elements");
  56. }
  57. public void remove() {
  58. throw new IllegalStateException("Iterator contains no elements");
  59. }
  60. public Object getKey() {
  61. throw new IllegalStateException("Iterator contains no elements");
  62. }
  63. public Object getValue() {
  64. throw new IllegalStateException("Iterator contains no elements");
  65. }
  66. public Object setValue(Object value) {
  67. throw new IllegalStateException("Iterator contains no elements");
  68. }
  69. public void reset() {
  70. // do nothing
  71. }
  72. }