NodeLabelUtil { public static void checkAndThrowAttributeValue(String value) throws IOException { if (value == null) { return; } else if (value.trim().length() > MAX_LABEL_LENGTH) { throw new IOException("Attribute value added exceeds " + MAX_LABEL_LENGTH + " character(s)"); } value = value.trim(); if(value.isEmpty()) { return; } boolean match = ATTRIBUTE_VALUE_PATTERN.matcher(value).matches(); if (!match) { throw new IOException("attribute value should only contains " + "{0-9, a-z, A-Z, -, _} and should not started with {-,_}" + ", now it is= " + value); } } private  NodeLabelUtil(); static void checkAndThrowLabelName(String label); static void checkAndThrowAttributeValue(String value); static void checkAndThrowAttributePrefix(String prefix); static void validateNodeAttributes(Set<NodeAttribute> attributeSet); static Set<NodeAttribute> filterAttributesByPrefix(
      Set<NodeAttribute> attributeSet, String prefix);  }
@Test public void testAttributeValueAddition() { String[] values = new String[]{"1_8", "1.8", "ABZ", "ABZ", "az", "a-z", "a_z", "123456789"}; for (String val : values) { try { NodeLabelUtil.checkAndThrowAttributeValue(val); } catch (Exception e) { fail("Valid values for NodeAttributeValue :" + val); } } String[] invalidVals = new String[]{"_18", "1,8", "1/5", ".15", "1\\5"}; for (String val : invalidVals) { try { NodeLabelUtil.checkAndThrowAttributeValue(val); fail("Valid values for NodeAttributeValue :" + val); } catch (Exception e) { } } }