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   * 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  
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       * Adds the name of a file to the result list which has been copied from the {@link ChangeSet} to the target stream
35       *
36       * @param fileName the name of the file
37       */
38      void addedFromChangeSet(final String fileName) {
39          addedFromChangeSet.add(fileName);
40      }
41  
42      /**
43       * Adds the name of a file to the result list which has been copied from the source stream to the target stream.
44       *
45       * @param fileName the file name which has been added from the original stream
46       */
47      void addedFromStream(final String fileName) {
48          addedFromStream.add(fileName);
49      }
50  
51      /**
52       * Adds the file name of a recently deleted file to the result list.
53       *
54       * @param fileName the file which has been deleted
55       */
56      void deleted(final String fileName) {
57          deleted.add(fileName);
58      }
59  
60      /**
61       * Gets a list of file names which has been added from the {@link ChangeSet}
62       *
63       * @return the list of file names
64       */
65      public List<String> getAddedFromChangeSet() {
66          return addedFromChangeSet;
67      }
68  
69      /**
70       * Gets a list of file names which has been added from the original stream
71       *
72       * @return the list of file names
73       */
74      public List<String> getAddedFromStream() {
75          return addedFromStream;
76      }
77  
78      /**
79       * Gets a list of file names which has been deleted
80       *
81       * @return the list of file names
82       */
83      public List<String> getDeleted() {
84          return deleted;
85      }
86  
87      /**
88       * Tests if a file name already has been added to the result list
89       *
90       * @param fileName the file name to check
91       * @return true, if this file name already has been added
92       */
93      boolean hasBeenAdded(final String fileName) {
94          return addedFromChangeSet.contains(fileName) || addedFromStream.contains(fileName);
95      }
96  }