1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.minio;
20
21 import java.util.Objects;
22
23 import static java.util.Objects.requireNonNull;
24
25
26
27
28
29
30 public final class ObjectName {
31 private final String bucket;
32 private final String name;
33 private final int hashCode;
34
35 public ObjectName(String bucket, String name) {
36 this.bucket = requireNonNull(bucket);
37 this.name = requireNonNull(name);
38
39 if (bucket.contains("/")) {
40 throw new IllegalArgumentException("invalid bucket name: " + bucket);
41 }
42 if (name.contains("\\")) {
43 throw new IllegalArgumentException("invalid object name: " + name);
44 }
45
46 this.hashCode = Objects.hash(bucket, name);
47 }
48
49 public String getBucket() {
50 return bucket;
51 }
52
53 public String getName() {
54 return name;
55 }
56
57 @Override
58 public boolean equals(Object o) {
59 if (this == o) {
60 return true;
61 }
62 if (o == null || getClass() != o.getClass()) {
63 return false;
64 }
65 ObjectName that = (ObjectName) o;
66 return Objects.equals(bucket, that.bucket) && Objects.equals(name, that.name);
67 }
68
69 @Override
70 public int hashCode() {
71 return hashCode;
72 }
73
74 @Override
75 public String toString() {
76 return bucket + "/" + name;
77 }
78
79 public static String normalize(String name) {
80 return name.replace('\\', '/');
81 }
82 }