Debian Codegraph @

src/main/java/nom/tam/fits/header/hierarch/IHierarchKeyFormatter.java

raw
1 package nom.tam.fits.header.hierarch;
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.utilities.FitsLineAppender;
35
36 /**
37 * Interface for formatting HIERARCH-style header keywords. Our own standard is to define such keywords internally as
38 * starting with the string <code>HIERARCH.</code> followed by a dot-separated hierarchy, or just an unusually long FITS
39 * keywords that cannot be represented by a standard 8-byte keyword. The HIERARCH formatted will take such string
40 * keywords and will format them according to its rules when writing them to FITS headers.
41 *
42 * @see nom.tam.fits.FitsFactory#setHierarchFormater(IHierarchKeyFormatter)
43 * @see Hierarch
44 */
45 @SuppressWarnings("deprecation")
46 public interface IHierarchKeyFormatter {
47
48 /**
49 * Returns the string reppresentation of the specified HIERARCH keyword in the FITS header
50 *
51 * @param key the HIERARCH keyword, in the dot separated convention of this library
52 *
53 * @return how this key looks in the FITS header with this formatting convention.
54 *
55 * @since 1.16
56 */
57 String toHeaderString(String key);
58
59 /**
60 * Appends the formatted HIERARCH keyword to the Fits line buffer. For example as a step towards builing up the
61 * header card for this keyword.
62 *
63 * @param key The HIERARCH keyword in out own internal representation (<code>HIERARCH.</code> followed by the
64 * dot-sepatated hierarchical components).
65 * @param buffer The FITS line buffer to which we want the formatted HIERARCH-style keyword to be appended.
66 */
67 void append(String key, FitsLineAppender buffer);
68
69 /**
70 * Returns the extra spaces required when printing the key, relative to a space separated components following
71 * "HIERARCH " and the "= " prior to the value.
72 *
73 * @param key the HIERARCH-style header key.
74 *
75 * @return the number of extra spaces relative to the most compact notation for the components.
76 *
77 * @since 1.16
78 */
79 int getExtraSpaceRequired(String key);
80
81 /**
82 * Sets whether case-sensitive (mixed-case) HIERARCH keywords are supported.
83 *
84 * @param value If <code>false</code> (default), then all HIERARCH keywords will be converted to upper-case.
85 * Otherwise, case will be preserved.
86 *
87 * @see #isCaseSensitive()
88 *
89 * @since 1.16
90 */
91 void setCaseSensitive(boolean value);
92
93 /**
94 * Checks if this formatter allows support for case-sensitive (mixed-case) hierarchical keywords.
95 *
96 * @return If <code>false</code> (default), then all HIERARCH keywords will be converted to upper-case. Otherwise,
97 * case will be preserved.
98 *
99 * @since 1.16
100 */
101 boolean isCaseSensitive();
102
103 /**
104 * Returns the assignment string that separates the hierarchical key and value components, for the given amount of
105 * space available. For example, the ESO HIERARCH convention just requires an '=' character (1 byte), but it is
106 * common to surround it with spaces before and after (3 bytes). As the spaces before an after are optional, the
107 * assignment can occupy anywhere between 1 to 3 bytes in the header card. So we can use the 3-byte version if there
108 * is room, or squeeze it down as needed.
109 *
110 * @param space (bytes) Number of characters available for the assignment marker to separate the keyword from the
111 * value part.
112 *
113 * @return The string to use for the assignment marker. If the space is smaller than the minimum assignment
114 * string length, then it returns the minimal assignment string.
115 *
116 * @since 1.20.2
117 *
118 * @see #getMinAssignLength()
119 */
120 default String getAssignStringForSpace(int space) {
121 switch (space) {
122 case 1:
123 return "="; // minimal '='
124 case 2:
125 return "= "; // standard FITS style assigmnment marker
126 default:
127 return " = "; // easy to read commonly used marker
128 }
129 }
130
131 /**
132 * Returns the minimum length of the sequence that separates keywords from values.
133 *
134 * @return the length of the minimal key/value separator string.
135 *
136 * @since 1.20.2
137 *
138 * @see #getAssignStringForSpace(int)
139 */
140 default int getMinAssignLength() {
141 return 1;
142 }
143 }