View Javadoc
1   package nom.tam.fits.compression.provider.param.api;
2   
3   import nom.tam.fits.Header;
4   
5   /*
6    * #%L
7    * nom.tam FITS library
8    * %%
9    * Copyright (C) 1996 - 2024 nom-tam-fits
10   * %%
11   * This is free and unencumbered software released into the public domain.
12   *
13   * Anyone is free to copy, modify, publish, use, compile, sell, or
14   * distribute this software, either in source code form or as a compiled
15   * binary, for any purpose, commercial or non-commercial, and by any
16   * means.
17   *
18   * In jurisdictions that recognize copyright laws, the author or authors
19   * of this software dedicate any and all copyright interest in the
20   * software to the public domain. We make this dedication for the benefit
21   * of the public at large and to the detriment of our heirs and
22   * successors. We intend this dedication to be an overt act of
23   * relinquishment in perpetuity of all present and future rights to this
24   * software under copyright law.
25   *
26   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32   * OTHER DEALINGS IN THE SOFTWARE.
33   * #L%
34   */
35  
36  import nom.tam.fits.HeaderCard;
37  import nom.tam.fits.HeaderCardException;
38  import nom.tam.fits.header.IFitsHeader;
39  
40  /**
41   * <p>
42   * (<i>for internal use / no longer used</i>) Access to a specific FITS header card with runtime exceptions only.
43   * Regular modifications to {@link HeaderCard} may throw {@link HeaderCardException}s, which are hard exceptions. They
44   * really should have been softer runtime exceptions from the start, but unfortunately that was choice this library made
45   * a very long time ago, and we therefore stick to it, at least until the next major code revision (major version 2 at
46   * the earliest). So this class provides an alternative access to a header card converting any
47   * <code>HeaderCardException</code>s to {@link IllegalArgumentException}.
48   * </p>
49   * <p>
50   * Unlike {@link HeaderAccess} this class operates on single cards. Methods that specify a keywords are applied to the
51   * selected card if and only if the keyword matches that of the card's keyword.
52   * </p>
53   * 
54   * @see        Header
55   * 
56   * @deprecated This class serves no purpose since 1.19. Will remove in some future. Prior to 1.19 {@link Header} threw
57   *                 hard {@link HeaderCardException}, and this class was added so we can convert these into soft
58   *                 {@link IllegalArgumentException} instead. However, now that we demoted
59   *                 <code>HeaderCardException</code> to be soft exceptions itself, there is no reason to convert. It just
60   *                 adds confusion.
61   */
62  @Deprecated
63  public class HeaderCardAccess implements IHeaderAccess {
64  
65      private final HeaderCard headerCard;
66  
67      /**
68       * <p>
69       * Creates a new access to modifying a {@link HeaderCard} without the hard exceptions that <code>HeaderCard</code>
70       * may throw.
71       * </p>
72       * <p>
73       * Unlike {@link HeaderAccess} this class operates on single cards. Methods that specify a keywords are applied to
74       * the selected card if and only if the keyword matches that of the card's keyword.
75       * </p>
76       * 
77       * @param  headerCard               the FITS keyword of the card we will provide access to
78       * @param  value                    the initial string value for the card (assuming the keyword allows string
79       *                                      values).
80       * 
81       * @throws IllegalArgumentException if the header card could not be created
82       */
83      @Deprecated
84      public HeaderCardAccess(IFitsHeader headerCard, String value) throws IllegalArgumentException {
85          try {
86              this.headerCard = new HeaderCard(headerCard.key(), value, null);
87          } catch (HeaderCardException e) {
88              throw new IllegalArgumentException("header card could not be created");
89          }
90      }
91  
92      @Deprecated
93      @Override
94      public final Header getHeader() {
95          Header header = new Header();
96          header.addLine(headerCard);
97          return header;
98      }
99  
100     /**
101      * Returns the header card that this class is providing access to.
102      * 
103      * @return the Header card that we access through this class
104      * 
105      * @since  1.19
106      */
107     @Deprecated
108     public final HeaderCard getHeaderCard() {
109         return headerCard;
110     }
111 
112     @Deprecated
113     @Override
114     public void addValue(IFitsHeader key, int value) {
115         if (headerCard.getKey().equals(key.key())) {
116             headerCard.setValue(value);
117         }
118     }
119 
120     @Deprecated
121     @Override
122     public void addValue(IFitsHeader key, String value) {
123         if (headerCard.getKey().equals(key.key())) {
124             headerCard.setValue(value);
125         }
126     }
127 
128     @Deprecated
129     @Override
130     public HeaderCard findCard(IFitsHeader key) {
131         return findCard(key.key());
132     }
133 
134     @Deprecated
135     @Override
136     public HeaderCard findCard(String key) {
137         if (headerCard.getKey().equals(key)) {
138             return headerCard;
139         }
140         return null;
141     }
142 }