63 error(
" FileDataCollection cannot be used as java is not enabled. ");
66 data_dir = fullfile(
KerMor.
App.TempDirectory,...
67 sprintf(
" temp_fdc_%s ",...
70 this =
this@data.FileData(data_dir);
71 this.hm= java.util.HashMap;
89 delete@data.FileData(
this);
103 if this.hm.containsKey(key)
105 data = load(this.
getfile(this.hm.get(key)), varargin[:]);
107 warning(
" KerMor:FileDataCollection ",...
108 " Error loading a file from directory %s: %s ",...
117 if exist(file,
" file ") == 2
118 data = load(file,varargin[:]);
119 this.hm.put(key,[key
" .mat "]);
143 if nr > this.hm.size || nr < 1
144 error(
" Invalid data position number: %d ",nr);
146 keys = this.hm.keySet.toArray(java_array(
" java.lang.String ",1));
147 data = load(this.
getfile(this.hm.get(keys(nr))), varargin[:]);
165 res = this.hm.containsKey(key);
167 res = res || exist(fullfile(this.
DataDirectory,[key
" .mat "]),
" file ") == 2;
173 file = [key
" .mat "];
174 this.hm.put(key,file);
179 save(file,
" -struct ",
" data ",fn[:]);
188 ks = this.hm.values.iterator;
193 warning(
" KerMor:data:FileDataCollection ",...
194 " Could not delete file '%s': %s\nPlease remove manually. ",...
205 static function this =
loadobj(
this,initfrom) {
207 if ~isa(
this,
" data.FileDataCollection ")
209 this = data.FileDataCollection(initfrom.DataDirectory);
212 if nargin == 2 || created
213 this.hm= initfrom.hm;
214 this =
loadobj@data.FileData(
this, initfrom);
216 this =
loadobj@data.FileData(
this);
225 thedir = fullfile(
KerMor.
App.TempDirectory,
" testFDC ");
226 c = data.FileDataCollection(thedir);
231 s.field= rand(200,300);
232 c.addData(keys(
k),s);
236 if exist(thedir,
" file ") ~= 0
240 c = data.FileDataCollection(thedir);
242 s.field= rand(500,500);
243 c.addData(keys(
k),s);
245 save(fullfile(thedir,
" tmpsave.mat "),
" c ");
247 if exist(thedir,
" file ") ~= 7
function res = hasData(keydata)
Collection of generally useful functions.
static function res = test_FileDataCollection()
Quickly tests if the directory is persisted(deleted) when (not) saved to a mat file.
static function gen = generateID()
Generates a new unique ID.
function file = getfile(file)
static function this = loadobj(this, initfrom)
function struct data = getDataNr(nr, varargin)
Retrieves data from the nr-st collection element.
FileDataCollection(data_dir)
Creates a new FileDataCollection in a file folder.
A variable number of input arguments.
KeepFiles
Tells the FileDataCollection to keep any stored files if the instance is deleted but has not been pre...
fieldnames
Returns a cell array of string containing the names of public properties. See the MATLAB fieldnames f...
function n = getCollectionSize()
FileData: Base class for access of files stored in a specific folder in the local file system...
static function h = getHash(vec)
Returns a hash code for the given vector.
FileDataCollection: Basic class for storing data given a hashable key value.
char DataDirectory
The root folder where the FileData's files are saved.
function addData(keydata, data)
logical isSaved
This flag indicates that this FileData instance has been stored to disk via the save method somewhere...
Global configuration class for all KerMor run-time settings.
function struct data = getData(rowvec< double > keydata, varargin)
methods(Access=protected) Retrieves data from the collection element of a given key.
static function KerMor theinstance = App()
The singleton KerMor instance.