View Javadoc
1   package nom.tam.fits.header.hierarch;
2   
3   import java.util.Locale;
4   
5   import nom.tam.fits.utilities.FitsLineAppender;
6   
7   /*
8    * #%L
9    * nom.tam FITS library
10   * %%
11   * Copyright (C) 1996 - 2024 nom-tam-fits
12   * %%
13   * This is free and unencumbered software released into the public domain.
14   *
15   * Anyone is free to copy, modify, publish, use, compile, sell, or
16   * distribute this software, either in source code form or as a compiled
17   * binary, for any purpose, commercial or non-commercial, and by any
18   * means.
19   *
20   * In jurisdictions that recognize copyright laws, the author or authors
21   * of this software dedicate any and all copyright interest in the
22   * software to the public domain. We make this dedication for the benefit
23   * of the public at large and to the detriment of our heirs and
24   * successors. We intend this dedication to be an overt act of
25   * relinquishment in perpetuity of all present and future rights to this
26   * software under copyright law.
27   *
28   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
32   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
33   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34   * OTHER DEALINGS IN THE SOFTWARE.
35   * #L%
36   */
37  
38  import static nom.tam.fits.header.NonStandard.HIERARCH;
39  
40  /**
41   * @deprecated Non-standard HIERARCH keyword formatter that separates hierarchical keyword component by multiple while
42   *                 spaces. Otherwise, it is similar to {@link StandardIHierarchKeyFormatter}. Its use over the more
43   *                 standard formatter is discouraged.
44   */
45  @Deprecated
46  public class BlanksDotHierarchKeyFormatter implements IHierarchKeyFormatter {
47  
48      private final String blanks;
49  
50      private boolean allowMixedCase;
51  
52      /**
53       * Creates a HIERARCH keyword formatter instance with the desired number of blank spaces spearating components.
54       * 
55       * @param  count                    The number of blank spaces to separate hierarchical components (at least 1 is
56       *                                      required).
57       * 
58       * @throws IllegalArgumentException if count is less than 1
59       */
60      @Deprecated
61      public BlanksDotHierarchKeyFormatter(int count) throws IllegalArgumentException {
62          if (count < 1) {
63              throw new IllegalArgumentException("HIERARCH needs at least one blank space after it.");
64          }
65  
66          StringBuilder builder = new StringBuilder();
67          for (int index = 0; index < count; index++) {
68              builder.append(' ');
69          }
70          blanks = builder.toString();
71      }
72  
73      @Deprecated
74      @Override
75      public void append(String key, FitsLineAppender buffer) {
76          buffer.append(toHeaderString(key));
77      }
78  
79      @Deprecated
80      @Override
81      public int getExtraSpaceRequired(String key) {
82          return blanks.length() - 1;
83      }
84  
85      @Deprecated
86      @Override
87      public String toHeaderString(String key) {
88          if (!allowMixedCase) {
89              key = key.toUpperCase(Locale.US);
90          }
91  
92          return HIERARCH.key() + blanks + key.substring(HIERARCH.key().length() + 1);
93      }
94  
95      @Deprecated
96      @Override
97      public void setCaseSensitive(boolean value) {
98          allowMixedCase = value;
99      }
100 
101     @Deprecated
102     @Override
103     public final boolean isCaseSensitive() {
104         return allowMixedCase;
105     }
106 }