Object index = node.getIndex(); if (index == null) { index = node.getKey();
Object index = node.getIndex(); if (index == null) { index = node.getKey();
@Test @SpecAssertions({ @SpecAssertion(section = "4.2", id = "f"), @SpecAssertion(section = "4.2", id = "j"), @SpecAssertion(section = "4.2", id = "k") }) public void testPropertyPathWithMap() { Validator validator = TestUtil.getValidatorUnderTest(); ActorDB db = new ActorDB(); Actor morgan = new ActorArrayBased( "Morgan", null ); Integer id = db.addActor( morgan ); Set<ConstraintViolation<ActorDB>> constraintViolations = validator.validate( db ); assertCorrectNumberOfViolations( constraintViolations, 1 ); ConstraintViolation<ActorDB> constraintViolation = constraintViolations.iterator().next(); Iterator<Path.Node> nodeIter = constraintViolation.getPropertyPath().iterator(); assertTrue( nodeIter.hasNext() ); Path.Node node = nodeIter.next(); assertEquals( node.getName(), "actors" ); assertFalse( node.isInIterable() ); node = nodeIter.next(); assertEquals( node.getName(), "lastName" ); assertTrue( node.isInIterable() ); assertEquals( node.getKey(), id ); assertFalse( nodeIter.hasNext() ); }
/** * Append a Node to the specified StringBuilder. * @param node * @param to * @return to */ public static StringBuilder appendNode(Node node, StringBuilder to) { if (node.isInIterable()) { to.append(INDEX_OPEN); if (node.getIndex() != null) { to.append(node.getIndex()); } else if (node.getKey() != null) { to.append(node.getKey()); } to.append(INDEX_CLOSE); } if (node.getName() != null) { if (to.length() > 0) { to.append(PathImpl.PROPERTY_PATH_SEPARATOR); } to.append(node.getName()); } return to; }
private static int compareIterability(Node quid, Node quo, boolean strict) { if (quid.isInIterable()) { if (quo.isInIterable()) { if (quid.getKey() != null) { return Comparator.comparing(Node::getKey, KEY_COMPARATOR).compare(quid, quo); } if (quo.getKey() != null) { return -1; } if (quid.getIndex() == null) { if (strict) { // this method cannot consistently order iterables without key or index; the first argument is // always assumed to be less: return -1; } return quo.getIndex() == null ? 0 : -1; } return quo.getIndex() == null ? 1 : quid.getIndex().compareTo(quo.getIndex()); } return 1; } return quo.isInIterable() ? -1 : 0; }
/** * Append a Node to the specified StringBuilder. * * @param node * @param to * @return to */ public static StringBuilder appendNode(Node node, StringBuilder to) { if (node.isInIterable()) { to.append(INDEX_OPEN); if (node.getIndex() != null) { to.append(node.getIndex()); } else if (node.getKey() != null) { to.append(node.getKey()); } to.append(INDEX_CLOSE); } if (node.getName() != null) { if (to.length() > 0) { to.append(PathImpl.PROPERTY_PATH_SEPARATOR); } to.append(node.getName()); } return to; }
private PathExpectation(Path propertyPath) { for ( Path.Node node : propertyPath ) { Integer parameterIndex = null; if ( node.getKind() == ElementKind.PARAMETER ) { parameterIndex = node.as( Path.ParameterNode.class ).getParameterIndex(); } Class<?> containerClass = getContainerClass( node ); Integer typeArgumentIndex = getTypeArgumentIndex( node ); nodes.add( new NodeExpectation( node.getName(), node.getKind(), node.isInIterable(), node.getKey(), node.getIndex(), parameterIndex, containerClass, typeArgumentIndex ) ); } }
/** * Append a Node to the specified StringBuilder. * * @param node * @param to * @return to */ public static StringBuilder appendNode(Node node, StringBuilder to) { if (node.isInIterable()) { to.append(INDEX_OPEN); if (node.getIndex() != null) { to.append(node.getIndex()); } else if (node.getKey() != null) { to.append(node.getKey()); } to.append(INDEX_CLOSE); } if (node.getName() != null) { if (to.length() > 0) { to.append(PathImpl.PROPERTY_PATH_SEPARATOR); } to.append(node.getName()); } return to; }
private PathExpectation(Path propertyPath) { for ( Path.Node node : propertyPath ) { Integer parameterIndex = null; if ( node.getKind() == ElementKind.PARAMETER ) { parameterIndex = node.as( Path.ParameterNode.class ).getParameterIndex(); } Class<?> containerClass = getContainerClass( node ); Integer typeArgumentIndex = getTypeArgumentIndex( node ); nodes.add( new NodeExpectation( node.getName(), node.getKind(), node.isInIterable(), node.getKey(), node.getIndex(), parameterIndex, containerClass, typeArgumentIndex ) ); } }
private static int compareIterability(Node quid, Node quo, boolean strict) { if (quid.isInIterable()) { if (quo.isInIterable()) { if (quid.getKey() != null) { return Comparator.comparing(Node::getKey, KEY_COMPARATOR).compare(quid, quo); } if (quo.getKey() != null) { return -1; } if (quid.getIndex() == null) { if (strict) { // this method cannot consistently order iterables without key or index; the first argument is // always assumed to be less: return -1; } return quo.getIndex() == null ? 0 : -1; } return quo.getIndex() == null ? 1 : quid.getIndex().compareTo(quo.getIndex()); } return 1; } return quo.isInIterable() ? -1 : 0; }
/** * Create a new NodeImpl instance. * * @param node */ NodeImpl(Path.Node node) { this(node.getName()); this.inIterable = node.isInIterable(); this.index = node.getIndex(); this.key = node.getKey(); if (node instanceof NodeImpl) { final NodeImpl n = (NodeImpl) node; this.parameterIndex = n.parameterIndex; this.parameterTypes = n.parameterTypes; this.containerType = n.containerType; this.typeArgumentIndex = n.typeArgumentIndex; } }
private PathExpectation(Path propertyPath) { for ( Path.Node node : propertyPath ) { Integer parameterIndex = null; if ( node.getKind() == ElementKind.PARAMETER ) { parameterIndex = node.as( Path.ParameterNode.class ).getParameterIndex(); } nodes.add( new NodeExpectation( node.getName(), node.getKind(), node.isInIterable(), node.getKey(), node.getIndex(), parameterIndex ) ); } }
/** * Create a new NodeImpl instance. * * @param node */ NodeImpl(Path.Node node) { this(node.getName()); this.inIterable = node.isInIterable(); this.index = node.getIndex(); this.key = node.getKey(); if (node instanceof NodeImpl) { final NodeImpl n = (NodeImpl) node; this.parameterIndex = n.parameterIndex; this.parameterTypes = n.parameterTypes; this.containerType = n.containerType; this.typeArgumentIndex = n.typeArgumentIndex; } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); Iterator<Node> it = this.iterator(); int index = 0; while(it.hasNext()) { Node node = it.next(); if(index != 0 && node.getKey() == null && node.getIndex() == null) { builder.append("."); } builder.append(node.toString()); index++; } return builder.toString(); }
/** * Create a new NodeImpl instance. * @param node */ NodeImpl(Path.Node node) { this.name = node.getName(); this.inIterable = node.isInIterable(); this.index = node.getIndex(); this.key = node.getKey(); }
private void assertNode(Path.Node actualNode, String expectedName, ElementKind expectedKind, boolean expectedInIterable, Integer expectedIndex, Object expectedKey) { assertEquals( actualNode.getName(), expectedName ); assertEquals( actualNode.getKind(), expectedKind ); assertEquals( actualNode.isInIterable(), expectedInIterable ); assertEquals( actualNode.getIndex(), expectedIndex ); assertEquals( actualNode.getKey(), expectedKey ); }
private PathExpectation(Path propertyPath) { for ( Path.Node node : propertyPath ) { Integer parameterIndex = null; if ( node.getKind() == ElementKind.PARAMETER ) { parameterIndex = node.as( Path.ParameterNode.class ).getParameterIndex(); } Class<?> containerClass = getContainerClass( node ); Integer typeArgumentIndex = getTypeArgumentIndex( node ); nodes.add( new NodeExpectation( node.getName(), node.getKind(), node.isInIterable(), node.getKey(), node.getIndex(), parameterIndex, containerClass, typeArgumentIndex ) ); } }