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
package org.litesoft.language.model;

import org.litesoft.core.annotations.*;
import org.litesoft.core.typeutils.*;
import org.litesoft.core.util.*;

/**
 * A Language Key is a series of constrained 7bit Ascii Java Identifier (Alpha followed by zero or more by AlphaNumerics or underscores) separated by single dots ('.').
 */
public class Key
{
    public Key( @NotEmpty String pKey )
    {
        Problem zProblem = validate( key = pKey );
        if ( zProblem != null )
        {
            throw new IllegalArgumentException( zProblem.toString() );
        }
    }

    public final @NotEmpty String getKey()
    {
        return key;
    }

    public static @Nullable Problem validate( String pKey )
    {
        if ( Strings.isNullOrEmpty( pKey ) )
        {
            return new Problem( "Empty" );
        }
        String[] zParts = Strings.parseChar( pKey, '.' );
        for ( int i = 0; i < zParts.length; i++ )
        {
            String zPart = zParts[i];
            if ( !Strings.isConstrainedAsciiIdentifier( zPart ) )
            {
                return new Problem.Builder( "Invalid" )
                        .add( "Part", i )
                        .add( "At", pKey.indexOf( zPart ) )
                        .build();
            }
        }
        return null;
    }

    private /* final */ String key;

    @Deprecated /** for Serialization */
    protected Key()
    {
    }
}

Commits for litesoft/trunk/DeviceDesktopTest/src/org/litesoft/language/model/Key.java

Diff revisions: vs.
Revision Author Commited Message
936 GeorgeS picture GeorgeS Sun 01 Jun, 2014 20:19:38 +0000

Language Support