void register ( long mjDay , int leapAdjustment ) { if ( leapAdjustment != - 1 && leapAdjustment != 1 ) { throw new IllegalArgumentException ( "Leap adjustment must be -1 or 1" ) ; } Data data = dataRef . get ( ) ; int pos = Arrays . binarySearch ( data . dates , mjDay ) ; int currentAdj = pos > 0 ? data . offsets [ pos ] - data . offsets [ pos - 1 ] : 0 ; if ( currentAdj == leapAdjustment ) { return ; // matches previous definition } if ( mjDay <= data . dates [ data . dates . length - 1 ] ) { throw new IllegalArgumentException ( "Date must be after the last configured leap second date" ) ; } long [ ] dates = Arrays . copyOf ( data . dates , data . dates . length + 1 ) ; int [ ] offsets = Arrays . copyOf ( data . offsets , data . offsets . length + 1 ) ; long [ ] taiSeconds = Arrays . copyOf ( data . taiSeconds , data . taiSeconds . length + 1 ) ; int offset = offsets [ offsets . length - 2 ] + leapAdjustment ; dates [ dates . length - 1 ] = mjDay ; offsets [ offsets . length - 1 ] = offset ; taiSeconds [ taiSeconds . length - 1 ] = tai ( mjDay , offset ) ; Data newData = new Data ( dates , offsets , taiSeconds ) ; if ( dataRef . compareAndSet ( data , newData ) == false ) { throw new ConcurrentModificationException ( "Unable to update leap second rules as they have already been updated" ) ; } }
Adds a new leap second to these rules .