2 * ============LICENSE_START=======================================================
3 * DCAEGEN2-SERVICES-SDK
4 * ================================================================================
5 * Copyright (C) 2019-2022 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 package org.onap.dcaegen2.services.sdk.rest.services.adapters.http;
24 public final class URI {
25 private String scheme;
29 private String fragment;
30 private String authority;
31 private String userInfo;
33 private String schemeSpecificPart;
34 private String string;
39 public static final class URIBuilder {
40 private String scheme;
44 private String fragment;
45 private String authority;
46 private String userInfo;
48 private String schemeSpecificPart;
50 public URIBuilder scheme(String scheme) {
55 public URIBuilder host(String host) {
60 public URIBuilder port(int port) {
65 public URIBuilder path(String path) {
70 public URIBuilder fragment(String fragment) {
71 this.fragment = fragment;
75 public URIBuilder authority(String authority) {
76 this.authority = authority;
80 public URIBuilder userInfo(String userInfo) {
81 this.userInfo = userInfo;
85 public URIBuilder query(String query) {
90 public URIBuilder schemeSpecificPart(String schemeSpecificPart) {
91 this.schemeSpecificPart = schemeSpecificPart;
97 uri.scheme = this.scheme;
100 uri.path = this.path;
101 uri.fragment = this.fragment;
102 uri.authority = this.authority;
103 uri.userInfo = this.userInfo;
104 uri.query = this.query;
105 uri.schemeSpecificPart = this.schemeSpecificPart;
111 public String toString() {
116 private void defineString() {
117 if (string != null) return;
119 StringBuilder sb = new StringBuilder();
120 if (scheme != null) {
125 sb.append(schemeSpecificPart);
129 if (userInfo != null) {
133 boolean needBrackets = ((host.indexOf(':') >= 0)
134 && !host.startsWith("[")
135 && !host.endsWith("]"));
136 if (needBrackets) sb.append('[');
138 if (needBrackets) sb.append(']');
143 } else if (authority != null) {
145 sb.append(authority);
154 if (fragment != null) {
158 string = sb.toString();
161 private boolean isOpaque() {