Skip to content

Package: DirectoryDrewLoader

DirectoryDrewLoader

nameinstructionbranchcomplexitylinemethod
DirectoryDrewLoader(List, int)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 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: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
convertType(Object)
M: 23 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
convertType(Rational[])
M: 28 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: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getTagName(int)
M: 8 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: 28 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
hasNext()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
next()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 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.Nonnegative;
30: import javax.annotation.Nonnull;
31: import java.util.List;
32: import java.util.NoSuchElementException;
33: import com.drew.metadata.Directory;
34: import it.tidalwave.image.Rational;
35:
36: /***********************************************************************************************************************
37: *
38: * @author Fabrizio Giudici
39: *
40: **********************************************************************************************************************/
41: public class DirectoryDrewLoader implements DirectoryLoader
42: {
43: @Nonnull
44: private final List<? extends Directory> directories;
45:
46: private final Directory directory;
47:
48: @Nonnegative
49: private final int index;
50:
51: /*******************************************************************************************************************
52: *
53: ******************************************************************************************************************/
54: public DirectoryDrewLoader (@Nonnull final List<? extends Directory> directories, @Nonnegative int index)
55: {
56: this.directories = directories;
57: this.index = index;
58: this.directory = directories.get(index);
59: }
60:
61: /*******************************************************************************************************************
62: * {@inheritDoc}
63: ******************************************************************************************************************/
64: @SuppressWarnings("unchecked")
65: @Override @Nonnull
66: public int[] getTags()
67: {
68: final var result = new int[directory.getTagCount()];
69: var j = 0;
70:
71:• for (final var tag : directory.getTags())
72: {
73: result[j++] = tag.getTagType();
74: }
75:
76: return result;
77:
78:
79: /** TODO
80: var xmp = new XMP();
81: xmp.loadFromAdapter(xmpAdapter);
82: xmp._setProperties(xmpDirectory.getXmpProperties()); // FIXME 18 e 19
83: return xmp;
84: */
85: }
86:
87: /*******************************************************************************************************************
88: * {@inheritDoc}
89: ******************************************************************************************************************/
90: @Override @Nonnull
91: public Object getObject (final int tag)
92: throws NoSuchElementException
93: {
94: checkIfTagExists(tag);
95: return convertType(directory.getObject(tag));
96: }
97:
98: /*******************************************************************************************************************
99: * {@inheritDoc}
100: ******************************************************************************************************************/
101: @Override @Nonnull
102: public String getTagName (final int tag)
103: {
104: checkIfTagExists(tag);
105: return directory.getTagName(tag);
106: }
107:
108: /*******************************************************************************************************************
109: * {@inheritDoc}
110: ******************************************************************************************************************/
111: @Override
112: public boolean containsTag (final int tag)
113: {
114: return directory.containsTag(tag);
115: }
116:
117: /*******************************************************************************************************************
118: * {@inheritDoc}
119: ******************************************************************************************************************/
120: @Override @Nonnull
121: public DirectoryLoader next()
122: {
123: return new DirectoryDrewLoader(directories, index + 1);
124: }
125:
126: /*******************************************************************************************************************
127: * {@inheritDoc}
128: ******************************************************************************************************************/
129: @Override
130: public boolean hasNext()
131: {
132:• return index + 1 < directories.size();
133: }
134:
135: /*******************************************************************************************************************
136: *
137: ******************************************************************************************************************/
138: private void checkIfTagExists (final int tag)
139: throws NoSuchElementException
140: {
141:• if (!containsTag(tag))
142: {
143: throw new NoSuchElementException("" + tag);
144: }
145: }
146:
147: /*******************************************************************************************************************
148: *
149: ******************************************************************************************************************/
150: @Nonnull
151: private static Object convertType (final @Nonnull Object value)
152: {
153:• if (value instanceof com.drew.lang.Rational)
154: {
155: final var drewRational = (com.drew.lang.Rational)value;
156: return Rational.of((int)drewRational.getNumerator(), (int)drewRational.getDenominator());
157: }
158:• else if (value instanceof com.drew.lang.Rational[])
159: {
160: return convertType((com.drew.lang.Rational[])value);
161: }
162:
163: return value;
164: }
165:
166: /*******************************************************************************************************************
167: *
168: ******************************************************************************************************************/
169: @Nonnull
170: private static Rational[] convertType (final @Nonnull com.drew.lang.Rational[] temp)
171: {
172: final var r = new Rational[temp.length];
173:
174:• for (var i = 0; i < r.length; i++)
175: {
176: r[i] = Rational.of((int)temp[i].getNumerator(), (int)temp[i].getDenominator());
177: }
178:
179: return r;
180: }
181: }