|
| 1 | +package io.github.clidey.connparse; |
| 2 | + |
| 3 | +import java.util.LinkedHashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +public final class Address { |
| 7 | + public final String scheme; |
| 8 | + public final String type; |
| 9 | + public final Map<String, Object> authority; |
| 10 | + public final Resource resource; |
| 11 | + public final String path; |
| 12 | + public final Map<String, Object> query; |
| 13 | + public final String fragment; |
| 14 | + public final Map<String, String> credentials; |
| 15 | + public final Map<String, Object> options; |
| 16 | + public final String raw; |
| 17 | + public final String safe; |
| 18 | + |
| 19 | + public Address( |
| 20 | + String scheme, |
| 21 | + String type, |
| 22 | + Map<String, Object> authority, |
| 23 | + Resource resource, |
| 24 | + String path, |
| 25 | + Map<String, Object> query, |
| 26 | + String fragment, |
| 27 | + Map<String, String> credentials, |
| 28 | + Map<String, Object> options, |
| 29 | + String raw, |
| 30 | + String safe) { |
| 31 | + this.scheme = scheme == null ? "" : scheme; |
| 32 | + this.type = type == null ? "unknown" : type; |
| 33 | + this.authority = new LinkedHashMap<>(authority == null ? Map.of() : authority); |
| 34 | + this.resource = resource == null ? new Resource("none", null) : resource; |
| 35 | + this.path = path == null ? "" : path; |
| 36 | + this.query = new LinkedHashMap<>(query == null ? Map.of() : query); |
| 37 | + this.fragment = fragment; |
| 38 | + this.credentials = new LinkedHashMap<>(credentials == null ? Map.of() : credentials); |
| 39 | + this.options = new LinkedHashMap<>(options == null ? Map.of() : options); |
| 40 | + this.raw = raw == null ? "" : raw; |
| 41 | + this.safe = safe == null ? "" : safe; |
| 42 | + } |
| 43 | + |
| 44 | + public Map<String, Object> toMap() { |
| 45 | + Map<String, Object> output = new LinkedHashMap<>(); |
| 46 | + output.put("scheme", scheme); |
| 47 | + output.put("type", type); |
| 48 | + output.put("authority", authority); |
| 49 | + output.put("resource", resource.toMap()); |
| 50 | + output.put("path", path); |
| 51 | + output.put("query", query); |
| 52 | + output.put("fragment", fragment); |
| 53 | + output.put("credentials", credentials); |
| 54 | + output.put("options", options); |
| 55 | + output.put("raw", raw); |
| 56 | + output.put("safe", safe); |
| 57 | + return output; |
| 58 | + } |
| 59 | + |
| 60 | + public static final class Resource { |
| 61 | + public final String type; |
| 62 | + public final String name; |
| 63 | + |
| 64 | + public Resource(String type, String name) { |
| 65 | + this.type = type == null ? "none" : type; |
| 66 | + this.name = name; |
| 67 | + } |
| 68 | + |
| 69 | + public Map<String, Object> toMap() { |
| 70 | + Map<String, Object> output = new LinkedHashMap<>(); |
| 71 | + output.put("type", type); |
| 72 | + output.put("name", name); |
| 73 | + return output; |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments