@Test void throwsExceptionEncoding() { assertThrows(InvalidEntityException.class, () -> { EntityIdEndec.encode(1L << SHARD_BITS, 0, 0); }); assertThrows(InvalidEntityException.class, () -> { EntityIdEndec.encode(0, 1L << REALM_BITS, 0); }); assertThrows(InvalidEntityException.class, () -> { EntityIdEndec.encode(0, 0, 1L << NUM_BITS); }); assertThrows(InvalidEntityException.class, () -> { EntityIdEndec.encode(-1, 0, 0); }); assertThrows(InvalidEntityException.class, () -> { EntityIdEndec.encode(0, -1, 0); }); assertThrows(InvalidEntityException.class, () -> { EntityIdEndec.encode(0, 0, -1); }); }
public static Long encode(long shardNum, long realmNum, long entityNum) { if (shardNum > SHARD_MASK || shardNum < 0 || realmNum > REALM_MASK || realmNum < 0 || entityNum > NUM_MASK || entityNum < 0) { throw new InvalidEntityException("Entity outside encoding range: " + shardNum + "." + realmNum + "." + entityNum); } return (entityNum & NUM_MASK) | (realmNum & REALM_MASK) << NUM_BITS | (shardNum & SHARD_MASK) << (REALM_BITS + NUM_BITS); }
EntityIdEndec { public static Long encode(long shardNum, long realmNum, long entityNum) { if (shardNum > SHARD_MASK || shardNum < 0 || realmNum > REALM_MASK || realmNum < 0 || entityNum > NUM_MASK || entityNum < 0) { throw new InvalidEntityException("Entity outside encoding range: " + shardNum + "." + realmNum + "." + entityNum); } return (entityNum & NUM_MASK) | (realmNum & REALM_MASK) << NUM_BITS | (shardNum & SHARD_MASK) << (REALM_BITS + NUM_BITS); } }
EntityIdEndec { public static Long encode(long shardNum, long realmNum, long entityNum) { if (shardNum > SHARD_MASK || shardNum < 0 || realmNum > REALM_MASK || realmNum < 0 || entityNum > NUM_MASK || entityNum < 0) { throw new InvalidEntityException("Entity outside encoding range: " + shardNum + "." + realmNum + "." + entityNum); } return (entityNum & NUM_MASK) | (realmNum & REALM_MASK) << NUM_BITS | (shardNum & SHARD_MASK) << (REALM_BITS + NUM_BITS); }  }
EntityIdEndec { public static Long encode(long shardNum, long realmNum, long entityNum) { if (shardNum > SHARD_MASK || shardNum < 0 || realmNum > REALM_MASK || realmNum < 0 || entityNum > NUM_MASK || entityNum < 0) { throw new InvalidEntityException("Entity outside encoding range: " + shardNum + "." + realmNum + "." + entityNum); } return (entityNum & NUM_MASK) | (realmNum & REALM_MASK) << NUM_BITS | (shardNum & SHARD_MASK) << (REALM_BITS + NUM_BITS); }  static Long encode(long shardNum, long realmNum, long entityNum); static EntityId decode(long encodedId, EntityTypeEnum entityTypeEnum); }
EntityIdEndec { public static Long encode(long shardNum, long realmNum, long entityNum) { if (shardNum > SHARD_MASK || shardNum < 0 || realmNum > REALM_MASK || realmNum < 0 || entityNum > NUM_MASK || entityNum < 0) { throw new InvalidEntityException("Entity outside encoding range: " + shardNum + "." + realmNum + "." + entityNum); } return (entityNum & NUM_MASK) | (realmNum & REALM_MASK) << NUM_BITS | (shardNum & SHARD_MASK) << (REALM_BITS + NUM_BITS); }  static Long encode(long shardNum, long realmNum, long entityNum); static EntityId decode(long encodedId, EntityTypeEnum entityTypeEnum);  }