-
Notifications
You must be signed in to change notification settings - Fork 595
/
PathApi.scala
130 lines (105 loc) · 5.04 KB
/
PathApi.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package fs2
package io
package file
import cats.Show
import cats.kernel.Hash
import cats.kernel.Monoid
import cats.kernel.Order
private[file] trait PathApi {
/** Joins the given path segments together using the platform-specific separator as
* a delimiter, then normalizes the resulting path.
*/
def /(name: String): Path
/** Joins the given path segments together using the platform-specific separator as
* a delimiter, then normalizes the resulting path.
*/
def /(path: Path): Path
/** Resolve the given path against this path. */
def resolve(name: String): Path
/** Resolve the given path against this path. */
def resolve(path: Path): Path
/** Resolves the given path against this path's parent path. */
def resolveSibling(name: String): Path
/** Resolves the given path against this path's parent path. */
def resolveSibling(path: Path): Path
/** Constructs a relative path between this path and a given path. */
def relativize(path: Path): Path
/** Returns a path that is this path with redundant name elements eliminated. */
def normalize: Path
/** Tells whether or not this path is absolute. */
def isAbsolute: Boolean
/** Returns a Path object representing the absolute path of this path. */
def absolute: Path
/** Returns the name elements in the path. */
def names: Seq[Path]
/** Returns the name of the file or directory denoted by this path as a Path object.
* The file name is the farthest element from the root in the directory hierarchy.
*/
def fileName: Path
/** Returns the extension of the path, from the last occurrence of the . (period)
* character to end of string in the last portion of the path.
* If there is no . in the last portion of the path, or if there are no . characters
* other than the first character of the filename of path, an empty string is returned.
*/
def extName: String
/** Returns the parent path, or None if this path does not have a parent. */
def parent: Option[Path]
/** Tests if this path starts with the given path.
* This path starts with the given path if this path's root component
* starts with the root component of the given path,
* and this path starts with the same name elements as the given path.
* If the given path has more name elements than this path then false is returned.
*/
def startsWith(path: String): Boolean
/** Tests if this path starts with the given path.
* This path starts with the given path if this path's root component
* starts with the root component of the given path,
* and this path starts with the same name elements as the given path.
* If the given path has more name elements than this path then false is returned.
*/
def startsWith(path: Path): Boolean
/** Tests if this path ends with the given path.
* If the given path has N elements, and no root component, and this path has N or more elements,
* then this path ends with the given path if the last N elements of each path,
* starting at the element farthest from the root, are equal.
*/
def endsWith(path: String): Boolean
/** Tests if this path ends with the given path.
* If the given path has N elements, and no root component, and this path has N or more elements,
* then this path ends with the given path if the last N elements of each path,
* starting at the element farthest from the root, are equal.
*/
def endsWith(path: Path): Boolean
def toString: String
}
private[file] trait PathCompanionApi {
def apply(path: String): Path
implicit def instances: Monoid[Path] with Order[Path] with Hash[Path] with Show[Path] = algebra
private object algebra extends Monoid[Path] with Order[Path] with Hash[Path] with Show[Path] {
val empty: Path = Path("")
def combine(x: Path, y: Path): Path = x / y
def compare(x: Path, y: Path): Int = x.toString.compare(y.toString)
def hash(x: Path): Int = x.hashCode()
def show(t: Path): String = t.toString
}
}