Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package org.litesoft.textfiledirectory;

import org.litesoft.commonfoundation.annotations.*;
import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.core.simpletypes.*;

import org.litesoft.commonfoundation.typeutils.Objects;
import java.util.*;

public class TextFileDirectoryMemory extends AbstractTextFileDirectory
{
    public static final String DEFAULT_DIRECTORY = "TheOne";

    private final Map<String, TextFile> mFiles = new HashMap<String, TextFile>();
    private final String mDirectory;
    private boolean mExists;

    public TextFileDirectoryMemory( String pDirectory, boolean pExists )
    {
        mDirectory = Strings.assertNotNullNotEmpty( "Directory", pDirectory );
        mExists = pExists;
    }

    public TextFileDirectoryMemory( String pDirectory )
    {
        this( pDirectory, true );
    }

    public TextFileDirectoryMemory( boolean pExists )
    {
        this( DEFAULT_DIRECTORY, pExists );
    }

    public TextFileDirectoryMemory()
    {
        this( true );
    }

    @Override
    public String getDirectoryPath()
    {
        return mDirectory;
    }

    @Override
    public boolean exists()
    {
        return mExists;
    }

    @Override
    public String[] getFiles( String... pExtensions )
    {
        String[] zExtensions = preprocessExtensions( pExtensions );
        if ( mFiles.isEmpty() )
        {
            return Strings.EMPTY_ARRAY;
        }
        if ( zExtensions.length == 0 )
        {
            return mFiles.keySet().toArray( new String[mFiles.size()] );
        }
        List<String> zFound = new ArrayList<String>( mFiles.size() );
        for ( String zFileName : mFiles.keySet() )
        {
            if ( endsWithOneOf( zFileName, zExtensions ) )
            {
                zFound.add( zFileName );
            }
        }
        Collections.sort( zFound );
        return zFound.toArray( new String[zFound.size()] );
    }

    private boolean endsWithOneOf( String pFileName, String[] pExtensions )
    {
        for ( String zExtension : pExtensions )
        {
            if ( pFileName.endsWith( zExtension ) )
            {
                return true;
            }
        }
        return false;
    }

    @Override
    public TextFile load( @NotNull String pFileName )
            throws FileDoesNotExists
    {
        return mFiles.get( assertExists( Strings.assertNotNullNotEmpty( "FileName", pFileName ) ) );
    }

    @Override
    public void create( @NotNull TextFile pFile )
            throws FileAlreadyExists
    {
        write( assertNotExist( getFile( pFile ) ), pFile );
    }

    @Override
    public void update( @NotNull TextFile pFile )
            throws FileDoesNotExists
    {
        write( assertExists( getFile( pFile ) ), pFile );
    }

    @Override
    public void delete( @NotNull TextFile pFile )
            throws FileDoesNotExists
    {
        LLdelete( getFile( pFile ) );
    }

    @Override
    public void delete( @NotNull String pFileName )
            throws FileDoesNotExists
    {
        LLdelete( Strings.assertNotNullNotEmpty( "FileName", pFileName ) );
    }

    private void write( String pFileName, TextFile pTextFile )
    {
        mFiles.put( pFileName, pTextFile );
        mExists = true;
    }

    private void LLdelete( String pFileName )
    {
        mFiles.remove( assertExists( pFileName ) );
        mExists = true;
    }

    private String assertExists( String pFileName )
    {
        assertExists( mFiles.containsKey( pFileName ), pFileName );
        return pFileName;
    }

    private String assertNotExist( String pFileName )
    {
        assertNotExists( mFiles.containsKey( pFileName ), pFileName );
        return pFileName;
    }

    private String getFile( TextFile pFile )
    {
        return Objects.assertNotNull( "File", pFile ).getFileName();
    }
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/textfiledirectory/TextFileDirectoryMemory.java

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

836 Diff Diff GeorgeS picture GeorgeS Wed 05 Sep, 2012 15:01:18 +0000
821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
800 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:33:38 +0000
791 Diff Diff GeorgeS picture GeorgeS Sun 12 Aug, 2012 15:22:58 +0000

!

789 GeorgeS picture GeorgeS Sat 11 Aug, 2012 17:47:31 +0000