1 /**
2  * The utillib library.
3  * More information is available at http://www.jinchess.com/.
4  * Copyright (C) 2003 Alexander Maryanovsky.
5  * All rights reserved.
6  *
7  * The utillib library is free software; you can redistribute
8  * it and/or modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * The utillib library is distributed in the hope that it will
13  * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with utillib library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 
22 package free.util;
23 
24 import java.util.Enumeration;
25 import java.util.NoSuchElementException;
26 
27 
28 /**
29  * An implementation of the <code>Enumeration</code> interface which delegates
30  * to another <code>Enumeration</code>, but modifies the values via the
31  * {@link #map(Object)} method, which can be overridden to specify different
32  * mappings.
33  */
34 
35 public abstract class MappingEnumeration implements Enumeration{
36 
37 
38 
39   /**
40    * The delegate enumeration.
41    */
42 
43   private final Enumeration delegate;
44 
45 
46 
47   /**
48    * Creates a new <code>MappingEnumeration</code> object with the specified
49    * delegate.
50    */
51 
MappingEnumeration(Enumeration delegate)52   public MappingEnumeration(Enumeration delegate){
53     this.delegate = delegate;
54   }
55 
56 
57 
58   /**
59    * Returns whether there are more elements in this <code>Enumeration</code>.
60    */
61 
hasMoreElements()62   public boolean hasMoreElements(){
63     return delegate.hasMoreElements();
64   }
65 
66 
67 
68   /**
69    * Returns the result of invoking {@link #map(Object)} on the next element in
70    * the delegate enumeration.
71    */
72 
nextElement()73   public Object nextElement() throws NoSuchElementException{
74     return map(delegate.nextElement());
75   }
76 
77 
78 
79   /**
80    * Maps the specified element to some other element.
81    */
82 
map(Object element)83   public abstract Object map(Object element);
84 
85 
86 
87 }