swim.uri.UriPath 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 java.lang.reflect.Array;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import swim.codec.Debug;
import swim.codec.Display;
import swim.codec.Output;
import swim.util.HashGenCacheSet;
public abstract class UriPath implements Collection, Comparable, Debug, Display {
protected UriPath() {
// stub
}
public abstract boolean isDefined();
public abstract boolean isAbsolute();
public abstract boolean isRelative();
@Override
public abstract boolean isEmpty();
@Override
public int size() {
return UriPath.size(this);
}
private static int size(UriPath path) {
int n = 0;
while (!path.isEmpty()) {
n += 1;
path = path.tail();
}
return n;
}
public abstract String head();
public abstract UriPath tail();
protected abstract void setTail(UriPath tail);
protected abstract UriPath dealias();
public String name() {
return UriPath.name(this);
}
private static String name(UriPath path) {
if (path.isEmpty()) {
return "";
}
do {
final UriPath tail = path.tail();
if (tail.isEmpty()) {
return path.isRelative() ? path.head() : "";
} else {
path = tail;
}
} while (true);
}
public UriPath foot() {
return UriPath.foot(this);
}
private static UriPath foot(UriPath path) {
if (path.isEmpty()) {
return path;
}
do {
final UriPath tail = path.tail();
if (tail.isEmpty()) {
return path;
} else {
path = tail;
}
} while (true);
}
public boolean isSubpathOf(UriPath b) {
return UriPath.isSubpathOf(this, b);
}
private static boolean isSubpathOf(UriPath a, UriPath b) {
while (!a.isEmpty() && !b.isEmpty()) {
if (!a.head().equals(b.head())) {
return false;
}
a = a.tail();
b = b.tail();
}
return b.isEmpty();
}
@Override
public boolean contains(Object component) {
if (component instanceof String) {
return UriPath.contains(this, (String) component);
}
return false;
}
private static boolean contains(UriPath path, String component) {
while (!path.isEmpty()) {
if (component.equals(path.head())) {
return true;
}
path = path.tail();
}
return false;
}
@Override
public boolean containsAll(Collection> components) {
if (components == null) {
throw new NullPointerException();
}
return UriPath.containsAll(this, new HashSet
© 2015 - 2025 Weber Informatics LLC | Privacy Policy