source: josm/trunk/src/com/drew/metadata/Tag.java@ 10862

Last change on this file since 10862 was 10862, checked in by Don-vip, 8 years ago

update to metadata-extractor 2.9.1

File size: 3.6 KB
Line 
1/*
2 * Copyright 2002-2016 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21package com.drew.metadata;
22
23import com.drew.lang.annotations.NotNull;
24import com.drew.lang.annotations.Nullable;
25
26/**
27 * Models a particular tag within a {@link com.drew.metadata.Directory} and provides methods for obtaining its value.
28 * Immutable.
29 *
30 * @author Drew Noakes https://drewnoakes.com
31 */
32public class Tag
33{
34 private final int _tagType;
35 @NotNull
36 private final Directory _directory;
37
38 public Tag(int tagType, @NotNull Directory directory)
39 {
40 _tagType = tagType;
41 _directory = directory;
42 }
43
44 /**
45 * Gets the tag type as an int
46 *
47 * @return the tag type as an int
48 */
49 public int getTagType()
50 {
51 return _tagType;
52 }
53
54 /**
55 * Gets the tag type in hex notation as a String with padded leading
56 * zeroes if necessary (i.e. <code>0x100e</code>).
57 *
58 * @return the tag type as a string in hexadecimal notation
59 */
60 @NotNull
61 public String getTagTypeHex()
62 {
63 return String.format("0x%04x", _tagType);
64 }
65
66 /**
67 * Get a description of the tag's value, considering enumerated values
68 * and units.
69 *
70 * @return a description of the tag's value
71 */
72 @Nullable
73 public String getDescription()
74 {
75 return _directory.getDescription(_tagType);
76 }
77
78 /**
79 * Get whether this tag has a name.
80 *
81 * If <code>true</code>, it may be accessed via {@link #getTagName}.
82 * If <code>false</code>, {@link #getTagName} will return a string resembling <code>"Unknown tag (0x1234)"</code>.
83 *
84 * @return whether this tag has a name
85 */
86 @NotNull
87 public boolean hasTagName()
88 {
89 return _directory.hasTagName(_tagType);
90 }
91
92 /**
93 * Get the name of the tag, such as <code>Aperture</code>, or
94 * <code>InteropVersion</code>.
95 *
96 * @return the tag's name
97 */
98 @NotNull
99 public String getTagName()
100 {
101 return _directory.getTagName(_tagType);
102 }
103
104 /**
105 * Get the name of the {@link com.drew.metadata.Directory} in which the tag exists, such as
106 * <code>Exif</code>, <code>GPS</code> or <code>Interoperability</code>.
107 *
108 * @return name of the {@link com.drew.metadata.Directory} in which this tag exists
109 */
110 @NotNull
111 public String getDirectoryName()
112 {
113 return _directory.getName();
114 }
115
116 /**
117 * A basic representation of the tag's type and value. EG: <code>[Exif IFD0] FNumber - f/2.8</code>.
118 *
119 * @return the tag's type and value
120 */
121 @Override
122 @NotNull
123 public String toString()
124 {
125 String description = getDescription();
126 if (description == null)
127 description = _directory.getString(getTagType()) + " (unable to formulate description)";
128 return "[" + _directory.getName() + "] " + getTagName() + " - " + description;
129 }
130}
Note: See TracBrowser for help on using the repository browser.