/** * Parses a Clock value from its raw bytes. * * @param raw - the raw bytes of Clock * @return a Clock object. * <code>Clock.ZERO</code> is returned upon <code>null</code> or a byte array with the length less than 8. */ public static Clock parseClock(byte[] raw) { if(raw == null || raw.length < 8) { return Clock.ZERO; } int cnt = raw.length >> 3; long[] values = new long[cnt]; ByteBuffer bb = ByteBuffer.wrap(raw); for(int i = 0; i < values.length; i++) { values[i] = bb.getLong(); } return new Clock(values); }
/** * Parses a Clock value from its raw bytes. * * @param raw - the raw bytes of Clock * @return a Clock object. * <code>Clock.ZERO</code> is returned upon <code>null</code> or a byte array with the length less than 8. */ public static Clock parseClock(byte[] raw) { if(raw == null || raw.length < 8) { return Clock.ZERO; } int cnt = raw.length >> 3; long[] values = new long[cnt]; ByteBuffer bb = ByteBuffer.wrap(raw); for(int i = 0; i < values.length; i++) { values[i] = bb.getLong(); } return new Clock(values); }
/** * Parses a Clock value from its string representation. * * @param str - the string representation of Clock * @return A Clock object. * <code>Clock.ZERO</code> is returned <code>upon</code> null or zero-length string. */ public static Clock parseClock(String str) { if(str == null || str.length() == 0) { return Clock.ZERO; } String[] parts = str.split(":"); long[] values = new long[parts.length]; for(int i = 0; i < values.length; i++) { values[i] = Long.parseLong(parts[i]); } return new Clock(values); }
/** * Parses a Clock value from its string representation. * * @param str - the string representation of Clock * @return A Clock object. * <code>Clock.ZERO</code> is returned <code>upon</code> null or zero-length string. */ public static Clock parseClock(String str) { if(str == null || str.length() == 0) { return Clock.ZERO; } String[] parts = str.split(":"); long[] values = new long[parts.length]; for(int i = 0; i < values.length; i++) { values[i] = Long.parseLong(parts[i]); } return new Clock(values); }
/** * @return the current clock of this SourceWaterMarksClock. */ @Override public synchronized Clock current() { int cnt = _entries.size(); long[] values = new long[cnt]; for(int i = 0; i < cnt; i++) { values[i] = _entries.get(i).getHWMScn(); } return new Clock(values); }
/** * @return the current clock of this SourceWaterMarksClock. */ @Override public synchronized Clock current() { int cnt = _entries.size(); long[] values = new long[cnt]; for(int i = 0; i < cnt; i++) { values[i] = _entries.get(i).getHWMScn(); } return new Clock(values); }
/** * Parses a string representation of <tt>SimplePosition</tt> in the form of <tt>Id:Offset:Index:Clock</tt>. * * <p> * For example, <tt>1:128956235:59272:12789234:12789257:12789305</tt> defines a position with <tt>Id=1</tt>, * <tt>Offset=128956235</tt>, <tt>Index=59272</tt> and <tt>Clock=12789234:12789257:12789305</tt>. * * @param s - the string representation of a position. * @throws <tt>NullPointerException</tt> if the string <tt>s</tt> is null. * @throws <tt>NumberFormatException</tt> if the string <tt>s</tt> contains non-parsable <tt>int</tt> or <tt>long</tt>. */ public static SimplePosition parsePosition(String s) { String[] parts = s.split(":"); int id = Integer.parseInt(parts[0]); long offset = Long.parseLong(parts[1]); int index = Integer.parseInt(parts[2]); if(parts.length == 3) { return new SimplePosition(id, offset, index, Clock.ZERO); } long[] values = new long[parts.length - 3]; for(int i = 0; i < values.length; i++) { values[i] = Long.parseLong(parts[3+i]); } return new SimplePosition(id, offset, index, new Clock(values)); } }
/** * Parses a string representation of <tt>SimplePosition</tt> in the form of <tt>Id:Offset:Index:Clock</tt>. * * <p> * For example, <tt>1:128956235:59272:12789234:12789257:12789305</tt> defines a position with <tt>Id=1</tt>, * <tt>Offset=128956235</tt>, <tt>Index=59272</tt> and <tt>Clock=12789234:12789257:12789305</tt>. * * @param s - the string representation of a position. * @throws <tt>NullPointerException</tt> if the string <tt>s</tt> is null. * @throws <tt>NumberFormatException</tt> if the string <tt>s</tt> contains non-parsable <tt>int</tt> or <tt>long</tt>. */ public static SimplePosition parsePosition(String s) { String[] parts = s.split(":"); int id = Integer.parseInt(parts[0]); long offset = Long.parseLong(parts[1]); int index = Integer.parseInt(parts[2]); if(parts.length == 3) { return new SimplePosition(id, offset, index, Clock.ZERO); } long[] values = new long[parts.length - 3]; for(int i = 0; i < values.length; i++) { values[i] = Long.parseLong(parts[3+i]); } return new SimplePosition(id, offset, index, new Clock(values)); } }