@Test public void testExpandComponent() { assertThat(InterfaceRangeMember.expandComponent("0"), equalTo(ImmutableList.of(0))); assertThat(InterfaceRangeMember.expandComponent("[0-0]"), equalTo(ImmutableList.of(0))); assertThat(InterfaceRangeMember.expandComponent("[0]"), equalTo(ImmutableList.of(0))); assertThat(InterfaceRangeMember.expandComponent("[0-2]"), equalTo(ImmutableList.of(0, 1, 2))); assertThat(InterfaceRangeMember.expandComponent("[0,2,4]"), equalTo(ImmutableList.of(0, 2, 4))); }
static List<Integer> expandComponent(String component) { List<Integer> retList = new LinkedList<>(); if (SOLO_PATTERN.matcher(component).matches()) { retList.add(Integer.parseInt(component)); } else if (RANGE_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] range = strippedComponent.split("-"); int lo = Integer.parseInt(range[0]); int hi = Integer.parseInt(range[1]); for (int i = lo; i <= hi; i++) { retList.add(i); } } else if (LIST_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] list = strippedComponent.split(","); Arrays.stream(list).forEach(i -> retList.add(Integer.parseInt(i))); } else { throw new IllegalArgumentException("Unknown pattern for component " + component); } return retList; }
InterfaceRangeMember implements Serializable { static List<Integer> expandComponent(String component) { List<Integer> retList = new LinkedList<>(); if (SOLO_PATTERN.matcher(component).matches()) { retList.add(Integer.parseInt(component)); } else if (RANGE_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] range = strippedComponent.split("-"); int lo = Integer.parseInt(range[0]); int hi = Integer.parseInt(range[1]); for (int i = lo; i <= hi; i++) { retList.add(i); } } else if (LIST_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] list = strippedComponent.split(","); Arrays.stream(list).forEach(i -> retList.add(Integer.parseInt(i))); } else { throw new IllegalArgumentException("Unknown pattern for component " + component); } return retList; } }
InterfaceRangeMember implements Serializable { static List<Integer> expandComponent(String component) { List<Integer> retList = new LinkedList<>(); if (SOLO_PATTERN.matcher(component).matches()) { retList.add(Integer.parseInt(component)); } else if (RANGE_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] range = strippedComponent.split("-"); int lo = Integer.parseInt(range[0]); int hi = Integer.parseInt(range[1]); for (int i = lo; i <= hi; i++) { retList.add(i); } } else if (LIST_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] list = strippedComponent.split(","); Arrays.stream(list).forEach(i -> retList.add(Integer.parseInt(i))); } else { throw new IllegalArgumentException("Unknown pattern for component " + component); } return retList; } InterfaceRangeMember(String memberId); }
InterfaceRangeMember implements Serializable { static List<Integer> expandComponent(String component) { List<Integer> retList = new LinkedList<>(); if (SOLO_PATTERN.matcher(component).matches()) { retList.add(Integer.parseInt(component)); } else if (RANGE_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] range = strippedComponent.split("-"); int lo = Integer.parseInt(range[0]); int hi = Integer.parseInt(range[1]); for (int i = lo; i <= hi; i++) { retList.add(i); } } else if (LIST_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] list = strippedComponent.split(","); Arrays.stream(list).forEach(i -> retList.add(Integer.parseInt(i))); } else { throw new IllegalArgumentException("Unknown pattern for component " + component); } return retList; } InterfaceRangeMember(String memberId); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
InterfaceRangeMember implements Serializable { static List<Integer> expandComponent(String component) { List<Integer> retList = new LinkedList<>(); if (SOLO_PATTERN.matcher(component).matches()) { retList.add(Integer.parseInt(component)); } else if (RANGE_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] range = strippedComponent.split("-"); int lo = Integer.parseInt(range[0]); int hi = Integer.parseInt(range[1]); for (int i = lo; i <= hi; i++) { retList.add(i); } } else if (LIST_PATTERN.matcher(component).matches()) { String strippedComponent = component.replaceAll("\\[|]", ""); String[] list = strippedComponent.split(","); Arrays.stream(list).forEach(i -> retList.add(Integer.parseInt(i))); } else { throw new IllegalArgumentException("Unknown pattern for component " + component); } return retList; } InterfaceRangeMember(String memberId); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }