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 * http://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     * Adds the name of a file to the result list which has been copied from the {@link ChangeSet} to the target stream
035     *
036     * @param fileName the name of the file
037     */
038    void addedFromChangeSet(final String fileName) {
039        addedFromChangeSet.add(fileName);
040    }
041
042    /**
043     * Adds the name of a file to the result list which has been copied from the source stream to the target stream.
044     *
045     * @param fileName the file name which has been added from the original stream
046     */
047    void addedFromStream(final String fileName) {
048        addedFromStream.add(fileName);
049    }
050
051    /**
052     * Adds the file name of a recently deleted file to the result list.
053     *
054     * @param fileName the file which has been deleted
055     */
056    void deleted(final String fileName) {
057        deleted.add(fileName);
058    }
059
060    /**
061     * Gets a list of file names which has been added from the {@link ChangeSet}
062     *
063     * @return the list of file names
064     */
065    public List<String> getAddedFromChangeSet() {
066        return addedFromChangeSet;
067    }
068
069    /**
070     * Gets a list of file names which has been added from the original stream
071     *
072     * @return the list of file names
073     */
074    public List<String> getAddedFromStream() {
075        return addedFromStream;
076    }
077
078    /**
079     * Gets a list of file names which has been deleted
080     *
081     * @return the list of file names
082     */
083    public List<String> getDeleted() {
084        return deleted;
085    }
086
087    /**
088     * Tests if a file name already has been added to the result list
089     *
090     * @param fileName the file name to check
091     * @return true, if this file name already has been added
092     */
093    boolean hasBeenAdded(final String fileName) {
094        return addedFromChangeSet.contains(fileName) || addedFromStream.contains(fileName);
095    }
096}