You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OneCharIterator.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright 1999-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. /* $Id$ */
  17. package org.apache.fop.fo;
  18. import java.util.NoSuchElementException;
  19. /**
  20. * Class providing an iterator for one character.
  21. */
  22. public class OneCharIterator extends AbstractCharIterator {
  23. private boolean bFirst = true;
  24. private char charCode;
  25. /**
  26. * Constructor
  27. * @param c the character that this iterator should iterate.
  28. */
  29. public OneCharIterator(char c) {
  30. this.charCode = c;
  31. }
  32. /**
  33. * @return true if there is another element in the collection over which to
  34. * iterate (since this iterator only handles one character, this will return
  35. * false if it is past that character).
  36. */
  37. public boolean hasNext() {
  38. return bFirst;
  39. }
  40. /**
  41. * @return the next character, if there is one (since there is only one
  42. * character over which to iterate, it must be the first character).
  43. * @throws NoSuchElementException if past the first character
  44. */
  45. public char nextChar() throws NoSuchElementException {
  46. if (bFirst) {
  47. bFirst = false;
  48. return charCode;
  49. } else {
  50. throw new NoSuchElementException();
  51. }
  52. }
  53. }