Mercurial Hosting > luan
comparison core/src/luan/LuanTableImpl.java @ 226:392105b660d7
add LuanProperty
git-svn-id: https://luan-java.googlecode.com/svn/trunk@227 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 22 Jul 2014 06:23:13 +0000 |
parents | 05eb2837ddbf |
children | 9ce18106f95a |
comparison
equal
deleted
inserted
replaced
225:7c768f63bbb3 | 226:392105b660d7 |
---|---|
13 import java.util.HashSet; | 13 import java.util.HashSet; |
14 import java.util.IdentityHashMap; | 14 import java.util.IdentityHashMap; |
15 import java.util.regex.Pattern; | 15 import java.util.regex.Pattern; |
16 | 16 |
17 | 17 |
18 final class LuanTableImpl extends AbstractLuanTable implements LuanTable, DeepCloneable<LuanTableImpl>, LuanRepr { | 18 class LuanTableImpl extends AbstractLuanTable implements LuanTable, DeepCloneable<LuanTableImpl>, LuanRepr { |
19 private Map<Object,Object> map = null; | 19 private Map<Object,Object> map = null; |
20 private List<Object> list = null; | 20 private List<Object> list = null; |
21 private LuanTable metatable = null; | 21 private LuanTable metatable = null; |
22 | 22 |
23 public LuanTableImpl() {} | 23 public LuanTableImpl() {} |
138 } | 138 } |
139 StringBuilder sb = new StringBuilder(); | 139 StringBuilder sb = new StringBuilder(); |
140 sb.append('{'); | 140 sb.append('{'); |
141 boolean isFirst = true; | 141 boolean isFirst = true; |
142 if( list != null ) { | 142 if( list != null ) { |
143 boolean gotNull = false; | |
144 for( int i=0; i<list.size(); i++ ) { | 143 for( int i=0; i<list.size(); i++ ) { |
145 Object obj = list.get(i); | 144 Object obj = list.get(i); |
146 if( obj==null ) { | 145 if( isFirst ) { |
147 gotNull = true; | 146 isFirst = false; |
148 } else { | 147 } else { |
149 if( isFirst ) { | 148 sb.append(", "); |
150 isFirst = false; | 149 } |
151 } else { | 150 sb.append(repr(set,obj)); |
152 sb.append(", "); | |
153 } | |
154 if( gotNull ) | |
155 sb.append(i+1).append('='); | |
156 sb.append(repr(set,obj)); | |
157 } | |
158 } | 151 } |
159 } | 152 } |
160 if( map != null ) { | 153 if( map != null ) { |
161 for( Map.Entry<Object,Object> entry : map.entrySet() ) { | 154 for( Map.Entry<Object,Object> entry : map.entrySet() ) { |
162 if( isFirst ) { | 155 if( isFirst ) { |
171 return sb.toString(); | 164 return sb.toString(); |
172 } | 165 } |
173 | 166 |
174 private static final Pattern namePtn = Pattern.compile("[a-zA-Z_][a-zA-Z_0-9]*"); | 167 private static final Pattern namePtn = Pattern.compile("[a-zA-Z_][a-zA-Z_0-9]*"); |
175 | 168 |
176 private static String reprKey(Set<LuanTableImpl> set,Object obj) { | 169 private String reprKey(Set<LuanTableImpl> set,Object obj) { |
177 if( obj instanceof String ) { | 170 if( obj instanceof String ) { |
178 String s = (String)obj; | 171 String s = (String)obj; |
179 if( namePtn.matcher(s).matches() ) | 172 if( namePtn.matcher(s).matches() ) |
180 return s; | 173 return s; |
181 } | 174 } |
182 return "[" + repr(set,obj) + "]"; | 175 return "[" + repr(set,obj) + "]"; |
183 } | 176 } |
184 | 177 |
185 private static String repr(Set<LuanTableImpl> set,Object obj) { | 178 String repr(Set<LuanTableImpl> set,Object obj) { |
186 if( obj instanceof LuanTableImpl ) { | 179 if( obj instanceof LuanTableImpl ) { |
187 LuanTableImpl t = (LuanTableImpl)obj; | 180 LuanTableImpl t = (LuanTableImpl)obj; |
188 return t.repr(set); | 181 return t.repr(set); |
189 } else { | 182 } else { |
190 String s = Luan.repr(obj); | 183 String s = Luan.repr(obj); |
347 } | 340 } |
348 }; | 341 }; |
349 } | 342 } |
350 | 343 |
351 @Override public LuanTable subList(int from,int to) { | 344 @Override public LuanTable subList(int from,int to) { |
352 LuanTableImpl tbl = new LuanTableImpl(); | 345 LuanTableImpl tbl = shallowClone(); |
353 tbl.list = new ArrayList<Object>(list().subList(from-1,to-1)); | 346 tbl.list = new ArrayList<Object>(list().subList(from-1,to-1)); |
354 return tbl; | 347 return tbl; |
355 } | 348 } |
356 | 349 |
357 @Override public LuanTable getMetatable() { | 350 @Override public LuanTable getMetatable() { |