public int hash(JimfsPath path) {
    // Note: JimfsPath.equals() is implemented using the compare() method below;
    // equalityUsesCanonicalForm is taken into account there via the namesOrdering, which is set
    // at construction time.
    int hash = 31;
    hash = 31 * hash + getFileSystem().hashCode();

    final Name root = path.root();
    final ImmutableList<Name> names = path.names();

    if (equalityUsesCanonicalForm) {
      // use hash codes of names themselves, which are based on the canonical form
      hash = 31 * hash + (root == null ? 0 : root.hashCode());
      for (Name name : names) {
        hash = 31 * hash + name.hashCode();
      }
    } else {
      // use hash codes from toString() form of names
      hash = 31 * hash + (root == null ? 0 : root.toString().hashCode());
      for (Name name : names) {
        hash = 31 * hash + name.toString().hashCode();
      }
    }
    return hash;
  }
@Test
  public void testHash_usingDisplayForm() {
    PathService pathService = fakePathService(PathType.unix(), false);

    JimfsPath path1 = new JimfsPath(pathService, null, ImmutableList.of(Name.create("FOO", "foo")));
    JimfsPath path2 = new JimfsPath(pathService, null, ImmutableList.of(Name.create("FOO", "FOO")));
    JimfsPath path3 =
        new JimfsPath(
            pathService, null, ImmutableList.of(Name.create("FOO", "9874238974897189741")));

    assertThat(pathService.hash(path1)).isEqualTo(pathService.hash(path2));
    assertThat(pathService.hash(path2)).isEqualTo(pathService.hash(path3));
  }