Subversion Repository Public Repository

litesoft

Diff Revisions 960 vs 961 for /trunk/DeviceDesktopTest/src/org/litesoft/language/server/SimplePropertyFileAccessorImpl.java

Diff revisions: vs.
  @@ -6,12 +6,12 @@
6 6 import java.util.*;
7 7
8 8 /**
9 - * Like Properties.java but simplified to only use natural lines and equals separators. And also supporting quoted values and only limited Key Forms Dotted Constrained Ascii Identifier (See Key).
9 + * Like Properties.java but simplified to only use natural lines and equals separators. And also supporting quoted values and only limited Key Forms Dotted
10 + * Constrained Ascii Identifier (See Key).
10 11 * Only supports # comments (as only the first non-whitespace character in a line)
11 12 * Leading and trailing whitespace is not preserved on save.
12 13 */
13 - public class SimplePropertyFileAccessorImpl implements SimplePropertyFileAccessor
14 - {
14 + public class SimplePropertyFileAccessorImpl implements SimplePropertyFileAccessor {
15 15
16 16 private TextFileAccessor mPropertyFile;
17 17
  @@ -20,64 +20,53 @@
20 20 */
21 21 @Override
22 22 public @NotNull
23 - @Immutable List<String> getKeys()
24 - {
23 + @Immutable List<String> getKeys() {
25 24 return Collections.unmodifiableList( new ArrayList<>( mOrderedKeyValues.keySet() ) );
26 25 }
27 26
28 27 @Override
29 - public @Nullable String getProperty( String pKey )
30 - {
28 + public @Nullable String getProperty( String pKey ) {
31 29 return null;
32 30 }
33 31
34 32 /**
35 - * Writes all the properties to a properties file retaining the order of the properties as they were read and retaining any comments as they were read as well.
33 + * Writes all the properties to a properties file retaining the order of the properties as they were read and retaining any comments as they were read as
34 + * well.
36 35 *
37 36 * @throws IOException
38 37 */
39 38 @Override
40 39 public void save()
41 - throws IOException
42 - {
40 + throws IOException {
43 41 mPropertyFile.write( mLineTracker.toLines() );
44 42 }
45 43
46 44 public SimplePropertyFileAccessorImpl( TextFileAccessor pPropertyFile )
47 - throws IOException
48 - {
45 + throws IOException {
49 46 mPropertyFile = pPropertyFile;
50 47 mLineTracker = new LineTracker( mPropertyFile.read(), mOrderedKeyValues );
51 48 }
52 49
53 50 public SimplePropertyFileAccessorImpl( File pPropertyFile )
54 - throws IOException
55 - {
51 + throws IOException {
56 52 this( new TextFileAccessorImpl( pPropertyFile ) );
57 53 }
58 54
59 55 private Map<String, String> mOrderedKeyValues = new LinkedHashMap<>();
60 56 private LineTracker mLineTracker;
61 57
62 - private static class LineTracker
63 - {
58 + private static class LineTracker {
64 59 private Object[] mLines;
65 60
66 - public LineTracker( String[] pLines, Map<String, String> pKeyValues )
67 - {
61 + public LineTracker( String[] pLines, Map<String, String> pKeyValues ) {
68 62 mLines = new Object[pLines.length];
69 - for ( int i = 0; i < pLines.length; i++ )
70 - {
63 + for ( int i = 0; i < pLines.length; i++ ) {
71 64 String zLine = pLines[i].trim();
72 - if ( zLine.length() == 0 || zLine.startsWith( "#" ) )
73 - {
65 + if ( zLine.length() == 0 || zLine.startsWith( "#" ) ) {
74 66 mLines[i] = zLine;
75 - }
76 - else
77 - {
67 + } else {
78 68 Entry zEntry = Entry.parse( zLine );
79 - if ( zEntry == null )
80 - {
69 + if ( zEntry == null ) {
81 70 throw new IllegalArgumentException( "Bad Line in Property File at: " + i );
82 71 }
83 72 mLines[i] = zEntry;
  @@ -86,36 +75,30 @@
86 75 }
87 76 }
88 77
89 - public String[] toLines()
90 - {
78 + public String[] toLines() {
91 79 String[] zLines = new String[mLines.length];
92 - for ( int i = 0; i < mLines.length; i++ )
93 - {
80 + for ( int i = 0; i < mLines.length; i++ ) {
94 81 zLines[i] = mLines[i].toString();
95 82 }
96 83 return zLines;
97 84 }
98 85 }
99 86
100 - private static class Entry
101 - {
87 + private static class Entry {
102 88
103 89 private String mKey;
104 90 private String mValue;
105 91
106 - public static Entry parse( String pLine )
107 - {
92 + public static Entry parse( String pLine ) {
108 93 // TODO: XXX
109 94 return null;
110 95 }
111 96
112 - public String getKey()
113 - {
97 + public String getKey() {
114 98 return mKey;
115 99 }
116 100
117 - public String getValue()
118 - {
101 + public String getValue() {
119 102 return mValue;
120 103 }
121 104 }