TaskIds implements TaskId, Serializable { static TaskId parse(String stringId) { final int pOpen = stringId.indexOf('('); final int pClose = stringId.lastIndexOf(')'); final int pHash = stringId.lastIndexOf('#'); if (pOpen < 0 || pClose < pOpen || pHash < pClose) { throw new IllegalArgumentException("Invalid stringId, follow 'Name(foo,bar)#deadbeef'"); } final String name = stringId.substring(0, pOpen); if (name.contains(")")) { throw new IllegalArgumentException("Name can not contain any parenthesis"); } final String args = stringId.substring(pOpen + 1, pClose); final String hash = stringId.substring(pHash + 1); return new AutoValue_TaskIds( name, Integer.parseUnsignedInt(hash, 16), args); }  abstract String args(); @Override String toString();  }
@Test public void shouldParseBigHash() throws Exception { TaskId taskId = TaskId.parse("FooBar(a,1)#8adaddda"); assertThat(taskId.hash(), equalTo(-1965367846)); }
@Test(expected = NumberFormatException.class) public void shouldNotParseInvalidIdHash() throws Exception { TaskId.parse("Wat(123)#hello"); }
@Test(expected = IllegalArgumentException.class) public void shouldNotParseInvalidName() throws Exception { TaskId.parse("Wat)#(123)#beef"); }
@Test(expected = IllegalArgumentException.class) public void shouldNotParseInvalidParens() throws Exception { TaskId.parse("Wat)foo(#beef"); }
@Test(expected = IllegalArgumentException.class) public void shouldNotParseInvalidParensNoOpen() throws Exception { TaskId.parse("Wat)foo#beef"); }
@Test(expected = IllegalArgumentException.class) public void shouldNotParseInvalidHashPlacement() throws Exception { TaskId.parse("Wat(#)beef"); }