public static LocationSpecifier from(@Nonnull NodesSpecifier ingressNodes) { switch (ingressNodes.getType()) { case NAME: return new NodeNameRegexInterfaceLocationSpecifier(ingressNodes.getRegex()); case ROLE: return new NodeRoleRegexInterfaceLocationSpecifier( ingressNodes.getRoleDimension(), ingressNodes.getRegex()); default: throw new BatfishException("Unexpected NodesSpecifier type: " + ingressNodes.getType()); } } }
public static NodeSpecifier from(@Nullable NodesSpecifier nodesSpecifier) { if (nodesSpecifier == null) { return null; } switch (nodesSpecifier.getType()) { case NAME: return new NameRegexNodeSpecifier(nodesSpecifier.getRegex()); case ROLE: return new RoleRegexNodeSpecifier( nodesSpecifier.getRegex(), nodesSpecifier.getRoleDimension()); default: throw new BatfishException("Unexpected NodesSpecifier type: " + nodesSpecifier.getType()); } } }
.filter(nodesSpecifier.getRegex().asPredicate()) .forEach( node -> {
@Test public void constructorExplicitName() { NodesSpecifier specifier = new NodesSpecifier("name:lhr-.*"); assertThat(specifier.getType(), equalTo(Type.NAME)); assertThat( specifier.getRegex().pattern(), equalTo(Pattern.compile("lhr-.*", Pattern.CASE_INSENSITIVE).pattern())); }
@Test public void constructorImplicitName() { NodesSpecifier specifier = new NodesSpecifier("lhr-.*"); assertThat(specifier.getType(), equalTo(Type.NAME)); assertThat( specifier.getRegex().pattern(), equalTo(Pattern.compile("lhr-.*", Pattern.CASE_INSENSITIVE).pattern())); }
@Test public void constructorRole() { NodesSpecifier specifier = new NodesSpecifier("role:dim:svr.*"); assertThat(specifier.getType(), equalTo(Type.ROLE)); assertThat(specifier.getRoleDimension(), equalTo("dim")); assertThat( specifier.getRegex().pattern(), equalTo(Pattern.compile("svr.*", Pattern.CASE_INSENSITIVE).pattern())); }