Skip to content

Commit

Permalink
Rename temporal index fields and methods according to value groups
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Mar 9, 2018
1 parent bb4f3e9 commit c6023ce
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 107 deletions.
Expand Up @@ -234,26 +234,25 @@ public PartAccessor<?> newDate() throws IOException
}

@Override
public PartAccessor<?> newDateTime() throws IOException
public PartAccessor<?> newLocalDateTime() throws IOException
{
return createPartAccessor( temporalIndexFiles.dateTime() );
return createPartAccessor( temporalIndexFiles.localDateTime() );
}

@Override
public PartAccessor<?> newDateTimeZoned()
public PartAccessor<?> newZonedDateTime() throws IOException
{
throw new UnsupportedOperationException( "no comprende" );
}

@Override
public PartAccessor<?> newTime() throws IOException
public PartAccessor<?> newLocalTime() throws IOException
{
return createPartAccessor( temporalIndexFiles.time() );

return createPartAccessor( temporalIndexFiles.localTime() );
}

@Override
public PartAccessor<?> newTimeZoned()
public PartAccessor<?> newZonedTime() throws IOException
{
throw new UnsupportedOperationException( "no comprende" );
}
Expand Down
Expand Up @@ -22,10 +22,8 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

import org.neo4j.helpers.collection.Iterators;
import org.neo4j.values.storable.ValueGroup;

/**
Expand All @@ -43,10 +41,10 @@ class TemporalIndexCache<T, E extends Exception> implements Iterable<T>
private final Factory<T, E> factory;

private volatile T date;
private volatile T dateTime;
private volatile T dateTimeZoned;
private volatile T time;
private volatile T timeZoned;
private volatile T localDateTime;
private volatile T zonedDateTime;
private volatile T localTime;
private volatile T zonedTime;
private volatile T duration;

private List<T> parts;
Expand Down Expand Up @@ -92,16 +90,16 @@ T select( ValueGroup valueGroup ) throws E
return date();

case LOCAL_DATE_TIME:
return dateTime();
return localDateTime();

case ZONED_DATE_TIME:
return dateTimeZoned();
return zonedDateTime();

case LOCAL_TIME:
return time();
return localTime();

case ZONED_TIME:
return timeZoned();
return zonedTime();

case DURATION:
return duration();
Expand Down Expand Up @@ -129,16 +127,16 @@ <RESULT> RESULT selectOrElse( ValueGroup valueGroup, Function<T, RESULT> functio
return date != null ? function.apply( date ) : orElse;

case LOCAL_DATE_TIME:
return dateTime != null ? function.apply( dateTime ) : orElse;
return localDateTime != null ? function.apply( localDateTime ) : orElse;

case ZONED_DATE_TIME:
return dateTimeZoned != null ? function.apply( dateTimeZoned ) : orElse;
return zonedDateTime != null ? function.apply( zonedDateTime ) : orElse;

case LOCAL_TIME:
return time != null ? function.apply( time ) : orElse;
return localTime != null ? function.apply( localTime ) : orElse;

case ZONED_TIME:
return timeZoned != null ? function.apply( timeZoned ) : orElse;
return zonedTime != null ? function.apply( zonedTime ) : orElse;

case DURATION:
return duration != null ? function.apply( duration ) : orElse;
Expand All @@ -158,44 +156,44 @@ T date() throws E
return date;
}

T dateTime() throws E
T localDateTime() throws E
{
if ( dateTime == null )
if ( localDateTime == null )
{
dateTime = factory.newDateTime();
parts.add( dateTime );
localDateTime = factory.newLocalDateTime();
parts.add( localDateTime );
}
return dateTime;
return localDateTime;
}

T dateTimeZoned() throws E
T zonedDateTime() throws E
{
if ( dateTimeZoned == null )
if ( zonedDateTime == null )
{
dateTimeZoned = factory.newDateTimeZoned();
parts.add( dateTimeZoned );
zonedDateTime = factory.newZonedDateTime();
parts.add( zonedDateTime );
}
return dateTimeZoned;
return zonedDateTime;
}

T time() throws E
T localTime() throws E
{
if ( time == null )
if ( localTime == null )
{
time = factory.newTime();
parts.add( time );
localTime = factory.newLocalTime();
parts.add( localTime );
}
return time;
return localTime;
}

T timeZoned() throws E
T zonedTime() throws E
{
if ( timeZoned == null )
if ( zonedTime == null )
{
timeZoned = factory.newTimeZoned();
parts.add( timeZoned );
zonedTime = factory.newZonedTime();
parts.add( zonedTime );
}
return timeZoned;
return zonedTime;
}

T duration() throws E
Expand Down Expand Up @@ -223,10 +221,10 @@ public Iterator<T> iterator()
interface Factory<T, E extends Exception>
{
T newDate() throws E;
T newDateTime() throws E;
T newDateTimeZoned() throws E;
T newTime() throws E;
T newTimeZoned() throws E;
T newLocalDateTime() throws E;
T newZonedDateTime() throws E;
T newLocalTime() throws E;
T newZonedTime() throws E;
T newDuration() throws E;
}
}
Expand Up @@ -32,31 +32,31 @@
class TemporalIndexFiles
{
private final FileSystemAbstraction fs;
private FileLayout<DateSchemaKey> dateFileLayout;
private FileLayout<LocalDateTimeSchemaKey> dateTimeFileLayout;
private FileLayout dateTimeZonedFileLayout;
private FileLayout<LocalTimeSchemaKey> timeFileLayout;
private FileLayout timeZonedFileLayout;
private FileLayout durationFileLayout;
private FileLayout<DateSchemaKey> date;
private FileLayout<LocalDateTimeSchemaKey> localDateTime;
private FileLayout zonedDateTime;
private FileLayout<LocalTimeSchemaKey> localTime;
private FileLayout zonedTime;
private FileLayout duration;

TemporalIndexFiles( IndexDirectoryStructure directoryStructure, long indexId, IndexDescriptor descriptor, FileSystemAbstraction fs )
{
this.fs = fs;
File indexDirectory = directoryStructure.directoryForIndex( indexId );
dateFileLayout = new FileLayout<>( new File( indexDirectory, "date" ), DateLayout.of( descriptor ), ValueGroup.DATE );
timeFileLayout = new FileLayout<>( new File( indexDirectory, "time" ), LocalTimeLayout.of( descriptor ), ValueGroup.LOCAL_TIME );
dateTimeFileLayout = new FileLayout<>( new File( indexDirectory, "datetime" ), LocalDateTimeLayout.of( descriptor ), ValueGroup.LOCAL_DATE_TIME );
this.date = new FileLayout<>( new File( indexDirectory, "date" ), DateLayout.of( descriptor ), ValueGroup.DATE );
this.localTime = new FileLayout<>( new File( indexDirectory, "time" ), LocalTimeLayout.of( descriptor ), ValueGroup.LOCAL_TIME );
this.localDateTime = new FileLayout<>( new File( indexDirectory, "datetime" ), LocalDateTimeLayout.of( descriptor ), ValueGroup.LOCAL_DATE_TIME );
}

Iterable<FileLayout> existing()
{
List<FileLayout> existing = new ArrayList<>();
addIfExists( existing, dateFileLayout );
addIfExists( existing, dateTimeFileLayout );
addIfExists( existing, dateTimeZonedFileLayout );
addIfExists( existing, timeFileLayout );
addIfExists( existing, timeZonedFileLayout );
addIfExists( existing, durationFileLayout );
addIfExists( existing, date );
addIfExists( existing, localDateTime );
addIfExists( existing, zonedDateTime );
addIfExists( existing, localTime );
addIfExists( existing, zonedTime );
addIfExists( existing, duration );
return existing;
}

Expand All @@ -68,32 +68,32 @@ <T,E extends Exception> void loadExistingIndexes( TemporalIndexCache<T,E> indexC
}
}

private void addIfExists( List<FileLayout> existing, FileLayout fileLayout )
FileLayout<DateSchemaKey> date()
{
if ( exists( fileLayout ) )
{
existing.add( fileLayout );
}
return date;
}

private boolean exists( FileLayout fileLayout )
FileLayout<LocalTimeSchemaKey> localTime()
{
return fileLayout != null && fs.fileExists( fileLayout.indexFile );
return localTime;
}

public FileLayout<DateSchemaKey> date()
FileLayout<LocalDateTimeSchemaKey> localDateTime()
{
return dateFileLayout;
return localDateTime;
}

public FileLayout<LocalTimeSchemaKey> time()
private void addIfExists( List<FileLayout> existing, FileLayout fileLayout )
{
return timeFileLayout;
if ( exists( fileLayout ) )
{
existing.add( fileLayout );
}
}

public FileLayout<LocalDateTimeSchemaKey> dateTime()
private boolean exists( FileLayout fileLayout )
{
return dateTimeFileLayout;
return fileLayout != null && fs.fileExists( fileLayout.indexFile );
}

// .... we will add more explicit accessor methods later
Expand Down
Expand Up @@ -96,25 +96,25 @@ public IndexUpdater newDate() throws IOException
}

@Override
public IndexUpdater newDateTime() throws IOException
public IndexUpdater newLocalDateTime() throws IOException
{
return populator.dateTime().newPopulatingUpdater( propertyAccessor );
return populator.localDateTime().newPopulatingUpdater( propertyAccessor );
}

@Override
public IndexUpdater newDateTimeZoned() throws IOException
public IndexUpdater newZonedDateTime() throws IOException
{
throw new UnsupportedOperationException( "too tired to write" );
}

@Override
public IndexUpdater newTime() throws IOException
public IndexUpdater newLocalTime() throws IOException
{
return populator.time().newPopulatingUpdater( propertyAccessor );
return populator.localTime().newPopulatingUpdater( propertyAccessor );
}

@Override
public IndexUpdater newTimeZoned() throws IOException
public IndexUpdater newZonedTime() throws IOException
{
throw new UnsupportedOperationException( "too tired to write" );
}
Expand Down
Expand Up @@ -248,25 +248,25 @@ public PartPopulator<?> newDate() throws IOException
}

@Override
public PartPopulator<?> newDateTime() throws IOException
public PartPopulator<?> newLocalDateTime() throws IOException
{
return create( temporalIndexFiles.dateTime() );
return create( temporalIndexFiles.localDateTime() );
}

@Override
public PartPopulator<?> newDateTimeZoned() throws IOException
public PartPopulator<?> newZonedDateTime() throws IOException
{
throw new UnsupportedOperationException( "not implementedur still" );
}

@Override
public PartPopulator<?> newTime() throws IOException
public PartPopulator<?> newLocalTime() throws IOException
{
return create( temporalIndexFiles.time() );
return create( temporalIndexFiles.localTime() );
}

@Override
public PartPopulator<?> newTimeZoned() throws IOException
public PartPopulator<?> newZonedTime() throws IOException
{
throw new UnsupportedOperationException( "not implementedur still" );
}
Expand Down
Expand Up @@ -137,31 +137,31 @@ static class PartFactory implements TemporalIndexCache.Factory<TemporalIndexPart
}

@Override
public TemporalIndexPartReader<?> newDate() throws IOException
public TemporalIndexPartReader<?> newDate()
{
return accessor.selectOrElse( ValueGroup.DATE, TemporalIndexAccessor.PartAccessor::newReader, null );
}

@Override
public TemporalIndexPartReader<?> newDateTime()
public TemporalIndexPartReader<?> newLocalDateTime()
{
return accessor.selectOrElse( ValueGroup.LOCAL_DATE_TIME, TemporalIndexAccessor.PartAccessor::newReader, null );
}

@Override
public TemporalIndexPartReader<?> newDateTimeZoned()
public TemporalIndexPartReader<?> newZonedDateTime()
{
throw new UnsupportedOperationException( "Illiterate" );
}

@Override
public TemporalIndexPartReader<?> newTime()
public TemporalIndexPartReader<?> newLocalTime()
{
return accessor.selectOrElse( ValueGroup.LOCAL_TIME, TemporalIndexAccessor.PartAccessor::newReader, null );
}

@Override
public TemporalIndexPartReader<?> newTimeZoned()
public TemporalIndexPartReader<?> newZonedTime()
{
throw new UnsupportedOperationException( "Illiterate" );
}
Expand Down

0 comments on commit c6023ce

Please sign in to comment.