Skip to content

Instantly share code, notes, and snippets.

@chalos
Created December 14, 2016 09:26
Show Gist options
  • Save chalos/665b93589be6c09315589c8777958fcd to your computer and use it in GitHub Desktop.
Save chalos/665b93589be6c09315589c8777958fcd to your computer and use it in GitHub Desktop.
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
public class TestObject {
int g;
String h;
int[] i;
String[] j;
public TestObject() {
this.g = 0;
this.h = "init";
this.i = new int[]{0, 1, 2, 3};
this.j = new String[] {"init", "init", "init", "init"};
}
public long hashClass() {
StringBuilder sb = new StringBuilder( String.valueOf(this.g));
sb.append(this.h);
for(int _i: this.i) sb.append(_i);
for(String _j: this.j) sb.append(_j);
try {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(sb.toString().getBytes());
byte[] results = md.digest();
ByteBuffer bb = ByteBuffer.wrap(results, 0, 8);
return bb.getLong();
} catch(Exception e) {
return -5566;
}
}
public void randomGenerate() {
this.g = (int)(Math.random() * 1000);
this.h = String.valueOf(Math.random());
for(int idx = 0; idx < this.i.length; idx++)
this.i[idx] = (int)(Math.random() * 1000);
for(int idx = 0; idx < this.j.length; idx++)
this.j[idx] = String.valueOf(Math.random());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment