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.cli.transfer;
20  
21  import java.io.File;
22  import java.util.Objects;
23  
24  import org.eclipse.aether.transfer.TransferResource;
25  import org.eclipse.sisu.Nullable;
26  
27  /**
28   * Immutable identifier of a {@link TransferResource}.
29   * The {@link TransferResource} is not immutable and does not implement {@code Objects#equals} and {@code Objects#hashCode} methods,
30   * making it not very suitable for usage in collections.
31   */
32  final class TransferResourceIdentifier {
33  
34      private final String repositoryId;
35      private final String repositoryUrl;
36      private final String resourceName;
37  
38      @Nullable
39      private final File file;
40  
41      private TransferResourceIdentifier(
42              String repositoryId, String repositoryUrl, String resourceName, @Nullable File file) {
43          this.repositoryId = repositoryId;
44          this.repositoryUrl = repositoryUrl;
45          this.resourceName = resourceName;
46          this.file = file;
47      }
48  
49      TransferResourceIdentifier(TransferResource resource) {
50          this(resource.getRepositoryId(), resource.getRepositoryUrl(), resource.getResourceName(), resource.getFile());
51      }
52  
53      @Override
54      public boolean equals(Object obj) {
55          if (obj == this) {
56              return true;
57          }
58  
59          if (obj == null || obj.getClass() != this.getClass()) {
60              return false;
61          }
62  
63          TransferResourceIdentifier that = (TransferResourceIdentifier) obj;
64          return Objects.equals(this.repositoryId, that.repositoryId)
65                  && Objects.equals(this.repositoryUrl, that.repositoryUrl)
66                  && Objects.equals(this.resourceName, that.resourceName)
67                  && Objects.equals(this.file, that.file);
68      }
69  
70      @Override
71      public int hashCode() {
72          return Objects.hash(repositoryId, repositoryUrl, resourceName, file);
73      }
74  }