CompoundLabel { public final static String[] labelComponents(String label) { String[] parts = new String[3]; parts[0] = ""; parts[1] = ""; parts[2] = ""; if(isValidCompound(label) && label.length() > 1) { String[] splitted = label.split(SEPARATOR); parts[0] = splitted[0]; if(splitted.length > 1) { if(!splitted[1].isEmpty() && (splitted[1].equalsIgnoreCase(Constants.TCP.replaceAll("_", "")) || splitted[1].equalsIgnoreCase(Constants.UDP.replaceAll("_", "")))) { parts[2] = splitted[1].toLowerCase(); return parts; } else parts[1] = splitted[1]; } if(splitted.length > 2) parts[2] = splitted[2].toLowerCase(); return parts; } else throw new IllegalArgumentException("malformed 'Compound Label' supposed to be '<label[<:sublabel:proto>|<:proto>]>'"); } CompoundLabel(String type);  CompoundLabel(String type, String subType);  CompoundLabel(String type, String subType, String proto); final static boolean isCompound(String label); final static boolean isValidCompound(String label); final static String[] labelComponents(String label); CompoundLabel buildByLabel(String label); String getType(); String getSubType(); String getProto(); boolean hasSubType(); boolean hasProtocol(); String prefixString(); String prefixString(String protocol); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testlabelComponents() { String label = "coap"; String[] test = null; try { test = CompoundLabel.labelComponents(label); Assert.fail("Expected an exception for: " +":"); } catch(Exception e) { } label = "coap:TCP"; try { test = CompoundLabel.labelComponents(label); Assert.assertEquals("coap", test[0]); Assert.assertEquals("tcp", test[2]); Assert.assertEquals("", test[1]); } catch(Exception e) { Assert.fail("Expected a parsing of: " +label); } label = "coap:subcoap:UDP"; try { test = CompoundLabel.labelComponents(label); Assert.assertEquals("coap", test[0]); Assert.assertEquals("udp", test[2]); Assert.assertEquals("subcoap", test[1]); } catch(Exception e) { Assert.fail("Expected a parsing of: " +label); } label = ":"; try { test = CompoundLabel.labelComponents(label); Assert.fail("Expected a parsing error for: '" +label +"'"); } catch(Exception e) { } label = "a:"; try { test = CompoundLabel.labelComponents(label); Assert.fail("Expected a parsing error for: '" +label +"'"); } catch(Exception e) { } label = ":a:"; try { test = CompoundLabel.labelComponents(label); Assert.fail("Expected a parsing error for: '" +label +"'"); } catch(Exception e) { } label = ":a"; try { test = CompoundLabel.labelComponents(label); Assert.fail("Expected a parsing error for: '" +label +"'"); } catch(Exception e) { } label = ":printer:udp"; try { test = CompoundLabel.labelComponents(label); Assert.fail("Expected a parsing error for: '" +label +"'"); } catch(Exception e) { } }