/* * Copyright 2002-2017 Drew Noakes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * More information about this project is available at: * * https://drewnoakes.com/code/exif/ * https://github.com/drewnoakes/metadata-extractor */ package com.drew.metadata; import com.drew.lang.annotations.NotNull; import com.drew.lang.annotations.Nullable; import java.util.*; /** * A top-level object that holds the metadata values extracted from an image. *
* Metadata objects may contain zero or more {@link Directory} objects. Each directory may contain zero or more tags
* with corresponding values.
*
* @author Drew Noakes https://drewnoakes.com
*/
public final class Metadata
{
/**
* The list of {@link Directory} instances in this container, in the order they were added.
*/
@NotNull
private final Listnull
is returned.
*
* @param type the Directory type
* @param null
if none exist
*/
@Nullable
@SuppressWarnings("unchecked")
public true
if a {@link Directory} of the specified type exists, otherwise false
*/
public boolean containsDirectoryOfType(Class extends Directory> type)
{
for (Directory dir : _directories) {
if (type.isAssignableFrom(dir.getClass()))
return true;
}
return false;
}
/**
* Indicates whether any errors were reported during the reading of metadata values.
* This value will be true if Directory.hasErrors() is true for one of the contained {@link Directory} objects.
*
* @return whether one of the contained directories has an error
*/
public boolean hasErrors()
{
for (Directory directory : getDirectories()) {
if (directory.hasErrors())
return true;
}
return false;
}
@Override
public String toString()
{
int count = getDirectoryCount();
return String.format("Metadata (%d %s)",
count,
count == 1
? "directory"
: "directories");
}
}