Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jena-arq/src/main/java/org/apache/jena/system/G.java
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,11 @@ public static void copyGraphSrcToDst(Graph src, Graph dst) {
* @param src the graph to copy
* @return a copy of the graph
*/
@SuppressWarnings("unchecked")
public static Graph copy(Graph src) {
if(src instanceof Copyable<?>) {
return ((Copyable<Graph>)src).copy();
if(src instanceof Copyable<?> copyable) {
Copyable<Graph> copyableGraph = (Copyable<Graph>)copyable;
return copyableGraph.copy();
}
Graph dst = GraphMemFactory.createDefaultGraph();
copyGraphSrcToDst(src, dst);
Expand Down
5 changes: 2 additions & 3 deletions jena-arq/src/test/java/org/apache/jena/system/GTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.apache.jena.testing_framework.GraphHelper.triple;
import static org.junit.Assert.*;

@SuppressWarnings("deprecation")
public class GTest {

@Test
Expand All @@ -34,8 +35,6 @@ public void copy() {
{
var graphImplementingCopyable = new GraphMem2Fast();

assertTrue(graphImplementingCopyable instanceof Copyable<?>);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graphImplementingCopyable is already a Copyable and can't be null.


graphImplementingCopyable.add(triple("s1 p1 o1"));
graphImplementingCopyable.add(triple("s1 p2 o1"));
graphImplementingCopyable.add(triple("s2 p1 o1"));
Expand All @@ -56,7 +55,7 @@ public void copy() {

// Test graph which does not implement Copyable<>
{
var notCopyableGraph = new GraphMem();
GraphMem notCopyableGraph = new GraphMem();

assertFalse(notCopyableGraph instanceof Copyable<?>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface Copyable<T> {

/**
* Create a copy of this object.
* @return
* @return T
*/
T copy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected FastHashBase() {
*
* @param baseToCopy
*/
protected <T extends FastHashBase> FastHashBase(final T baseToCopy) {
protected <T extends FastHashBase<?>> FastHashBase(final T baseToCopy) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic, not bare class, keeps Eclipse happy.

this.positions = new int[baseToCopy.positions.length];
System.arraycopy(baseToCopy.positions, 0, this.positions, 0, baseToCopy.positions.length);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ public interface TripleStore extends Copyable<TripleStore> {
*
* @return an independent copy of this store
*/
@Override
TripleStore copy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ protected Triple[] newKeysArray(int size) {
/**
* Create a copy of this set.
*
* @return
* @return TripleSet
*/
@Override
public TripleSet copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ public void testCopy() {

when(mockStore.copy()).thenReturn(mockStoreCopy);

var sut = new GraphMem2(mockStore);
var copy = sut.copy();
GraphMem2 sut = new GraphMem2(mockStore);
GraphMem2 copy = sut.copy();

assertTrue(copy instanceof GraphMem2);
assertNotNull(copy);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy is a GraphMem2 so the instanceof is false only if copy is null.

assertEquals(mockStoreCopy, copy.tripleStore);
}
}
}