001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging.formats.gif;
018
019import java.util.ArrayList;
020import java.util.Collections;
021import java.util.List;
022
023import org.apache.commons.imaging.common.ImageMetadata;
024
025public class GifImageMetadata implements ImageMetadata {
026
027    private static final String NEWLINE = System.lineSeparator();
028    private final int width;
029    private final int height;
030    private final List<GifImageMetadataItem> items;
031
032    GifImageMetadata(final int width, final int height, final List<GifImageMetadataItem> items) {
033        this.width = width;
034        this.height = height;
035        this.items = Collections.unmodifiableList(new ArrayList<>(items));
036    }
037
038    public int getHeight() {
039        return height;
040    }
041
042    @Override
043    public List<GifImageMetadataItem> getItems() {
044        return Collections.unmodifiableList(items);
045    }
046
047    public int getWidth() {
048        return width;
049    }
050
051    @Override
052    public String toString(String prefix) {
053        prefix = prefix == null ? "" : prefix;
054        final StringBuilder result = new StringBuilder();
055        result.append(String.format("%sGIF metadata:", prefix));
056        result.append(String.format("%sWidth: %d%s", prefix, width, NEWLINE));
057        result.append(String.format("%sHeight: %d%s", prefix, height, NEWLINE));
058        result.append(NEWLINE);
059        result.append(String.format("%sImages:", prefix));
060        for (final GifImageMetadataItem item : items) {
061            result.append(NEWLINE);
062            result.append(item.toString(prefix));
063        }
064        return result.toString();
065    }
066}