public class GeoFileRepository<T extends IGeoPointInfo> extends java.lang.Object implements IGeoRepository<T>
Repository to load/save List< GeoPointDto
> via a file.
It can be used for GeoPointDto
or any custom IGeoPointInfo
implementation.
Example
GeoFileRepository<GeoPointDto> repository
= new GeoFileRepository<>(new File("/path/to/repository.txt"));
List<GeoPointDto> items = repository.load();
items.add(new GeoPointDto().setLatitude(1).setLongitude(2)
.setId("#4711").setName("my test point"));
repository.save();
Created by k3b on 17.03.2015.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COMMENT
Lines starting with char are comments.
|
protected java.util.List<T> |
mGeoPointList
The
IGeoPointInfo points contained in this repository |
Constructor and Description |
---|
GeoFileRepository(java.io.File file)
Connect repository to a
File . |
GeoFileRepository(java.io.File file,
GeoPointDto factory)
Connect repository to a
File . |
Modifier and Type | Method and Description |
---|---|
protected GeoPointDto |
create()
Factory method to generate a new empy point while reading a
IGeoPointInfo . |
java.lang.String |
createId()
Generate a new id for
IGeoPointInfo.getId() . |
IGeoRepository<T> |
delete(T item)
Removes item from repository-momory and file.
|
protected boolean |
isValid(IGeoPointInfo geo)
Returns true if geo should be loaded from / saved to repository
|
java.util.List<T> |
load()
Load from repository-file to memory.
|
void |
load(java.util.List<T> result,
java.io.Reader reader)
Load points from reader
|
protected GeoPointDto |
loadItem(java.lang.String line)
Implementation detail: Load point from file line.
|
java.util.List<T> |
reload()
Uncached, fresh load from repository-file to memory.
|
IGeoRepository<T> |
save()
Save from meomory to repositoryfile.
|
protected void |
save(java.util.List<T> source,
java.io.Writer writer)
Save source-points to writer
|
protected boolean |
saveItem(java.io.Writer writer,
T geo)
Saves one point to writer
|
public static final java.lang.String COMMENT
Lines starting with char are comments. These lines are not interpreted
protected java.util.List<T extends IGeoPointInfo> mGeoPointList
The IGeoPointInfo
points contained in this repository
public GeoFileRepository(java.io.File file)
Connect repository to a File
.
public GeoFileRepository(java.io.File file, GeoPointDto factory)
Connect repository to a File
.
factory
- get-s cloned for every new point read from file. Workaround since java generics do not support construction of generic parameters.public java.util.List<T> load()
Load from repository-file to memory.
load
in interface IGeoRepository<T extends IGeoPointInfo>
public java.util.List<T> reload()
Uncached, fresh load from repository-file to memory.
reload
in interface IGeoRepository<T extends IGeoPointInfo>
public java.lang.String createId()
Generate a new id for IGeoPointInfo.getId()
.
createId
in interface IGeoRepository<T extends IGeoPointInfo>
public IGeoRepository<T> delete(T item)
Removes item from repository-momory and file.
delete
in interface IGeoRepository<T extends IGeoPointInfo>
item
- that should be removedpublic IGeoRepository<T> save()
Save from meomory to repositoryfile.
save
in interface IGeoRepository<T extends IGeoPointInfo>
public void load(java.util.List<T> result, java.io.Reader reader) throws java.io.IOException
Load points from reader
java.io.IOException
protected GeoPointDto loadItem(java.lang.String line)
Implementation detail: Load point from file line.
protected GeoPointDto create()
Factory method to generate a new empy point while reading a IGeoPointInfo
.
The method can be overwritten to create custom IGeoPointInfo
point types.
The default implementation uses GeoPointDto.clone()
to generate the point.
protected void save(java.util.List<T> source, java.io.Writer writer) throws java.io.IOException
Save source-points to writer
java.io.IOException
protected boolean saveItem(java.io.Writer writer, T geo) throws java.io.IOException
Saves one point to writer
java.io.IOException
protected boolean isValid(IGeoPointInfo geo)
Returns true if geo should be loaded from / saved to repository