View Javadoc
1   package nom.tam.util;
2   
3   /*
4    * #%L
5    * nom.tam FITS library
6    * %%
7    * Copyright (C) 2004 - 2024 nom-tam-fits
8    * %%
9    * This is free and unencumbered software released into the public domain.
10   *
11   * Anyone is free to copy, modify, publish, use, compile, sell, or
12   * distribute this software, either in source code form or as a compiled
13   * binary, for any purpose, commercial or non-commercial, and by any
14   * means.
15   *
16   * In jurisdictions that recognize copyright laws, the author or authors
17   * of this software dedicate any and all copyright interest in the
18   * software to the public domain. We make this dedication for the benefit
19   * of the public at large and to the detriment of our heirs and
20   * successors. We intend this dedication to be an overt act of
21   * relinquishment in perpetuity of all present and future rights to this
22   * software under copyright law.
23   *
24   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30   * OTHER DEALINGS IN THE SOFTWARE.
31   * #L%
32   */
33  
34  /**
35   * An <code>Iterator</code>-based interface for key / value pairs allowing insertions and reverse movement also.
36   *
37   * @param <KEY>   the generic type of the keyword element
38   * @param <VALUE> the generic type of the associated value
39   */
40  public interface Cursor<KEY, VALUE> extends java.util.Iterator<VALUE> {
41  
42      /**
43       * Add a keyed entry at the current location. The new entry is inserted before the entry that would be returned in
44       * the next invocation of 'next'. The new element is placed such that it will be called by a prev() call, but not a
45       * next() call.The return value for that call is unaffected. Note: this method is not in the Iterator interface.
46       *
47       * @param      key       the key of the value to add
48       * @param      reference the value to add
49       *
50       * @deprecated           Use {@link #add(Object)} instead
51       */
52      @Deprecated
53      void add(KEY key, VALUE reference);
54  
55      /**
56       * Add an unkeyed element to the collection. The new element is placed such that it will be called by a prev() call,
57       * but not a next() call.
58       *
59       * @param reference the value to add
60       */
61      void add(VALUE reference);
62  
63      /**
64       * Moves to the last element and returns it.
65       *
66       * @return the last element.
67       */
68      VALUE end();
69  
70      /**
71       * Checks if there is an element prior to the current one.
72       * 
73       * @return Whether there is a previous element in the collection
74       */
75      boolean hasPrev();
76  
77      /**
78       * Returns the count next element in the iteration.
79       *
80       * @param  count                            the offset
81       *
82       * @return                                  the n'th next element in the iteration
83       *
84       * @throws java.util.NoSuchElementException if the iteration has no more elements
85       */
86      VALUE next(int count);
87  
88      /**
89       * Returns the previous element in the ordered collection.
90       * 
91       * @return the previous element.
92       */
93      VALUE prev();
94  
95      /**
96       * Point the iterator to a particular keyed entry. Point to the end of the list if the key is not found.This method
97       * is not in the Iterator interface.
98       *
99       * @param key the key to search for
100      */
101     void setKey(KEY key);
102 }