File tree Expand file tree Collapse file tree
src/main/java/com/javabaas/javasdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -138,8 +138,6 @@ public void setAcl(JBAcl acl) {
138138 INVALID_KEYS .add ("targetClass" );
139139 }
140140
141-
142-
143141 public JBObject () {
144142 objectId = "" ;
145143 serverData = new HashMap <>();
@@ -178,7 +176,9 @@ private boolean checkKey(String key) {
178176 return true ;
179177 }
180178
181-
179+ public Date getDate (String key ) {
180+ return JBUtils .dateFromString ((String ) get (key ));
181+ }
182182
183183 public void removeKey (String key ) {
184184 try {
@@ -215,7 +215,9 @@ public void increment(final String key, final Number amount) {
215215 }
216216
217217 public void addArray (String key , Object object ) {
218-
218+ List <Object > list = new ArrayList <>();
219+ list .add (object );
220+ addArray (key , list );
219221 }
220222
221223 public void addArray (String key , Collection <?> list ) {
Original file line number Diff line number Diff line change 1010import java .lang .reflect .Field ;
1111import java .security .MessageDigest ;
1212import java .security .NoSuchAlgorithmException ;
13+ import java .text .SimpleDateFormat ;
1314import java .util .*;
1415import java .util .regex .Pattern ;
1516
@@ -180,6 +181,44 @@ public static JBObject newJBObjectByClassName(String className) {
180181 }
181182 }
182183
184+ private static final ThreadLocal <SimpleDateFormat > THREAD_LOCAL_DATE_FORMAT =
185+ new ThreadLocal <SimpleDateFormat >();
186+ private static final String dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ;
187+
188+ public static Date dateFromString (String content ) {
189+ if (isEmpty (content ))
190+ return null ;
191+ if (isDigitString (content )) {
192+ return new Date (Long .parseLong (content ));
193+ }
194+ Date date = null ;
195+ SimpleDateFormat format = THREAD_LOCAL_DATE_FORMAT .get ();
196+ // reuse date format.
197+ if (format == null ) {
198+ format = new SimpleDateFormat (dateFormat );
199+ format .setTimeZone (TimeZone .getTimeZone ("UTC" ));
200+ THREAD_LOCAL_DATE_FORMAT .set (format );
201+ }
202+ try {
203+ date = format .parse (content );
204+ } catch (Exception exception ) {
205+
206+ }
207+ return date ;
208+ }
209+
210+ public static boolean isDigitString (String s ) {
211+ if (s == null )
212+ return false ;
213+ for (int i = 0 ; i < s .length (); i ++) {
214+ char c = s .charAt (i );
215+ if (!Character .isDigit (c )) {
216+ return false ;
217+ }
218+ }
219+ return true ;
220+ }
221+
183222 /****************JSON BEGIN****************/
184223 public static <T > T readValue (String content , Class <T > valueType ) {
185224 if (content == null ) {
You can’t perform that action at this time.
0 commit comments