@Override public CompareResult compare(Key otherKey, CompareMethod method) { return new CompareResult(ALWAYS_EQUALS); } }
@Override public CompareResult compare(Key o, CompareMethod method) { if(o != null) { if(o instanceof UUIDKey) { UUIDKey otherKey = (UUIDKey) o; return new CompareResult(compare(otherKey)); } else { return new CompareResult(-1); } } else { throw new NullPointerException("Cannot compare null Key"); } }
private CompareResult compare(Key[] otherKeys, CompareMethod compareMethod) { Key[] keys = getKeys(); //we assume keys are ordered in same order int keyLength = keys.length; int lastCompare = -1; for(int i=0; i<keyLength; i++) { Key key = keys[i]; Key otherKey = otherKeys.length > i ? otherKeys[i] : null; if(key != null && otherKey != null && i<valueMarker) { lastCompare = key.compareTo(otherKey); if(lastCompare != 0) { return new CompareResult(lastCompare); } } else { break; } } if(compareMethod == CompareMethod.BEFORE) { return new CompareResult(-1); } else { return new CompareResult(lastCompare); } }
private CompareResult evaluateKey(Key o) { int result; if(o instanceof LongKey) { LongKey longIndexPointer = (LongKey) o; if(key.length == 0) { result = 0; } else { result = (getKey() < longIndexPointer.getKey()) ? -1 : ((getKey() == longIndexPointer.getKey()) ? 0 : 1); } } else if(o instanceof StringKey) { StringKey stringKey = (StringKey) o; try { result = Long.valueOf(getKey()).compareTo(Long.parseLong(stringKey.getKey())); } catch(NumberFormatException ignored) { result = -1; } } else { result = -1; } return new CompareResult(result); }
@Override public CompareResult compare(Key o, CompareMethod method) { if(o != null) { int result = -1; if(o instanceof StringKey) { result = compare(unicodeBytes, ((StringKey) o).getUnicodeBytes()); } else if(o instanceof LongKey) { LongKey longKey = (LongKey) o; try { LongKey localKey = new LongKey(Long.parseLong(getKey())); result = localKey.compareTo(longKey); } catch(NumberFormatException e) { result = -1; } } else if(o instanceof UUIDKey) { UUIDKey uuidKey = (UUIDKey) o; byte[] uuidBytes = KeyUtil.getUnicodeBytes(new UUID(uuidKey.getMostSignificant(), uuidKey.getLeastSignificant()).toString()); result = compare(unicodeBytes, uuidBytes); } return new CompareResult(result); } else { throw new RuntimeJasDBException("Cannot compare null Key"); } }