Skip to content

Package: DirectoryRawLoader

DirectoryRawLoader

nameinstructionbranchcomplexitylinemethod
DirectoryRawLoader(Directory)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
checkIfTagExists(int)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
containsTag(int)
M: 13 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertRationalArray(TagRational[])
M: 26 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getObject(int)
M: 30 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getSubDirectory(String)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getSubDirectoryNames()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTagName(int)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getTags()
M: 29 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
hasNext()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
next()
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.image.metadata.loader;
28:
29: import javax.annotation.Nonnull;
30: import java.util.NoSuchElementException;
31: import java.util.Objects;
32: import it.tidalwave.imageio.raw.Directory;
33: import it.tidalwave.imageio.raw.TagRational;
34: import it.tidalwave.image.Rational;
35:
36: /***********************************************************************************************************************
37: *
38: * @author Fabrizio Giudici
39: *
40: **********************************************************************************************************************/
41: public class DirectoryRawLoader implements DirectoryLoader
42: {
43: private final Directory directory;
44: private Directory nextDirectory;
45:
46: /*******************************************************************************************************************
47: *
48: *
49: ******************************************************************************************************************/
50: public DirectoryRawLoader (final @Nonnull Directory directory)
51: {
52: Objects.requireNonNull(directory, "directory");
53: this.directory = (Directory)directory;
54: }
55:
56: /*******************************************************************************************************************
57: * {@inheritDoc}
58: ******************************************************************************************************************/
59: @SuppressWarnings("unchecked")
60: @Override @Nonnull
61: public int[] getTags()
62: {
63: final var tags = directory.getTags();
64: final var result = new int[tags.size()];
65: var j = 0;
66:
67:• for (final var tag : tags)
68: {
69: result[j++] = tag.getCode();
70: }
71:
72: return result;
73: }
74:
75: /*******************************************************************************************************************
76: * {@inheritDoc}
77: ******************************************************************************************************************/
78: @Override @Nonnull
79: public String[] getSubDirectoryNames()
80: {
81: return directory.getSubDirectoryNames();
82: }
83:
84: /*******************************************************************************************************************
85: * {@inheritDoc}
86: ******************************************************************************************************************/
87: @Override @Nonnull
88: public DirectoryLoader getSubDirectory (final String name)
89: {
90: final var subDirectory = directory.getNamedDirectory(name);
91:• return (subDirectory != null) ? new DirectoryRawLoader(subDirectory) : null;
92: }
93:
94: /*******************************************************************************************************************
95: * {@inheritDoc}
96: ******************************************************************************************************************/
97: @Override
98: public boolean hasNext()
99: {
100: try
101: {
102:• return next() != null;
103: }
104: catch (NoSuchElementException e)
105: {
106: return false;
107: }
108: }
109:
110: /*******************************************************************************************************************
111: * {@inheritDoc}
112: ******************************************************************************************************************/
113: @Override @Nonnull
114: public DirectoryLoader next()
115: {
116:• if (nextDirectory == null)
117: {
118: nextDirectory = directory.getNextDirectory();
119: }
120:
121:• return (nextDirectory == null) ? null : new DirectoryRawLoader(nextDirectory);
122: }
123:
124: /*******************************************************************************************************************
125: * {@inheritDoc}
126: ******************************************************************************************************************/
127: @Override @Nonnull
128: public Object getObject (final int tag)
129: throws NoSuchElementException
130: {
131: checkIfTagExists(tag);
132: final var value = directory.getObject(tag);
133:
134:• if (value instanceof TagRational)
135: {
136: final var rational = (TagRational)value;
137: return Rational.of(rational.getNumerator(), rational.getDenominator());
138: }
139:
140:• else if (value instanceof TagRational[])
141: {
142: return convertRationalArray((TagRational[])value);
143: }
144:
145: return value;
146: }
147:
148: /*******************************************************************************************************************
149: * {@inheritDoc}
150: ******************************************************************************************************************/
151: @Override @Nonnull
152: public String getTagName (final int tag)
153: {
154: checkIfTagExists(tag);
155: return directory.getTagName(tag);
156: }
157:
158: /*******************************************************************************************************************
159: * {@inheritDoc}
160: ******************************************************************************************************************/
161: @Override
162: public boolean containsTag (final int tag)
163: {
164:• return directory != null && directory.containsTag(tag);
165: }
166:
167: /*******************************************************************************************************************
168: *
169: ******************************************************************************************************************/
170: private void checkIfTagExists (final int tag)
171: throws NoSuchElementException
172: {
173:• if (!containsTag(tag))
174: {
175: throw new NoSuchElementException("" + tag);
176: }
177: }
178:
179: /*******************************************************************************************************************
180: *
181: ******************************************************************************************************************/
182: private static Rational[] convertRationalArray (final TagRational[] temp)
183: {
184: final var r = new Rational[temp.length];
185:
186:• for (var i = 0; i < r.length; i++)
187: {
188: r[i] = Rational.of(temp[i].getNumerator(), temp[i].getDenominator());
189: }
190:
191: return r;
192: }
193: }