ChangeSetResults.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one
  3.  * or more contributor license agreements.  See the NOTICE file
  4.  * distributed with this work for additional information
  5.  * regarding copyright ownership.  The ASF licenses this file
  6.  * to you under the Apache License, Version 2.0 (the
  7.  * "License"); you may not use this file except in compliance
  8.  * with the License.  You may obtain a copy of the License at
  9.  *
  10.  * http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing,
  13.  * software distributed under the License is distributed on an
  14.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15.  * KIND, either express or implied.  See the License for the
  16.  * specific language governing permissions and limitations
  17.  * under the License.
  18.  */
  19. package org.apache.commons.compress.changes;

  20. import java.util.ArrayList;
  21. import java.util.List;

  22. /**
  23.  * Stores the results of a performed {@link ChangeSet} operation.
  24.  */
  25. public class ChangeSetResults {

  26.     private final List<String> addedFromChangeSet = new ArrayList<>();
  27.     private final List<String> addedFromStream = new ArrayList<>();
  28.     private final List<String> deleted = new ArrayList<>();

  29.     /**
  30.      * Adds the name of a file to the result list which has been copied from the {@link ChangeSet} to the target stream
  31.      *
  32.      * @param fileName the name of the file
  33.      */
  34.     void addedFromChangeSet(final String fileName) {
  35.         addedFromChangeSet.add(fileName);
  36.     }

  37.     /**
  38.      * Adds the name of a file to the result list which has been copied from the source stream to the target stream.
  39.      *
  40.      * @param fileName the file name which has been added from the original stream
  41.      */
  42.     void addedFromStream(final String fileName) {
  43.         addedFromStream.add(fileName);
  44.     }

  45.     /**
  46.      * Adds the file name of a recently deleted file to the result list.
  47.      *
  48.      * @param fileName the file which has been deleted
  49.      */
  50.     void deleted(final String fileName) {
  51.         deleted.add(fileName);
  52.     }

  53.     /**
  54.      * Gets a list of file names which has been added from the {@link ChangeSet}
  55.      *
  56.      * @return the list of file names
  57.      */
  58.     public List<String> getAddedFromChangeSet() {
  59.         return addedFromChangeSet;
  60.     }

  61.     /**
  62.      * Gets a list of file names which has been added from the original stream
  63.      *
  64.      * @return the list of file names
  65.      */
  66.     public List<String> getAddedFromStream() {
  67.         return addedFromStream;
  68.     }

  69.     /**
  70.      * Gets a list of file names which has been deleted
  71.      *
  72.      * @return the list of file names
  73.      */
  74.     public List<String> getDeleted() {
  75.         return deleted;
  76.     }

  77.     /**
  78.      * Tests if a file name already has been added to the result list
  79.      *
  80.      * @param fileName the file name to check
  81.      * @return true, if this file name already has been added
  82.      */
  83.     boolean hasBeenAdded(final String fileName) {
  84.         return addedFromChangeSet.contains(fileName) || addedFromStream.contains(fileName);
  85.     }
  86. }