public class Paths extends Object
Modifier and Type | Method and Description |
---|---|
static int |
compare(byte[] aPath,
int aPos,
int aEnd,
int aMode,
byte[] bPath,
int bPos,
int bEnd,
int bMode)
Compare two paths according to Git path sort ordering rules.
|
static int |
compareSameName(byte[] aPath,
int aPos,
int aEnd,
byte[] bPath,
int bPos,
int bEnd,
int bMode)
Compare two paths, checking for identical name.
|
static String |
stripTrailingSeparator(String path)
Remove trailing
'/' if present. |
public static String stripTrailingSeparator(String path)
'/'
if present.path
- input path to potentially remove trailing '/'
from.path == null
; path
after removing a
trailing '/'
.public static int compare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode)
aPath
- first path buffer. The range [aPos, aEnd)
is used.aPos
- index into aPath
where the first path starts.aEnd
- 1 past last index of aPath
.aMode
- mode of the first file. Trees are sorted as though
aPath[aEnd] == '/'
, even if aEnd does not exist.bPath
- second path buffer. The range [bPos, bEnd)
is used.bPos
- index into bPath
where the second path starts.bEnd
- 1 past last index of bPath
.bMode
- mode of the second file. Trees are sorted as though
bPath[bEnd] == '/'
, even if bEnd does not exist.aPath
sorts before bPath
;
0 if the paths are the same;
>0 if aPath
sorts after bPath
.public static int compareSameName(byte[] aPath, int aPos, int aEnd, byte[] bPath, int bPos, int bEnd, int bMode)
Unlike compare
this method returns 0
when the paths have
the same characters in their names, even if the mode differs. It is
intended for use in validation routines detecting duplicate entries.
Returns 0
if the names are identical and a conflict exists
between aPath
and bPath
, as they share the same name.
Returns <0
if all possibles occurrences of aPath
sort
before bPath
and no conflict can happen. In a properly sorted
tree there are no other occurrences of aPath
and therefore there
are no duplicate names.
Returns >0
when it is possible for a duplicate occurrence of
aPath
to appear later, after bPath
. Callers should
continue to examine candidates for bPath
until the method returns
one of the other return values.
aPath
- first path buffer. The range [aPos, aEnd)
is used.aPos
- index into aPath
where the first path starts.aEnd
- 1 past last index of aPath
.bPath
- second path buffer. The range [bPos, bEnd)
is used.bPos
- index into bPath
where the second path starts.bEnd
- 1 past last index of bPath
.bMode
- mode of the second file. Trees are sorted as though
bPath[bEnd] == '/'
, even if bEnd does not exist.bPath
should still be checked by caller.Copyright © 2017 Eclipse JGit Project. All rights reserved.