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.maven.plugin.compiler;
20  
21  import java.util.Collection;
22  import java.util.Collections;
23  import java.util.Set;
24  import java.util.TreeSet;
25  
26  /**
27   * Show the modifications between two lists.
28   */
29  final class DeltaList<E extends Comparable<E>> {
30  
31      private final Set<E> added = new TreeSet<>();
32      private final Set<E> removed = new TreeSet<>();
33      private final boolean hasChanged;
34  
35      DeltaList(Collection<E> oldList, Collection<E> newList) {
36          for (E newListItem : newList) {
37              if (!oldList.contains(newListItem)) {
38                  added.add(newListItem);
39              }
40          }
41          for (E oldListItem : oldList) {
42              if (!newList.contains(oldListItem)) {
43                  removed.add(oldListItem);
44              }
45          }
46          this.hasChanged = !added.isEmpty() || !removed.isEmpty();
47      }
48  
49      Collection<E> getAdded() {
50          return Collections.unmodifiableCollection(added);
51      }
52  
53      Collection<E> getRemoved() {
54          return Collections.unmodifiableCollection(removed);
55      }
56  
57      boolean hasChanged() {
58          return hasChanged;
59      }
60  }