1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model;
17
18 import java.net.InetAddress;
19 import java.net.URI;
20 import java.net.URL;
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public class Location {
35
36 protected final NetworkAddress networkAddress;
37 protected final String path;
38 protected final URL url;
39
40 public Location(NetworkAddress networkAddress, String path) {
41 this.networkAddress = networkAddress;
42 this.path = path;
43 this.url = createAbsoluteURL(networkAddress.getAddress(), networkAddress.getPort(), path);
44 }
45
46 public NetworkAddress getNetworkAddress() {
47 return networkAddress;
48 }
49
50 public String getPath() {
51 return path;
52 }
53
54 @Override
55 public boolean equals(Object o) {
56 if (this == o) return true;
57 if (o == null || getClass() != o.getClass()) return false;
58
59 Location location = (Location) o;
60
61 if (!networkAddress.equals(location.networkAddress)) return false;
62 if (!path.equals(location.path)) return false;
63
64 return true;
65 }
66
67 @Override
68 public int hashCode() {
69 int result = networkAddress.hashCode();
70 result = 31 * result + path.hashCode();
71 return result;
72 }
73
74
75
76
77 public URL getURL() {
78 return url;
79 }
80
81
82 private static URL createAbsoluteURL(InetAddress address, int localStreamPort, String path) {
83 try {
84 return new URL("http", address.getHostAddress(), localStreamPort, path);
85 } catch (Exception ex) {
86 throw new IllegalArgumentException("Address, port, and URI can not be converted to URL", ex);
87 }
88 }
89 }