public class UUIDGenerator { /** * random number generator for UUID generation */ private final SecureRandom secRand = new SecureRandom(); /** * 128-bit buffer for use with secRand */ private final byte[] secRandBuf16 = new byte[16]; public UUIDGenerator() { super(); } /** * @return uuid as String */ public String newUUID() { secRand.nextBytes(secRandBuf16); secRandBuf16[6] &= 0x0f; secRandBuf16[6] |= 0x40; /* version 4 */ secRandBuf16[8] &= 0x3f; secRandBuf16[8] |= 0x80; /* IETF variant */ secRandBuf16[10] |= 0x80; /* multicast bit */ long mostSig = 0; for (int i = 0; i < 8; i++) { mostSig = (mostSig << 8) | (secRandBuf16[i] & 0xff); } long leastSig = 0; for (int i = 8; i < 16; i++) { leastSig = (leastSig << 8) | (secRandBuf16[i] & 0xff); } return (digits(mostSig >> 32, 8) + "-" + digits(mostSig >> 16, 4) + "-" + digits(mostSig, 4) + "-" + digits(leastSig >> 48, 4) + "-" + digits( leastSig, 12)); } /** Returns val represented by the specified number of hex digits. */ private static String digits(long val, int digits) { long hi = 1L << (digits * 4); return Long.toHexString(hi | (val & (hi - 1))).substring(1);
public class UUIDGenerator { /** * random number generator for UUID generation */ private final SecureRandom secRand = new SecureRandom(); /** * 128-bit buffer for use with secRand */ private final byte[] secRandBuf16 = new byte[16]; public UUIDGenerator() { super(); } /** * @return uuid as String */ public String newUUID() { secRand.nextBytes(secRandBuf16); secRandBuf16[6] &= 0x0f; secRandBuf16[6] |= 0x40; /* version 4 */ secRandBuf16[8] &= 0x3f; secRandBuf16[8] |= 0x80; /* IETF variant */ secRandBuf16[10] |= 0x80; /* multicast bit */ long mostSig = 0; for (int i = 0; i < 8; i++) { mostSig = (mostSig << 8) | (secRandBuf16[i] & 0xff); } long leastSig = 0; for (int i = 8; i < 16; i++) { leastSig = (leastSig << 8) | (secRandBuf16[i] & 0xff); } return (digits(mostSig >> 32, 8) + "-" + digits(mostSig >> 16, 4) + "-" //$NON-NLS-1$//$NON-NLS-2$ + digits(mostSig, 4) + "-" + digits(leastSig >> 48, 4) + "-" + digits( //$NON-NLS-1$//$NON-NLS-2$ leastSig, 12)); } /** Returns val represented by the specified number of hex digits. */ private static String digits(long val, int digits) { long hi = 1L << (digits * 4); return Long.toHexString(hi | (val & (hi - 1))).substring(1);
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/calendar/src/main/java/org/columba/calendar/base/UUIDGenerator.java File path: /columba-1.4-src/core/src/main/java/org/columba/core/base/UUIDGenerator.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class UUIDGenerator {
1
public class UUIDGenerator {
2
	/**
2
	/**
3
	 * random number generator for UUID generation
3
	 * random number generator for UUID generation
4
	 */
4
	 */
5
	private final SecureRandom secRand = new SecureRandom();
5
	private final SecureRandom secRand = new SecureRandom();
6
	/**
6
	/**
7
	 * 128-bit buffer for use with secRand
7
	 * 128-bit buffer for use with secRand
8
	 */
8
	 */
9
	private final byte[] secRandBuf16 = new byte[16];
9
	private final byte[] secRandBuf16 = new byte[16];
10
	public UUIDGenerator() {
10
	public UUIDGenerator() {
11
		super();
11
		super();
12
	}
12
	}
13
	/**
13
	/**
14
	 * @return	uuid as String
14
	 * @return	uuid as String
15
	 */
15
	 */
16
	public String newUUID() {
16
	public String newUUID() {
17
		secRand.nextBytes(secRandBuf16);
17
		secRand.nextBytes(secRandBuf16);
18
		secRandBuf16[6] &= 0x0f;
18
		secRandBuf16[6] &= 0x0f;
19
		secRandBuf16[6] |= 0x40; /* version 4 */
19
		secRandBuf16[6] |= 0x40; /* version 4 */
20
		secRandBuf16[8] &= 0x3f;
20
		secRandBuf16[8] &= 0x3f;
21
		secRandBuf16[8] |= 0x80; /* IETF variant */
21
		secRandBuf16[8] |= 0x80; /* IETF variant */
22
		secRandBuf16[10] |= 0x80; /* multicast bit */
22
		secRandBuf16[10] |= 0x80; /* multicast bit */
23
		long mostSig = 0;
23
		long mostSig = 0;
24
		for (int i = 0; i < 8; i++) {
24
		for (int i = 0; i < 8; i++) {
25
			mostSig = (mostSig << 8) | (secRandBuf16[i] & 0xff);
25
			mostSig = (mostSig << 8) | (secRandBuf16[i] & 0xff);
26
		}
26
		}
27
		long leastSig = 0;
27
		long leastSig = 0;
28
		for (int i = 8; i < 16; i++) {
28
		for (int i = 8; i < 16; i++) {
29
			leastSig = (leastSig << 8) | (secRandBuf16[i] & 0xff);
29
			leastSig = (leastSig << 8) | (secRandBuf16[i] & 0xff);
30
		}
30
		}
31
		return (digits(mostSig >> 32, 8) + "-" + digits(mostSig >> 16, 4) + "-"
31
		return (digits(mostSig >> 32, 8) + "-" + digits(mostSig >> 16, 4) + "-"  //$NON-NLS-1$//$NON-NLS-2$
32
				+ digits(mostSig, 4) + "-" + digits(leastSig >> 48, 4) + "-" + digits(
32
				+ digits(mostSig, 4) + "-" + digits(leastSig >> 48, 4) + "-" + digits(  //$NON-NLS-1$//$NON-NLS-2$
33
				leastSig, 12));
33
				leastSig, 12));
34
	}
34
	}
35
	/** Returns val represented by the specified number of hex digits. */
35
	/** Returns val represented by the specified number of hex digits. */
36
	private static String digits(long val, int digits) {
36
	private static String digits(long val, int digits) {
37
		long hi = 1L << (digits * 4);
37
		long hi = 1L << (digits * 4);
38
		return Long.toHexString(hi | (val & (hi - 1))).substring(1);
38
		return Long.toHexString(hi | (val & (hi - 1))).substring(1);
39
	
39
	
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0