swim.uri.UriPathMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swim-uri Show documentation
Show all versions of swim-uri Show documentation
Uploads all artifacts belonging to configuration ':swim-uri:archives'
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.uri;
import swim.collections.HashTrieMap;
abstract class UriPathMapper extends UriAuthorityMapper {
abstract T get(UriPath path, UriQuery query, UriFragment fragment);
@Override
T get(UriAuthority authority, UriPath path, UriQuery query, UriFragment fragment) {
return get(path, query, fragment);
}
abstract UriPathMapper merged(UriPathMapper that);
@Override
UriAuthorityMapper merged(UriAuthorityMapper that) {
if (that instanceof UriPathMapper>) {
return merged((UriPathMapper) that);
} else {
return that;
}
}
abstract UriPathMapper removed(UriPath path, UriQuery query, UriFragment fragment);
@Override
UriAuthorityMapper removed(UriAuthority authority, UriPath path, UriQuery query, UriFragment fragment) {
return removed(path, query, fragment);
}
abstract UriPathMapper unmerged(UriPathMapper that);
@Override
UriAuthorityMapper unmerged(UriAuthorityMapper that) {
if (that instanceof UriPathMapper>) {
return unmerged((UriPathMapper) that);
} else {
return this;
}
}
@SuppressWarnings("unchecked")
static UriPathMapper compile(Uri pattern, UriPath path, UriQuery query, UriFragment fragment, T value) {
if (!path.isEmpty()) {
final String segment = path.head();
if (!segment.isEmpty() && segment.charAt(0) == ':') {
return new UriPathMapping(HashTrieMap.>empty(), compile(pattern, path.tail(), query, fragment, value), (UriQueryMapper) empty());
} else {
return new UriPathMapping(HashTrieMap.>empty().updated(segment, compile(pattern, path.tail(), query, fragment, value)), (UriPathMapper) empty(), (UriQueryMapper) empty());
}
} else {
return new UriPathMapping(HashTrieMap.>empty(), (UriPathMapper) empty(), UriQueryMapper.compile(pattern, query, fragment, value));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy