View Javadoc
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   *   https://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  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * Stores the results of a performed {@link ChangeSet} operation.
26   */
27  public class ChangeSetResults {
28  
29      private final List<String> addedFromChangeSet = new ArrayList<>();
30      private final List<String> addedFromStream = new ArrayList<>();
31      private final List<String> deleted = new ArrayList<>();
32  
33      /**
34       * Constructs a new instance.
35       */
36      public ChangeSetResults() {
37          // empty
38      }
39  
40      /**
41       * Adds the name of a file to the result list which has been copied from the {@link ChangeSet} to the target stream
42       *
43       * @param fileName the name of the file
44       */
45      void addedFromChangeSet(final String fileName) {
46          addedFromChangeSet.add(fileName);
47      }
48  
49      /**
50       * Adds the name of a file to the result list which has been copied from the source stream to the target stream.
51       *
52       * @param fileName the file name which has been added from the original stream
53       */
54      void addedFromStream(final String fileName) {
55          addedFromStream.add(fileName);
56      }
57  
58      /**
59       * Adds the file name of a recently deleted file to the result list.
60       *
61       * @param fileName the file which has been deleted
62       */
63      void deleted(final String fileName) {
64          deleted.add(fileName);
65      }
66  
67      /**
68       * Gets a list of file names which has been added from the {@link ChangeSet}
69       *
70       * @return the list of file names
71       */
72      public List<String> getAddedFromChangeSet() {
73          return addedFromChangeSet;
74      }
75  
76      /**
77       * Gets a list of file names which has been added from the original stream
78       *
79       * @return the list of file names
80       */
81      public List<String> getAddedFromStream() {
82          return addedFromStream;
83      }
84  
85      /**
86       * Gets a list of file names which has been deleted
87       *
88       * @return the list of file names
89       */
90      public List<String> getDeleted() {
91          return deleted;
92      }
93  
94      /**
95       * Tests if a file name already has been added to the result list
96       *
97       * @param fileName the file name to check
98       * @return true, if this file name already has been added
99       */
100     boolean hasBeenAdded(final String fileName) {
101         return addedFromChangeSet.contains(fileName) || addedFromStream.contains(fileName);
102     }
103 }