Skip to content

Instantly share code, notes, and snippets.

@firexel
Created June 5, 2012 18:11
Show Gist options
  • Save firexel/2876639 to your computer and use it in GitHub Desktop.
Save firexel/2876639 to your computer and use it in GitHub Desktop.
Простота vs прозрачность
class UselessDTO
{
public byte val1;
public int val2, val3;
}
public UselessDTO readFromByteArray(@NotNull byte[] array)
{
if (array.length < 9) throw new IllegalArgumentException("Need 9 bytes to read");
UselessDTO dto = new UselessDTO();
dto.val1 = array[0];
dto.val2 = (array[1] << 24) | (array[2] << 16) | (array[3] << 8) | array[4];
dto.val3 = (array[5] << 24) | (array[6] << 16) | (array[7] << 8) | array[8];
return dto;
}
public UselessDTO readFromByteDataSource(@NotNull ByteBufferDataSource source)
{
UselessDTO dto = new UselessDTO();
dto.val1 = source.readByte();
dto.val2 = source.readInt();
dto.val3 = source.readInt();
return dto;
}
public UselessDTO readFromAbstractSource(@NotNull DataSource source)
{
UselessDTO dto = new UselessDTO();
dto.val1 = source.readByte();
dto.val2 = source.readInt();
dto.val3 = source.readInt();
return dto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment