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 @Override
public PartAccessor<?> newDateTime() throws IOException public PartAccessor<?> newLocalDateTime() throws IOException
{ {
return createPartAccessor( temporalIndexFiles.dateTime() ); return createPartAccessor( temporalIndexFiles.localDateTime() );
} }


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


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

} }


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


import org.neo4j.helpers.collection.Iterators;
import org.neo4j.values.storable.ValueGroup; 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 final Factory<T, E> factory;


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


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


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


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


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


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


case DURATION: case DURATION:
return 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; return date != null ? function.apply( date ) : orElse;


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


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


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


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


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


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


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


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


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


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


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


Iterable<FileLayout> existing() Iterable<FileLayout> existing()
{ {
List<FileLayout> existing = new ArrayList<>(); List<FileLayout> existing = new ArrayList<>();
addIfExists( existing, dateFileLayout ); addIfExists( existing, date );
addIfExists( existing, dateTimeFileLayout ); addIfExists( existing, localDateTime );
addIfExists( existing, dateTimeZonedFileLayout ); addIfExists( existing, zonedDateTime );
addIfExists( existing, timeFileLayout ); addIfExists( existing, localTime );
addIfExists( existing, timeZonedFileLayout ); addIfExists( existing, zonedTime );
addIfExists( existing, durationFileLayout ); addIfExists( existing, duration );
return existing; 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 ) ) return date;
{
existing.add( fileLayout );
}
} }


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 // .... we will add more explicit accessor methods later
Expand Down
Expand Up @@ -96,25 +96,25 @@ public IndexUpdater newDate() throws IOException
} }


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


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


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


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


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


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


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


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


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


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


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


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


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

0 comments on commit c6023ce

Please sign in to comment.