in commands/src/main/java/org/jclouds/karaf/commands/table/internal/AlphanumericComparator.java [64:108]
public int compare(String left, String right)
{
int leftMarker = 0;
int rightMarker = 0;
int leftLength = left.length();
int rightLength = right.length();
while (leftMarker < leftLength && rightMarker < rightLength)
{
String leftChunk = getChunk(left, leftLength, leftMarker);
leftMarker += leftChunk.length();
String rightChunk = getChunk(right, rightLength, rightMarker);
rightMarker += rightChunk.length();
// If both chunks contain numeric characters, sort them numerically
int result = 0;
if (isDigit(leftChunk.charAt(0)) && isDigit(rightChunk.charAt(0)))
{
// Simple chunk comparison by length.
int leftChunkLength = leftChunk.length();
result = leftChunkLength - rightChunk.length();
// If equal, the first different number counts
if (result == 0)
{
for (int i = 0; i < leftChunkLength; i++)
{
result = leftChunk.charAt(i) - rightChunk.charAt(i);
if (result != 0)
{
return result;
}
}
}
} else
{
result = leftChunk.compareTo(rightChunk);
}
if (result != 0)
return result;
}
return leftLength - rightLength;
}