@Override public PetContract.Race reverseMap(Race output) { switch (output) { case CAT: return PetContract.Race.CAT; case DOG: return PetContract.Race.DOG; case PIG: return PetContract.Race.GUINEA_PIG; default: throw new EidIllegalArgumentException(new Eid("20161221:191805")); } }
@Override public Race map(PetContract.Race input) { switch (input) { case CAT: return Race.CAT; case DOG: return Race.DOG; case GUINEA_PIG: return Race.PIG; default: throw new EidIllegalArgumentException(new Eid("20161221:183136")); } }
private EntityReference unpack(CharSequence repr) { try { Cipher cipher = getDecrypt(); byte[] input = decode(repr); String output = new String(cipher.doFinal(input), UTF_8); int idx = output.indexOf(REPR_SPLITTER); String serializedId = output.substring(0, idx); String type = output.substring(idx + REPR_SPLITTER.length()); String fqcn = getFqcnForType(type); return new EntityReferenceImpl( classLocator.locateClassByName(fqcn), serializer.unserialize(serializedId) ); } catch (GeneralSecurityException | ClassNotFoundException | NumberFormatException | IOException ex) { throw new EidIllegalArgumentException("20180509:134806", ex); } }
private CharSequence pack(Serializable type, @Nullable Serializable id) { if (id == null) { return EMPTY_STRING; } String classNameRepr = getClassNameRepr(type); try { String repr = repr(id, classNameRepr); byte[] input = repr.getBytes(UTF_8); Cipher cipher = getEncrypt(); byte[] output; output = cipher.doFinal(input); return encode(output); } catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | IllegalArgumentException ex) { throw new EidIllegalArgumentException("20140131:003856", ex); } }