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>
A CrudMapAdapter for a map from file keys to the file's text content, backed by a ICommonFileSystem.

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 the ICommonFileSystem. 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:
  • Method Details

    • delete

      public void delete(String fileId)
      Description copied from interface: CrudMapAdapter
      Removes the mapping for the given key.
      Specified by:
      delete in interface CrudMapAdapter<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, see CrudMapAdapter.computeSize(). Must NOT contain duplicate keys.
      Specified by:
      enumerateCandidateKeys in interface CrudMapAdapter<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. Returns null when no value is available for the key.
      Specified by:
      get in interface CrudMapAdapter<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 interface CrudMapAdapter<String,String>
      Parameters:
      fileId - Key to associate with a different value.
      content - Value to associate with the key, never null.
    • builder

      public static <Entry> TextFileSystemViewCrudMapAdapter.Builder<Entry> builder(ISerializableFunction<Entry,String> entryEncoder, ISerializableFunction<String,Entry> entryDecoder)
      Creates a new builder for a TextFileSystemViewCrudMapAdapter, 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.