private void updateTime ( long tolerance ) { long now = System . currentTimeMillis ( ) ; // check for exact match if ( now == this . lastTimeCheck ) { return ; } // check for a "range" match if ( 0L != tolerance ) { long range = ( - 1 == tolerance ) ? DEFAULT_TOLERANCE : tolerance ; if ( ( now - this . lastTimeCheck ) <= range ) { return ; } } // otherwise need to format the current time this . myDate . setTime ( now ) ; this . myBuffer . setLength ( 0 ) ; this . myBuffer = this . myFormat . format ( this . myDate , this . myBuffer , new FieldPosition ( 0 ) ) ; // int len = this.myBuffer.length(); // // // extract the char[] of the time and save the byte[] equivalent // if (this.caTime.length != len) { // // both arrays will always have the same length // this.caTime = new char[len]; // this.baTime = new byte[len]; // } // this.myBuffer.getChars(0, len, this.caTime, 0); // for (int i = 0; i < len; i++) { // this.baTime[i] = (byte) this.caTime[i]; // } // delay the string creation until it's actually needed this . sTime = null ; this . lastTimeCheck = now ; }
Utility method to determine whether to use the cached time value or update to a newly formatted timestamp .