    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 an performed ChangeSet operation.
    026 */
    027public class ChangeSetResults {
    028    private final List<String> addedFromChangeSet = new ArrayList<>();
    029    private final List<String> addedFromStream = new ArrayList<>();
    030    private final List<String> deleted = new ArrayList<>();
    031
    032    /**
    033     * Adds the file name of a recently deleted file to the result list.
    034     * @param fileName the file which has been deleted
    035     */
    036    void deleted(final String fileName) {
    037        deleted.add(fileName);
    038    }
    039
    040    /**
    041     * Adds the name of a file to the result list which has been
    042     * copied from the source stream to the target stream.
    043     * @param fileName the file name which has been added from the original stream
    044     */
    045    void addedFromStream(final String fileName) {
    046        addedFromStream.add(fileName);
    047    }
    048
    049    /**
    050     * Adds the name of a file to the result list which has been
    051     * copied from the changeset to the target stream
    052     * @param fileName the name of the file
    053     */
    054    void addedFromChangeSet(final String fileName) {
    055        addedFromChangeSet.add(fileName);
    056    }
    057
    058    /**
    059     * Returns a list of file names which has been added from the changeset
    060     * @return the list of file names
    061     */
    062    public List<String> getAddedFromChangeSet() {
    063        return addedFromChangeSet;
    064    }
    065
    066    /**
    067     * Returns a list of file names which has been added from the original stream
    068     * @return the list of file names
    069     */
    070    public List<String> getAddedFromStream() {
    071        return addedFromStream;
    072    }
    073
    074    /**
    075     * Returns a list of file names which has been deleted
    076     * @return the list of file names
    077     */
    078    public List<String> getDeleted() {
    079        return deleted;
    080    }
    081
    082    /**
    083     * Checks if an file name already has been added to the result list
    084     * @param fileName the file name to check
    085     * @return true, if this file name already has been added
    086     */
    087    boolean hasBeenAdded(final String fileName) {
    088        return addedFromChangeSet.contains(fileName) || addedFromStream.contains(fileName);
    089    }
    090}