Class SynchronizableRepeater
- java.lang.Object
-
- org.ametys.plugins.repository.data.holder.values.SynchronizableRepeater
-
public final class SynchronizableRepeater extends Object
Wrapper for a synchronizable repeater.
Contains the repeater values and a mapping between stored entry positions and new ones.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SynchronizableRepeater.Mode
The entries write mode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SynchronizableRepeater
appendOrRemove(List<Map<String,Object>> newEntries, Set<Integer> removedEntries)
Append and/or remove entries in a repeater.static SynchronizableRepeater
copy(SynchronizableRepeater repeater, List<Map<String,Object>> newEntries)
Copy the provided repeater, optionally replacing entries with given ones.List<Map<String,Object>>
getEntries()
Returns the new repeater values.SynchronizableRepeater.Mode
getMode()
Returns the write mode for provided entries.Map<Integer,Integer>
getPositionsMapping()
Returns the mapping from stored positions to new ones.Optional<Integer>
getPreviousPosition(int newPosition)
Retrieves the previous position of the given one from the repeater mappingSet<Integer>
getRemovedEntries()
Returns the entries to be removed.List<Integer>
getReplacePositions()
Returns the positions of replacing entries.static SynchronizableRepeater
replace(List<Map<String,Object>> entries, List<Integer> positions)
Replace values in a repeater.static SynchronizableRepeater
replaceAll(List<Map<String,Object>> entries, Map<Integer,Integer> positionsMapping)
Replace all values in a repeater, optionally moving or removing entries.
-
-
-
Method Detail
-
replaceAll
public static SynchronizableRepeater replaceAll(List<Map<String,Object>> entries, Map<Integer,Integer> positionsMapping)
Replace all values in a repeater, optionally moving or removing entries. Entries not present in the mapping will be removed.- Parameters:
entries
- the new repeater values.positionsMapping
- a mapping from stored positions to new ones. No mapping for an existing entry means removal. A null mapping means the identity mapping.- Returns:
- a
SynchronizableRepeater
in replace mode.
-
replace
public static SynchronizableRepeater replace(List<Map<String,Object>> entries, List<Integer> positions)
Replace values in a repeater.- Parameters:
entries
- the new repeater values.positions
- the positions of the provided entries in the repeater. A null List means replacing the first entries.- Returns:
- a
SynchronizableRepeater
in replace mode.
-
appendOrRemove
public static SynchronizableRepeater appendOrRemove(List<Map<String,Object>> newEntries, Set<Integer> removedEntries)
Append and/or remove entries in a repeater.- Parameters:
newEntries
- the entries to be appended to the repeater.removedEntries
- the entries to be removed from the repeater.- Returns:
- a
SynchronizableRepeater
in append mode.
-
copy
public static SynchronizableRepeater copy(SynchronizableRepeater repeater, List<Map<String,Object>> newEntries)
Copy the provided repeater, optionally replacing entries with given ones.- Parameters:
repeater
- the SynchronizableRepeater to copynewEntries
- the new entries values- Returns:
- a new SynchronizableRepeater
-
getPositionsMapping
public Map<Integer,Integer> getPositionsMapping()
Returns the mapping from stored positions to new ones.- Returns:
- the mapping from stored positions to new ones.
-
getReplacePositions
public List<Integer> getReplacePositions()
Returns the positions of replacing entries.- Returns:
- the positions of replacing entries.
-
getEntries
public List<Map<String,Object>> getEntries()
Returns the new repeater values.- Returns:
- the new repeater values.
-
getRemovedEntries
public Set<Integer> getRemovedEntries()
Returns the entries to be removed.
Only relevant for append mode.
For replace mode, removed entries are carried trough the positions mapping.- Returns:
- the new repeater values.
-
getPreviousPosition
public Optional<Integer> getPreviousPosition(int newPosition)
Retrieves the previous position of the given one from the repeater mapping- Parameters:
newPosition
- the new entry position- Returns:
- the previous entry position
-
getMode
public SynchronizableRepeater.Mode getMode()
Returns the write mode for provided entries.- Returns:
- the write mode
-
-