Class TextFileSystemViewCrudMapAdapter<Entry>
- java.lang.Object
-
- de.xima.fc.gui.common.model.file.TextFileSystemViewCrudMapAdapter<Entry>
-
- Type Parameters:
Entry
- The type of the file system entry.
- All Implemented Interfaces:
CrudMapAdapter<String,String>
,Serializable
public final class TextFileSystemViewCrudMapAdapter<Entry> extends Object implements Serializable, CrudMapAdapter<String,String>
ACrudMapAdapter
for a map from file keys to the file's text content, backed by aICommonFileSystem
.The map key is the ID of the file. The ID can be any arbitrary string that is recognized by the configured entry encoder and decoder.
The map value is the
text content
as obtained by theICommonFileSystem
. Uses the configured charset for encoding and decoding the binary data to/from strings.Wraps a
ICommonFileSystem
and forwards all file reads and writes to that view.Note: The iterator implementations may not be efficient. The intended use case of this class is to serve as a simple get-set map for known files, i.e. you should only use
Map.get(Object)
,Map.put(Object, Object)
,Map.containsKey(Object)
,Map.remove(Object)
.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TextFileSystemViewCrudMapAdapter.Builder<Entry>
Builder for aTextFileSystemViewCrudMapAdapter
.-
Nested classes/interfaces inherited from interface de.xima.fc.common.collection.CrudMapAdapter
CrudMapAdapter.Immutable<Key,Value>, CrudMapAdapter.SetLike<Value>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <Entry> TextFileSystemViewCrudMapAdapter.Builder<Entry>
builder(ISerializableFunction<Entry,String> entryEncoder, ISerializableFunction<String,Entry> entryDecoder)
Creates a new builder for aTextFileSystemViewCrudMapAdapter
, using the given encoder and decoder to convert between a file ID and a file system entry.void
delete(String fileId)
Removes the mapping for the given key.Iterable<String>
enumerateCandidateKeys()
Enumerates all keys for which a mapping may be present.String
get(String fileId)
Gets the value for the given key.void
set(String fileId, String content)
Associates a value with the given key.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.xima.fc.common.collection.CrudMapAdapter
computeSize, isEmpty
-
-
-
-
Method Detail
-
delete
public void delete(String fileId)
Description copied from interface:CrudMapAdapter
Removes the mapping for the given key.- Specified by:
delete
in interfaceCrudMapAdapter<String,String>
- Parameters:
fileId
- Key to disassociate with any values.
-
enumerateCandidateKeys
public Iterable<String> enumerateCandidateKeys()
Description copied from interface:CrudMapAdapter
Enumerates all keys for which a mapping may be present. May include additional keys for which no value is available, seeCrudMapAdapter.computeSize()
. Must NOT contain duplicate keys.- Specified by:
enumerateCandidateKeys
in interfaceCrudMapAdapter<String,String>
- Returns:
- A set with all potential keys.
-
get
public String get(String fileId)
Description copied from interface:CrudMapAdapter
Gets the value for the given key. Returnsnull
when no value is available for the key.- Specified by:
get
in interfaceCrudMapAdapter<String,String>
- Parameters:
fileId
- Key to access.- Returns:
- The value associated with the key, or
null
when no value is associated with the key.
-
set
public void set(String fileId, String content)
Description copied from interface:CrudMapAdapter
Associates a value with the given key.- Specified by:
set
in interfaceCrudMapAdapter<String,String>
- Parameters:
fileId
- Key to associate with a different value.content
- Value to associate with the key, nevernull
.
-
builder
public static <Entry> TextFileSystemViewCrudMapAdapter.Builder<Entry> builder(ISerializableFunction<Entry,String> entryEncoder, ISerializableFunction<String,Entry> entryDecoder)
Creates a new builder for aTextFileSystemViewCrudMapAdapter
, using the given encoder and decoder to convert between a file ID and a file system entry.Uses a
ICommonFileSystem
to read and write file text content. The map key is the file ID (as returned by the configured entry encoder), the map value is the file's text content. Uses the configured charset to encode and decode the binary data to / from strings.- Type Parameters:
Entry
- The type of the file system entry.- Parameters:
entryEncoder
- Encoder that converts a file system entry to a file ID string.entryDecoder
- Decoder that converts a file ID string to a file system entry.- Returns:
- A new builder for a
TextFileSystemViewCrudMapAdapter
.
-
-