| 1 |
package nom.tam.fits.header.hierarch; |
| 2 |
|
| 3 |
/*- |
| 4 |
* #%L |
| 5 |
* nom.tam.fits |
| 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.FitsFactory; |
| 35 |
|
| 36 |
/** |
| 37 |
* Helper class for creating HIERARCH-style (or long) FITS keywords for use within this library. |
| 38 |
* |
| 39 |
* @author Attila Kovacs |
| 40 |
* |
| 41 |
* @since 1.18 |
| 42 |
*/ |
| 43 |
public final class Hierarch { |
| 44 |
|
| 45 |
/** |
| 46 |
* The string prefix we use internally to identify HIERARCH-style keywords. |
| 47 |
*/ |
| 48 |
private static final String PREFIX = "HIERARCH"; |
| 49 |
|
| 50 |
/** |
| 51 |
* Private constructor since we don't want to instantiate this class. |
| 52 |
*/ |
| 53 |
private Hierarch() { |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Creates a hierarch-style (or long) keyword to use within this library, by prepending "HIERARCH." to the |
| 58 |
* user-specified long or hierarchical keyword. For example, for the argument <code>"group.property"</code>, this |
| 59 |
* will return <code>"HIERARCH.group.property"</code>, which is how we refer to this keyword internally within this |
| 60 |
* library. |
| 61 |
* |
| 62 |
* @param keyword The user-defined long or hierarchical keyword. Hierarchical keywords should have components |
| 63 |
* separated by dots, e.g. <code>system.subsystem.property</code>. Case-sensitivity depends on |
| 64 |
* the formatter used, see e.g. {@link IHierarchKeyFormatter#isCaseSensitive()}. |
| 65 |
* |
| 66 |
* @return The keyword, prepended by "HIERARCH." as per the internal convention for referring to such |
| 67 |
* keywords within this library. |
| 68 |
* |
| 69 |
* @since 1.18 |
| 70 |
* |
| 71 |
* @see #key(String...) |
| 72 |
* @see FitsFactory#getHierarchFormater() |
| 73 |
* @see IHierarchKeyFormatter#setCaseSensitive(boolean) |
| 74 |
*/ |
| 75 |
public static String key(String keyword) { |
| 76 |
return PREFIX + "." + keyword; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Creates a hierarch-style keyword from its hierarchical components to use within this library, For example, for |
| 81 |
* the arguments <code>"group"</code> and <code>"property"</code>, this will return |
| 82 |
* <code>"HIERARCH.group.property"</code>, which is how we refer to this keyword internally within this library. |
| 83 |
* |
| 84 |
* @param components A list of hierarchical keyword components. These will be concatenated into a dot-separated |
| 85 |
* keyword, and prepended by <code>HIERARCH.</code>. Case-sensitivity depends on the |
| 86 |
* formatter used, see e.g. {@link IHierarchKeyFormatter#isCaseSensitive()}. |
| 87 |
* |
| 88 |
* @return The keyword, prepended by "HIERARCH." as per the internal convention for referring to such |
| 89 |
* keywords within this library. |
| 90 |
* |
| 91 |
* @since 1.18 |
| 92 |
* |
| 93 |
* @see #key(String) |
| 94 |
* @see FitsFactory#getHierarchFormater() |
| 95 |
* @see IHierarchKeyFormatter#setCaseSensitive(boolean) |
| 96 |
*/ |
| 97 |
public static String key(String... components) { |
| 98 |
StringBuilder s = new StringBuilder(PREFIX); |
| 99 |
for (int i = 0; i < components.length; i++) { |
| 100 |
s.append('.'); |
| 101 |
s.append(components[i]); |
| 102 |
} |
| 103 |
return s.toString(); |
| 104 |
} |
| 105 |
|
| 106 |
} |