Package com.google.gerrit.server.patch
Class GitPositionTransformer.PositionedEntity<T>
- java.lang.Object
-
- com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity<T>
-
- Type Parameters:
T
- an object/entity type which has aGitPositionTransformer.Position
- Enclosing class:
- GitPositionTransformer
public static class GitPositionTransformer.PositionedEntity<T> extends Object
Wrapper around an instance ofT
which annotates it with aGitPositionTransformer.Position
. Methods such asshiftPositionBy(int)
andwithFilePath(String)
allow to update the associatedGitPositionTransformer.Position
. Afterwards, usegetEntityAtUpdatedPosition()
to get an updated version of theT
instance.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> GitPositionTransformer.PositionedEntity<T>
create(T entity, Function<T,GitPositionTransformer.Position> positionExtractor, BiFunction<T,GitPositionTransformer.Position,T> updatedEntityCreator)
Creates a newPositionedEntity
.T
getEntity()
Returns the original underlying entity.T
getEntityAtUpdatedPosition()
Returns an updated version of the entity to which the internally storedGitPositionTransformer.Position
was written back to.GitPositionTransformer.PositionedEntity<T>
shiftPositionBy(int amount)
Shifts the trackedGitPositionTransformer.Position
by the specified amount.GitPositionTransformer.PositionedEntity<T>
withFilePath(String filePath)
Updates the file path of the trackedGitPositionTransformer.Position
.GitPositionTransformer.PositionedEntity<T>
withPosition(GitPositionTransformer.Position newPosition)
Updates the trackedGitPositionTransformer.Position
.
-
-
-
Method Detail
-
create
public static <T> GitPositionTransformer.PositionedEntity<T> create(T entity, Function<T,GitPositionTransformer.Position> positionExtractor, BiFunction<T,GitPositionTransformer.Position,T> updatedEntityCreator)
Creates a newPositionedEntity
.- Type Parameters:
T
- an object/entity type which has aGitPositionTransformer.Position
- Parameters:
entity
- an instance which should be annotated with aGitPositionTransformer.Position
positionExtractor
- a function describing how aGitPositionTransformer.Position
can be derived from the given entityupdatedEntityCreator
- a function to create a new entity of typeT
from an existing entity and a givenGitPositionTransformer.Position
. This must return a new instance of typeT
! The existing instance must not be modified!
-
getEntity
public T getEntity()
Returns the original underlying entity.- Returns:
- the original instance of
T
-
getEntityAtUpdatedPosition
public T getEntityAtUpdatedPosition()
Returns an updated version of the entity to which the internally storedGitPositionTransformer.Position
was written back to.- Returns:
- an updated instance of
T
-
shiftPositionBy
public GitPositionTransformer.PositionedEntity<T> shiftPositionBy(int amount)
Shifts the trackedGitPositionTransformer.Position
by the specified amount.- Parameters:
amount
- number of lines to shift. Negative values mean moving the range up, positive values mean moving the range down.- Returns:
- a
PositionedEntity
with updatedGitPositionTransformer.Position
-
withFilePath
public GitPositionTransformer.PositionedEntity<T> withFilePath(String filePath)
Updates the file path of the trackedGitPositionTransformer.Position
.- Parameters:
filePath
- the new file path to use- Returns:
- a
PositionedEntity
with updatedGitPositionTransformer.Position
-
withPosition
public GitPositionTransformer.PositionedEntity<T> withPosition(GitPositionTransformer.Position newPosition)
Updates the trackedGitPositionTransformer.Position
.- Returns:
- a
PositionedEntity
with updatedGitPositionTransformer.Position
-
-