    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one
    003 * or more contributor license agreements.  See the NOTICE file
    004 * distributed with this work for additional information
    005 * regarding copyright ownership.  The ASF licenses this file
    006 * to you under the Apache License, Version 2.0 (the
    007 * "License"); you may not use this file except in compliance
    008 * with the License.  You may obtain a copy of the License at
    009 *
    010 *   https://www.apache.org/licenses/LICENSE-2.0
    011 *
    012 * Unless required by applicable law or agreed to in writing,
    013 * software distributed under the License is distributed on an
    014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015 * KIND, either express or implied.  See the License for the
    016 * specific language governing permissions and limitations
    017 * under the License.
    018 */
    019package org.apache.commons.compress.changes;
    020
    021import java.util.ArrayList;
    022import java.util.List;
    023
    024/**
    025 * Stores the results of a performed {@link ChangeSet} operation.
    026 */
    027public class ChangeSetResults {
    028
    029    private final List<String> addedFromChangeSet = new ArrayList<>();
    030    private final List<String> addedFromStream = new ArrayList<>();
    031    private final List<String> deleted = new ArrayList<>();
    032
    033    /**
    034     * Constructs a new instance.
    035     */
    036    public ChangeSetResults() {
    037        // empty
    038    }
    039
    040    /**
    041     * Adds the name of a file to the result list which has been copied from the {@link ChangeSet} to the target stream
    042     *
    043     * @param fileName the name of the file
    044     */
    045    void addedFromChangeSet(final String fileName) {
    046        addedFromChangeSet.add(fileName);
    047    }
    048
    049    /**
    050     * Adds the name of a file to the result list which has been copied from the source stream to the target stream.
    051     *
    052     * @param fileName the file name which has been added from the original stream
    053     */
    054    void addedFromStream(final String fileName) {
    055        addedFromStream.add(fileName);
    056    }
    057
    058    /**
    059     * Adds the file name of a recently deleted file to the result list.
    060     *
    061     * @param fileName the file which has been deleted
    062     */
    063    void deleted(final String fileName) {
    064        deleted.add(fileName);
    065    }
    066
    067    /**
    068     * Gets a list of file names which has been added from the {@link ChangeSet}
    069     *
    070     * @return the list of file names
    071     */
    072    public List<String> getAddedFromChangeSet() {
    073        return addedFromChangeSet;
    074    }
    075
    076    /**
    077     * Gets a list of file names which has been added from the original stream
    078     *
    079     * @return the list of file names
    080     */
    081    public List<String> getAddedFromStream() {
    082        return addedFromStream;
    083    }
    084
    085    /**
    086     * Gets a list of file names which has been deleted
    087     *
    088     * @return the list of file names
    089     */
    090    public List<String> getDeleted() {
    091        return deleted;
    092    }
    093
    094    /**
    095     * Tests if a file name already has been added to the result list
    096     *
    097     * @param fileName the file name to check
    098     * @return true, if this file name already has been added
    099     */
    100    boolean hasBeenAdded(final String fileName) {
    101        return addedFromChangeSet.contains(fileName) || addedFromStream.contains(fileName);
    102    }
    103}