View Javadoc
1   package nom.tam.fits.header;
2   
3   /*
4    * #%L
5    * nom.tam FITS library
6    * %%
7    * Copyright (C) 1996 - 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  import nom.tam.fits.header.IFitsHeader.HDU;
35  import nom.tam.fits.header.IFitsHeader.SOURCE;
36  import nom.tam.fits.header.IFitsHeader.VALUE;
37  
38  /**
39   * generic key interface, create an IFitsHeader from a key.
40   * 
41   * @author     ritchie
42   * 
43   * @deprecated This class duplicates functionality that is available in {@link FitsKey}, {@link Standard}, ans/or
44   *                 {@link IFitsHeader}.
45   */
46  @Deprecated
47  public final class GenericKey {
48  
49      private static final int NUMBER_BASE = 10;
50  
51      /**
52       * Creates a generic FITS header key that may be used in any HDU, with any type of value, and does not have a
53       * standard comment.
54       * 
55       * @param      key the string to create the key for
56       * 
57       * @return         the IFitsHeader implementation for the key.
58       * 
59       * @deprecated     Use {@link FitsKey#FitsKey(String, VALUE, String)} instead.
60       */
61      @Deprecated
62      public static IFitsHeader create(String key) {
63          IFitsHeader result = lookup(key);
64          if (result == null) {
65              result = new FitsKey(key, SOURCE.UNKNOWN, HDU.ANY, VALUE.ANY, "");
66          }
67          return result;
68      }
69  
70      /**
71       * @deprecated      (<i>for internal use</i>) Creates a array of generic FITS header keys. The resulting keys have
72       *                      no HDU assignment or value type restrictions, not default comments. As such they may be used
73       *                      for accessing existing keys by the specified names, more so than for adding new values.
74       * 
75       * @param      keys the array of string keys
76       * 
77       * @return          the equivalent array of super-generic standarddized keys.
78       */
79      @Deprecated
80      public static IFitsHeader[] create(String[] keys) {
81          IFitsHeader[] result = new IFitsHeader[keys.length];
82          for (int index = 0; index < result.length; index++) {
83              result[index] = create(keys[index]);
84          }
85          return result;
86      }
87  
88      /**
89       * Returns the number value that appear at the trailing end of a FITS keyword. For example for <code>NAXIS2</code>
90       * it will return 2, while for <code>TFORM17</code> it will return 17. If there keyword does not end with a number,
91       * 0 is returned (FITS keywords are always numbered from 1 and up).
92       * 
93       * @param      key The FITS keyword from which to extract the trailing number.
94       * 
95       * @return         the number contained at the end of the keyword or else 0 if the keyword does not end with a
96       *                     number.
97       * 
98       * @deprecated     Use {@link IFitsHeader#extractIndices(String)} instead.
99       */
100     @Deprecated
101     public static int getN(String key) {
102         int index = key.length() - 1;
103         int n = 0;
104         int numberBase = 1;
105 
106         // Skip coordinate alternative marker letter at end...
107         if (Character.isAlphabetic(key.charAt(index))) {
108             index--;
109         }
110 
111         while (index >= 0 && Character.isDigit(key.charAt(index))) {
112             n = n + (key.charAt(index) - '0') * numberBase;
113             numberBase *= NUMBER_BASE;
114             index--;
115         }
116         return n;
117     }
118 
119     /**
120      * Lookup a string key in the standard key sets, resolving indexes and coordinate alternatives as appropriate for
121      * the set of standard FITS keywords. Same as {@link Standard#match(String)}, which is preferred.
122      * 
123      * @param      key the fits key to search.
124      * 
125      * @return         the found fits key or null
126      * 
127      * @deprecated     Use {@link Standard#match(String)} instead.
128      */
129     @Deprecated
130     public static IFitsHeader lookup(String key) {
131         return Standard.match(key);
132     }
133 
134     /**
135      * utility class do not instantiate it.
136      */
137     private GenericKey() {
138     }
139 }