@Override public Object getDestination() { loadIdentifiers(); return edge.getDestination(); }
/** * Note this does not include the matchedVertex field. * * @return a hash code value for this edge. */ @Override public int hashCode() { return new HashCodeBuilder(21, 3) .appendSuper(super.hashCode()) .append(getSource()) .append(getDestination()) .append(isDirected()) .toHashCode(); }
/** * Note this does not include the matchedVertex field. * * @param edge the reference Edge with which to compare. * @return {@code true} if this object is the same as the edge * argument; {@code false} otherwise. */ public boolean equals(final Edge edge) { return null != edge && new EqualsBuilder() .append(isDirected(), edge.isDirected()) .append(getSource(), edge.getSource()) .append(getDestination(), edge.getDestination()) .appendSuper(super.equals(edge)) .isEquals(); }
@Override public String toString() { return new ToStringBuilder(this) .append("source", getSource()) .append("destination", getDestination()) .append("directed", isDirected()) .append("matchedVertex", getMatchedVertex()) .appendSuper(super.toString()) .build(); }
return false; if (!((Edge) element).getDestination().equals(((Edge) element2).getDestination())) { return false;
@Override public Object getIdentifier(final IdentifierType identifierType) { switch (identifierType) { case GROUP: return getGroup(); case SOURCE: return getSource(); case DESTINATION: return getDestination(); case DIRECTED: return isDirected(); case MATCHED_VERTEX: return getMatchedVertexValue(); case ADJACENT_MATCHED_VERTEX: return getAdjacentMatchedVertexValue(); default: return null; } }
@Override public Edge emptyClone() { return new Edge( getGroup(), getSource(), getDestination(), isDirected(), getMatchedVertex(), new Properties() ); }
@Test public void shouldSwapVerticesIfSourceIsGreaterThanDestination_comparable() { // Given final Edge edge = new Edge.Builder().group(TestGroups.EDGE) .directed(false) .source(new Integer(2)) .dest(new Integer(1)) .build(); // Then assertThat(edge.getSource(), equalTo(new Integer(1))); assertThat(edge.getDestination(), equalTo(new Integer(2))); }
@Test public void shouldNotSwapVerticesIfSourceIsLessThanDestination_comparable() { // Given final Edge edge = new Edge.Builder().group(TestGroups.EDGE) .directed(false) .source(new Integer(1)) .dest(new Integer(2)) .build(); // Then assertThat(edge.getSource(), equalTo(new Integer(1))); assertThat(edge.getDestination(), equalTo(new Integer(2))); }
@Test public void shouldLoadIdentifierWhenNotLoaded() { // Given final Edge edge = mock(Edge.class); given(edge.getProperties()).willReturn(mock(Properties.class)); final ElementValueLoader edgeLoader = mock(ElementValueLoader.class); final LazyEdge lazyEdge = new LazyEdge(edge, edgeLoader); final IdentifierType identifierType = IdentifierType.DESTINATION; final String exceptedIdentifierValue = "identifier value"; given(edge.getDestination()).willReturn(exceptedIdentifierValue); // When Object identifierValue = lazyEdge.getIdentifier(identifierType); // Then assertEquals(exceptedIdentifierValue, identifierValue); assertEquals(identifierValue, edge.getDestination()); verify(edgeLoader).loadIdentifiers(edge); }
@Test public void shouldNotSwapVerticesIfSourceIsLessThanDestination_toString() { // Given final Edge edge = new Edge.Builder().group(TestGroups.EDGE) .directed(false) .source(new Vertex("1")) .dest(new Vertex("2")) .build(); // Then assertThat(edge.getSource(), equalTo(new Vertex("1"))); assertThat(edge.getDestination(), equalTo(new Vertex("2"))); }
@Test public void shouldSwapVerticesIfSourceIsGreaterThanDestination_toString() { // Given final Edge edge = new Edge.Builder().group(TestGroups.EDGE) .directed(false) .source(new Vertex("2")) .dest(new Vertex("1")) .build(); // Then assertThat(edge.getSource(), equalTo(new Vertex("1"))); assertThat(edge.getDestination(), equalTo(new Vertex("2"))); }
private Edge cloneCoreFields(final Edge edge) { return new Edge.Builder() .group(edge.getGroup()) .source(edge.getSource()) .dest(edge.getDestination()) .directed(edge.isDirected()) .build(); }
@Override @Test public void shouldSetAndGetFields() { // Given final Edge edge = new Edge.Builder() .group("group") .source("source vertex") .dest("destination vertex") .directed(true) .build(); // When/Then assertEquals("group", edge.getGroup()); assertEquals("source vertex", edge.getSource()); assertEquals("destination vertex", edge.getDestination()); assertTrue(edge.isDirected()); }
@Test public void shouldBuildEdge() { // Given final String source = "source vertex"; final String destination = "dest vertex"; final boolean directed = true; final String propValue = "propValue"; // When final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .source(source) .dest(destination) .directed(directed) .property(TestPropertyNames.STRING, propValue) .build(); // Then assertEquals(TestGroups.EDGE, edge.getGroup()); assertEquals(source, edge.getSource()); assertEquals(destination, edge.getDestination()); assertTrue(edge.isDirected()); assertEquals(propValue, edge.getProperty(TestPropertyNames.STRING)); }
@Test public void shouldConstructEdge() { // Given final String source = "source vertex"; final String destination = "dest vertex"; final boolean directed = true; final String propValue = "propValue"; // When final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .source(source) .dest(destination) .directed(directed) .build(); edge.putProperty(TestPropertyNames.STRING, propValue); // Then assertEquals(TestGroups.EDGE, edge.getGroup()); assertEquals(source, edge.getSource()); assertEquals(destination, edge.getDestination()); assertTrue(edge.isDirected()); assertEquals(propValue, edge.getProperty(TestPropertyNames.STRING)); }
@Override @Test public void shouldReturnFalseForEqualsWhenGroupIsDifferent() { // Given final Edge edge1 = new Edge.Builder() .group("group") .source("source vertex") .dest("dest vertex") .directed(true) .build(); final Edge edge2 = new Edge.Builder() .group("a different group") .source(edge1.getSource()) .dest(edge1.getDestination()) .directed(edge1.isDirected()) .build(); // When boolean isEqual = edge1.equals((Object) edge2); // Then assertFalse(isEqual); assertFalse(edge1.hashCode() == edge2.hashCode()); }
@Test public void shouldReturnFalseForEqualsWhenSourceIsDifferent() { // Given final Edge edge1 = new Edge.Builder() .group("group") .source("source vertex") .dest("dest vertex") .directed(true) .build(); final Edge edge2 = new Edge.Builder() .group(edge1.getGroup()) .source("different source") .dest(edge1.getDestination()) .directed(edge1.isDirected()) .build(); // When boolean isEqual = edge1.equals((Object) edge2); // Then assertFalse(isEqual); assertFalse(edge1.hashCode() == edge2.hashCode()); }
@Test public void shouldReturnFalseForEqualsWhenDirectedIsDifferent() { // Given final Edge edge1 = new Edge.Builder() .group("group") .source("source vertex") .dest("dest vertex") .directed(true) .build(); final Edge edge2 = new Edge.Builder() .group(edge1.getGroup()) .source(edge1.getSource()) .dest(edge1.getDestination()) .directed(!edge1.isDirected()) .build(); // When boolean isEqual = edge1.equals((Object) edge2); // Then assertFalse(isEqual); assertFalse(edge1.hashCode() == edge2.hashCode()); }
assertEquals("destination vertex", edge.getDestination()); assertEquals(true, tuple.get(IdentifierType.DIRECTED.name())); assertEquals(1, tuple.get(TestPropertyNames.COUNT));