    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    private static final String NEWLINE = System.getProperty("line.separator");
    027    private final int width;
    028    private final int height;
    029    private final List<GifImageMetadataItem> items;
    030
    031    GifImageMetadata(final int width, final int height, final List<GifImageMetadataItem> items) {
    032        this.width = width;
    033        this.height = height;
    034        this.items = Collections.unmodifiableList(new ArrayList<>(items));
    035    }
    036
    037    @Override
    038    public String toString(String prefix) {
    039        prefix = prefix == null ? "" : prefix;
    040        final StringBuilder result = new StringBuilder();
    041        result.append(String.format("%sGIF metadata:", prefix));
    042        result.append(String.format("%sWidth: %d%s", prefix, width, NEWLINE));
    043        result.append(String.format("%sHeight: %d%s", prefix, height, NEWLINE));
    044        result.append(NEWLINE);
    045        result.append(String.format("%sImages:", prefix));
    046        for (final GifImageMetadataItem item : items) {
    047            result.append(NEWLINE);
    048            result.append(item.toString(prefix));
    049        }
    050        return result.toString();
    051    }
    052
    053    public int getWidth() {
    054        return width;
    055    }
    056
    057    public int getHeight() {
    058        return height;
    059    }
    060
    061    @Override
    062    public List<GifImageMetadataItem> getItems() {
    063        return Collections.unmodifiableList(items);
    064    }
    065}