package com.example.testapp;

import java.net.InetAddress;

/** All public data members, similar to a C-struct */
public class ClientDevice {
	public int id;
	public long hash;
	public String name;
	public InetAddress ip;
	public int port;

	ClientDevice(String desc) {
		id = 0;
		port = 0;

		// desc format: <name> (hash in 64-bit hex) connected
		String delims = "[ ]+";
		String tokens[] = desc.split(delims);

		name = tokens[0];
		String hashString = tokens[1].substring(1, tokens[1].length() - 1);
		hash = Long.parseLong(hashString, 16);
	}

	@Override
	public boolean equals(Object other) {
		if (other instanceof ClientDevice)
			return ((ClientDevice) other).hash == this.hash;
		else
			return false;
	}

	@Override
	public int hashCode() {
		return (int) (hash & 0xffffffff);
	}
}

@@ -234,16 +234,205 @@
  port;%0A%0A
+%09long unsignedParseLongHex(String s) %7B%0A%09%09long l = 0;%0A%09%09long hi = Long.parseLong(s.substring(0, 8), 16), lo = Long.parseLong(%0A%09%09%09%09s.substring(8), 16);%0A%09%09l = (hi %3C%3C 32) %7C lo;%0A%09%09return l;%0A%09%7D%0A%0A
 %09ClientD
@@ -452,16 +452,16 @@
 desc) %7B%0A
-
 %09%09id = 0
@@ -692,31 +692,231 @@
 1);%0A
+%0A
 %09%09
-hash = Long.p
+// Long.parseLong **sucks**. It is expecting a positive number, so it%0A%09%09// doesn't work if the first character on a 16-hex is 8-f%0A%09%09// I'm doing the split into two 32-bit longs and bitwise xor.%0A%09%09hash = unsignedP
 arseLong
 (has
@@ -911,16 +911,19 @@
 arseLong
+Hex
 (hashStr
@@ -925,20 +925,16 @@
 shString
-, 16
 );%0A%09%7D%0A%0A%09

Fix 16-bit unsigned hex parsing Exception with custom unsigned hex parser.