GcsPath implements Path, Serializable { @Override public int compareTo(Path other) { if (!(other instanceof GcsPath)) { throw new ClassCastException(); } GcsPath path = (GcsPath) other; int b = bucket.compareTo(path.bucket); if (b != 0) { return b; } Iterator<Path> left = iterator(); Iterator<Path> right = path.iterator(); while (left.hasNext() && right.hasNext()) { String leftStr = left.next().toString(); String rightStr = right.next().toString(); int c = leftStr.compareTo(rightStr); if (c != 0) { return c; } } if (!left.hasNext() && !right.hasNext()) { return 0; } else { return left.hasNext() ? 1 : -1; } } GcsPath(@Nullable FileSystem fs, @Nullable String bucket, @Nullable String object); static GcsPath fromUri(URI uri); static GcsPath fromUri(String uri); static GcsPath fromResourceName(String name); static GcsPath fromObject(StorageObject object); static GcsPath fromComponents(@Nullable String bucket, @Nullable String object); String getBucket(); String getObject(); void setFileSystem(FileSystem fs); @Override FileSystem getFileSystem(); @Override boolean isAbsolute(); @Override GcsPath getRoot(); @Override GcsPath getFileName(); @Override GcsPath getParent(); @Override int getNameCount(); @Override GcsPath getName(int count); @Override GcsPath subpath(int beginIndex, int endIndex); @Override boolean startsWith(Path other); @Override boolean startsWith(String prefix); @Override boolean endsWith(Path other); @Override boolean endsWith(String suffix); @Override GcsPath normalize(); @Override GcsPath resolve(Path other); @Override GcsPath resolve(String other); @Override Path resolveSibling(Path other); @Override Path resolveSibling(String other); @Override Path relativize(Path other); @Override GcsPath toAbsolutePath(); @Override GcsPath toRealPath(LinkOption... options); @Override File toFile(); @Override WatchKey register(
      WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers); @Override WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events); @Override Iterator<Path> iterator(); @Override int compareTo(Path other); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); String toResourceName(); @Override URI toUri(); static final String SCHEME; static final Pattern GCS_URI; }
@Test public void testCompareTo() { GcsPath a = GcsPath.fromComponents("bucket", "a"); GcsPath b = GcsPath.fromComponents("bucket", "b"); GcsPath b2 = GcsPath.fromComponents("bucket2", "b"); GcsPath brel = GcsPath.fromComponents(null, "b"); GcsPath a2 = GcsPath.fromComponents("bucket", "a"); GcsPath arel = GcsPath.fromComponents(null, "a"); assertThat(a.compareTo(b), Matchers.lessThan(0)); assertThat(b.compareTo(a), Matchers.greaterThan(0)); assertThat(a.compareTo(a2), Matchers.equalTo(0)); assertThat(a.hashCode(), Matchers.equalTo(a2.hashCode())); assertThat(a.hashCode(), Matchers.not(Matchers.equalTo(b.hashCode()))); assertThat(b.hashCode(), Matchers.not(Matchers.equalTo(brel.hashCode()))); assertThat(brel.compareTo(b), Matchers.lessThan(0)); assertThat(b.compareTo(brel), Matchers.greaterThan(0)); assertThat(arel.compareTo(brel), Matchers.lessThan(0)); assertThat(brel.compareTo(arel), Matchers.greaterThan(0)); assertThat(b.compareTo(b2), Matchers.lessThan(0)); assertThat(b2.compareTo(b), Matchers.greaterThan(0)); }