Skip to content

Commit

Permalink
Add IComparable<T> to Path (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyk4j authored Feb 27, 2024
1 parent 25cbd3d commit 99207c9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
6 changes: 3 additions & 3 deletions JShim/Java/NIO/File/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Java.NIO.File
/// <summary>
/// Description of Path.
/// </summary>
public interface Path
public interface Path : IComparable<Path>
{
int CompareTo(Path other);
//int CompareTo(Path other);
bool EndsWith(Path other);
bool EndsWith(string other);
bool Equals(object other);
Expand All @@ -20,7 +20,7 @@ public interface Path
int GetNameCount();
Path GetParent();
Path GetRoot();
int HashCode();
//int GetHashCode();
bool IsAbsolute();
IEnumerable<Path> Iterator();
Path Normalize();
Expand Down
65 changes: 61 additions & 4 deletions JShim/Sun/NIO/FS/WindowsPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,60 @@ public WindowsPath(WindowsFileSystem fs,
this.path = path;
}

/// <summary>
/// Compares two abstract paths lexicographically.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public int CompareTo(Path other)
{
throw new NotImplementedException();
return 0;
}

/// <summary>
/// Tests if this path ends with the given path.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool EndsWith(Path other)
{
throw new NotImplementedException();
}

/// <summary>
/// Tests if this path ends with a Path, constructed by converting the
/// given path string, in exactly the manner specified by the
/// <c>endsWith(Path)</c> method.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool EndsWith(string other)
{
throw new NotImplementedException();
}

/// <summary>
/// Tests this path for equality with the given object.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public override bool Equals(object other)
{
return Equals(other as WindowsPath);
}

/// <summary>
/// Tests this path for equality with the given object.
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(WindowsPath other)
{
return other != null &&
root.Equals(other.root) &&
path.Equals(other.path);
}

public Path GetFileName()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -103,9 +142,15 @@ public Path GetRoot()
throw new NotImplementedException();
}

public int HashCode()
public override int GetHashCode()
{
throw new NotImplementedException();
unchecked // Allow arithmetic overflow, numbers will just "wrap around"
{
int hashcode = 1430287;
hashcode = hashcode * 7302013 ^ root.GetHashCode();
hashcode = hashcode * 7302013 ^ path.GetHashCode();
return hashcode;
}
}

public bool IsAbsolute()
Expand Down Expand Up @@ -165,14 +210,26 @@ public Path SubPath(int beginIndex, int endIndex)

public Path ToAbsolutePath()
{
throw new NotImplementedException();
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
System.IO.DirectoryInfo rootDefault = drives[0].RootDirectory;

string root = !string.IsNullOrEmpty(this.root)?
this.root :
rootDefault.FullName;

return new WindowsPath(fs, WindowsPathType.Absolute, root, path);
}

public System.IO.FileSystemInfo ToFile()
{
throw new NotImplementedException();
}

/// <summary>
/// Returns the real path of an existing file.
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
public Path ToRealPath(params LinkOption[] options)
{
throw new NotImplementedException();
Expand Down

0 comments on commit 99207c9

Please sign in to comment.