regular maintenance
This commit is contained in:
		
							parent
							
								
									44bab60674
								
							
						
					
					
						commit
						8a5fc3d093
					
				| 
						 | 
					@ -149,8 +149,8 @@ public final class Ulid implements Serializable, Comparable<Ulid> {
 | 
				
			||||||
	 * @param ulid a ULID
 | 
						 * @param ulid a ULID
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public Ulid(Ulid ulid) {
 | 
						public Ulid(Ulid ulid) {
 | 
				
			||||||
		this.msb = ulid.getMostSignificantBits();
 | 
							this.msb = ulid.msb;
 | 
				
			||||||
		this.lsb = ulid.getLeastSignificantBits();
 | 
							this.lsb = ulid.lsb;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -313,29 +313,30 @@ public class UlidTest {
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void testIncrement() {
 | 
						public void testIncrement() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		long msb;
 | 
							final long milliseconds = System.currentTimeMillis();
 | 
				
			||||||
		long lsb;
 | 
							final BigInteger increment = BigInteger.valueOf(DEFAULT_LOOP_MAX);
 | 
				
			||||||
		Ulid ulid;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		final int loopMax = 100;
 | 
							// Test 1
 | 
				
			||||||
 | 
							byte[] random1 = { //
 | 
				
			||||||
		msb = 0x0123456789abcdefL;
 | 
									(byte) 0x00, (byte) 0x11, (byte) 0x22, (byte) 0x33, (byte) 0x44, //
 | 
				
			||||||
		lsb = 0x0123456789abcdefL;
 | 
									(byte) 0x55, (byte) 0x66, (byte) 0x77, (byte) 0x88, (byte) 0x99 };
 | 
				
			||||||
		ulid = new Ulid(msb, lsb);
 | 
							Ulid ulid1 = new Ulid(milliseconds, random1);
 | 
				
			||||||
		for (int i = 0; i < loopMax; i++) {
 | 
							for (int i = 0; i < DEFAULT_LOOP_MAX; i++) {
 | 
				
			||||||
			ulid = ulid.increment();
 | 
								ulid1 = ulid1.increment();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		assertEquals(msb, ulid.getMostSignificantBits());
 | 
							assertEquals(milliseconds, ulid1.getTime());
 | 
				
			||||||
		assertEquals(msb + loopMax, ulid.getLeastSignificantBits());
 | 
							assertEquals(new BigInteger(random1).add(increment), new BigInteger(ulid1.getRandom()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		msb = 0x0123456789abcdefL;
 | 
							// Test 2
 | 
				
			||||||
		lsb = 0xffffffffffffffffL - (loopMax / 2);
 | 
							byte[] random2 = { //
 | 
				
			||||||
		ulid = new Ulid(msb, lsb);
 | 
									(byte) 0x00, (byte) 0x11, (byte) 0xff, (byte) 0xff, (byte) 0xff, //
 | 
				
			||||||
		for (int i = 0; i < loopMax; i++) {
 | 
									(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
 | 
				
			||||||
			ulid = ulid.increment();
 | 
							Ulid ulid2 = new Ulid(milliseconds, random2);
 | 
				
			||||||
 | 
							for (int i = 0; i < DEFAULT_LOOP_MAX; i++) {
 | 
				
			||||||
 | 
								ulid2 = ulid2.increment();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		assertEquals(msb + 1, ulid.getMostSignificantBits());
 | 
							assertEquals(milliseconds, ulid2.getTime());
 | 
				
			||||||
		assertEquals((loopMax / 2) - 1, ulid.getLeastSignificantBits());
 | 
							assertEquals(new BigInteger(random2).add(increment), new BigInteger(ulid2.getRandom()));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue