KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > request > SubRequestIteratorSupport


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - SubRequestIteratorSupport.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21 package org.snmp4j.agent.request;
22
23 import java.util.*;
24
25 /**
26  * This support class allows to implement a <code>SubRequestIterator</code>
27  * instance based on an <code>Iterator</code> that iterates on
28  * {@link SubRequest} instances.
29  *
30  * @author Frank Fock
31  * @version 1.0
32  */

33 public class SubRequestIteratorSupport implements SubRequestIterator {
34
35   private Iterator subRequests;
36
37   /**
38    * Creates a <code>SubRequestIterator</code> that decorates an
39    * <code>Iterator</code>.
40    *
41    * @param subRequests
42    * an <code>Iterator</code> on {@link SubRequest} instances or instances
43    * of other objects if {@link #mapToSubRequest(Object element)} is
44    * implemented (overwritten) accordingly.
45    */

46   public SubRequestIteratorSupport(Iterator subRequests) {
47     this.subRequests = subRequests;
48   }
49
50   public boolean hasNext() {
51     return subRequests.hasNext();
52   }
53
54   public Object JavaDoc next() {
55     return mapToSubRequest(subRequests.next());
56   }
57
58   public SubRequest nextSubRequest() throws NoSuchElementException {
59     return mapToSubRequest(subRequests.next());
60   }
61
62   public void remove() {
63     throw new UnsupportedOperationException JavaDoc();
64   }
65
66   /**
67    * Returns the <code>SubRequest</code> contained or represented by the
68    * supplied object (element of the iterator). The default implementation
69    * simply casts the supplied object to <code>SubRequest</code>.
70    *
71    * @param element
72    * an Object from which a <code>SubRequest</code> can be deduced.
73    * @return
74    * a <code>SubRequest</code> instance.
75    */

76   protected SubRequest mapToSubRequest(Object JavaDoc element) {
77     return (SubRequest)element;
78   }
79 }
80
Popular Tags