Skip to content

Commit

Permalink
Review cleanup
Browse files Browse the repository at this point in the history
- Change field name 'entityIdIsSpecialTieBreaker' to 'compareId'
- Replace if-else with Integer.compare
  • Loading branch information
burqen committed Feb 15, 2018
1 parent 6bd0c15 commit 4880309
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 42 deletions.
Expand Up @@ -34,11 +34,11 @@ interface NativeSchemaKey
* of inclusive/exclusive bounds of range queries.
* This is because {@link GBPTree} only support from inclusive and to exclusive.
* <p>
* Note that {@code entityIdIsSpecialTieBreaker} is only an in memory state.
* Note that {@code compareId} is only an in memory state.
*/
void setEntityIdIsSpecialTieBreaker( boolean entityIdIsSpecialTieBreaker );
void setCompareId( boolean compareId );

boolean getEntityIdIsSpecialTieBreaker();
boolean getCompareId();

long getEntityId();

Expand Down
Expand Up @@ -39,7 +39,7 @@ public NumberSchemaKey copyKey( NumberSchemaKey key, NumberSchemaKey into )
into.type = key.type;
into.rawValueBits = key.rawValueBits;
into.setEntityId( key.getEntityId() );
into.setEntityIdIsSpecialTieBreaker( key.getEntityIdIsSpecialTieBreaker() );
into.setCompareId( key.getCompareId() );
return into;
}

Expand Down
Expand Up @@ -57,7 +57,7 @@ public int compare( NumberSchemaKey o1, NumberSchemaKey o2 )
if ( comparison == 0 )
{
// This is a special case where we need also compare entityId to support inclusive/exclusive
if ( o1.getEntityIdIsSpecialTieBreaker() || o2.getEntityIdIsSpecialTieBreaker() )
if ( o1.getCompareId() || o2.getCompareId() )
{
return Long.compare( o1.getEntityId(), o2.getEntityId() );
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ private void initToForRange( NumberRangePredicate rangePredicate, KEY treeKeyTo
else
{
treeKeyTo.from( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE, toValue );
treeKeyTo.setEntityIdIsSpecialTieBreaker( true );
treeKeyTo.setCompareId( true );
}
}

Expand All @@ -98,7 +98,7 @@ private void initFromForRange( NumberRangePredicate rangePredicate, KEY treeKeyF
else
{
treeKeyFrom.from( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE, fromValue );
treeKeyFrom.setEntityIdIsSpecialTieBreaker( true );
treeKeyFrom.setCompareId( true );
}
}

Expand Down
Expand Up @@ -44,21 +44,19 @@ class NumberSchemaKey extends ValueWriter.Adapter<RuntimeException> implements N
Long.BYTES; /* entityId */

private long entityId;
private boolean entityIdIsSpecialTieBreaker;
private boolean compareId;

byte type;
long rawValueBits;

@Override
public void setEntityIdIsSpecialTieBreaker( boolean entityIdIsSpecialTieBreaker )
public void setCompareId( boolean compareId )
{
this.entityIdIsSpecialTieBreaker = entityIdIsSpecialTieBreaker;
this.compareId = compareId;
}

@Override
public boolean getEntityIdIsSpecialTieBreaker()
public boolean getCompareId()
{
return entityIdIsSpecialTieBreaker;
return compareId;
}

@Override
Expand All @@ -78,7 +76,7 @@ public void from( long entityId, Value... values )
{
extractRawBitsAndType( assertValidValue( values ) );
this.entityId = entityId;
entityIdIsSpecialTieBreaker = false;
compareId = false;
}

private NumberValue assertValidValue( Value... values )
Expand Down Expand Up @@ -117,15 +115,15 @@ public void initAsLowest()
{
writeFloatingPoint( Double.NEGATIVE_INFINITY );
entityId = Long.MIN_VALUE;
entityIdIsSpecialTieBreaker = true;
compareId = true;
}

@Override
public void initAsHighest()
{
writeFloatingPoint( Double.POSITIVE_INFINITY );
entityId = Long.MAX_VALUE;
entityIdIsSpecialTieBreaker = true;
compareId = true;
}

/**
Expand Down
Expand Up @@ -42,7 +42,7 @@ public StringSchemaKey copyKey( StringSchemaKey key, StringSchemaKey into )
// TODO when we have reuse of byte[] take that into consideration here too
into.bytes = key.bytes.clone();
into.setEntityId( key.getEntityId() );
into.setEntityIdIsSpecialTieBreaker( key.getEntityIdIsSpecialTieBreaker() );
into.setCompareId( key.getCompareId() );
return into;
}

Expand Down
Expand Up @@ -56,7 +56,7 @@ public int compare( StringSchemaKey o1, StringSchemaKey o2 )
if ( comparison == 0 )
{
// This is a special case where we need also compare entityId to support inclusive/exclusive
if ( o1.getEntityIdIsSpecialTieBreaker() || o2.getEntityIdIsSpecialTieBreaker() )
if ( o1.getCompareId() || o2.getCompareId() )
{
return Long.compare( o1.getEntityId(), o2.getEntityId() );
}
Expand Down
Expand Up @@ -84,7 +84,7 @@ private void initFromForRange( StringRangePredicate rangePredicate, StringSchema
else
{
treeKeyFrom.from( rangePredicate.fromInclusive() ? Long.MIN_VALUE : Long.MAX_VALUE, fromValue );
treeKeyFrom.setEntityIdIsSpecialTieBreaker( true );
treeKeyFrom.setCompareId( true );
}
}

Expand All @@ -98,7 +98,7 @@ private void initToForRange( StringRangePredicate rangePredicate, StringSchemaKe
else
{
treeKeyTo.from( rangePredicate.toInclusive() ? Long.MAX_VALUE : Long.MIN_VALUE, toValue );
treeKeyTo.setEntityIdIsSpecialTieBreaker( true );
treeKeyTo.setCompareId( true );
}
}

Expand Down
Expand Up @@ -41,22 +41,20 @@ class StringSchemaKey extends ValueWriter.Adapter<RuntimeException> implements N
static final int ENTITY_ID_SIZE = Long.BYTES;

private long entityId;
private boolean entityIdIsSpecialTieBreaker;
private boolean compareId;

// TODO something better or?
// TODO this is UTF-8 bytes for now
byte[] bytes;

@Override
public void setEntityIdIsSpecialTieBreaker( boolean entityIdIsSpecialTieBreaker )
public void setCompareId( boolean compareId )
{
this.entityIdIsSpecialTieBreaker = entityIdIsSpecialTieBreaker;
this.compareId = compareId;
}

@Override
public boolean getEntityIdIsSpecialTieBreaker()
public boolean getCompareId()
{
return entityIdIsSpecialTieBreaker;
return compareId;
}

int size()
Expand All @@ -80,7 +78,7 @@ public void setEntityId( long entityId )
public void from( long entityId, Value... values )
{
this.entityId = entityId;
entityIdIsSpecialTieBreaker = false;
compareId = false;
assertValidValue( values ).writeTo( this );
}

Expand Down Expand Up @@ -120,20 +118,20 @@ public void initAsLowest()
{
bytes = null;
entityId = Long.MIN_VALUE;
entityIdIsSpecialTieBreaker = true;
compareId = true;
}

@Override
public void initAsHighest()
{
bytes = null;
entityId = Long.MAX_VALUE;
entityIdIsSpecialTieBreaker = true;
compareId = true;
}

private boolean isHighest()
{
return entityIdIsSpecialTieBreaker && entityId == Long.MAX_VALUE && bytes == null;
return compareId && entityId == Long.MAX_VALUE && bytes == null;
}

/**
Expand Down Expand Up @@ -194,16 +192,7 @@ private static int byteArrayCompare( byte[] a, byte[] b )
}
}

if ( Integer.compare( a.length, b.length ) < 0 )
{
return -1;
}

if ( Integer.compare( a.length, b.length ) > 0 )
{
return 1;
}
return 0;
return Integer.compare( a.length, b.length );
}

@Override
Expand Down

0 comments on commit 4880309

Please sign in to comment.