[Git][java-team/dirgra][upstream] Imported Upstream version 0.4

Miguel Landaeta (@nomadium) gitlab at salsa.debian.org
Tue Nov 28 18:11:03 GMT 2023



Miguel Landaeta pushed to branch upstream at Debian Java Maintainers / dirgra


Commits:
63c7099c by Miguel Landaeta at 2023-11-25T16:45:45+00:00
Imported Upstream version 0.4

- - - - -


10 changed files:

- − dirgra.iml
- pom.xml
- spec/data_iterator_spec.rb
- spec/directed_graph_spec.rb
- spec/edge_spec.rb
- spec/edge_type_iterator_spec.rb
- + spec/helpers/vertex_id_helper.rb
- spec/vertex_spec.rb
- + src/module-info.java
- src/org/jruby/dirgra/DirectedGraph.java


Changes:

=====================================
dirgra.iml deleted
=====================================
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
-    <output url="file://$MODULE_DIR$/target/classes" />
-    <output-test url="file://$MODULE_DIR$/target/test-classes" />
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
-      <excludeFolder url="file://$MODULE_DIR$/target" />
-    </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
-    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
-  </component>
-</module>
\ No newline at end of file


=====================================
pom.xml
=====================================
@@ -5,7 +5,7 @@
   <groupId>org.jruby</groupId>
   <artifactId>dirgra</artifactId>
   <packaging>jar</packaging>
-  <version>0.3</version>
+  <version>0.4-SNAPSHOT</version>
   <name>Dirgra</name>
   <url>https://github.com/jruby/dirgra</url>
   <description>Simple Directed Graph</description>
@@ -16,14 +16,9 @@
     <version>7</version>
   </parent>
 
-  <issueManagement>
-    <system>JIRA</system>
-    <url>http://jira.codehaus.org/browse/JRUBY</url>
-  </issueManagement>
-
   <scm>
-    <connection>scm:git:git://github.com/jruby/dirgra.git</connection>
-    <developerConnection>scm:git:git://github.com/jruby/dirgra.git</developerConnection>
+    <connection>scm:git:https://github.com/jruby/dirgra.git</connection>
+    <developerConnection>scm:git:https://github.com/jruby/dirgra.git</developerConnection>
     <url>http://github.com/jruby/dirgra</url>
   </scm>
 
@@ -46,7 +41,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.10</version>
+      <version>4.13.1</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
@@ -65,6 +60,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-source-plugin</artifactId>
+        <version>3.2.1</version> 
         <executions>
           <execution>
             <id>attach-sources</id>
@@ -77,6 +73,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-javadoc-plugin</artifactId>
+        <version>3.0.1</version> 
         <executions>
           <execution>
             <id>attach-javadocs</id>
@@ -87,20 +84,53 @@
         </executions>
       </plugin>
       <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <source>1.6</source>
-          <target>1.6</target>
-        </configuration>
+        <version>3.7.0</version>
+        <executions>
+          <execution>
+            <id>default-compile</id>
+            <configuration>
+              <includes>
+                <include>module-info.java</include>
+              </includes>
+              <release>9</release>
+            </configuration>
+          </execution>
+          <execution>
+            <id>default-testCompile</id>
+            <configuration>
+              <release>9</release>
+            </configuration>
+          </execution>
+          <execution>
+            <id>base-compile</id>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+            <configuration>
+              <source>8</source>
+              <target>8</target>
+              <excludes>
+                <exclude>module-info.java</exclude>
+              </excludes>
+            </configuration>
+          </execution>
+        </executions>
       </plugin>
       <plugin>
         <artifactId>maven-jar-plugin</artifactId>
+        <version>3.2.0</version>
         <configuration>
           <archive>
             <manifestFile>MANIFEST.MF</manifestFile>
           </archive>
         </configuration>
       </plugin>
+      <plugin>
+        <artifactId>maven-release-plugin</artifactId>
+        <version>2.5.3</version>
+      </plugin>
     </plugins>
   </build>
 </project>


=====================================
spec/data_iterator_spec.rb
=====================================
@@ -3,12 +3,19 @@ import 'org.jruby.dirgra.DirectedGraph'
 import 'org.jruby.dirgra.DataIterator'
 import 'java.util.NoSuchElementException'
 
+require 'vertex_id_helper'
+
 describe "DataIterator" do
+  let(:graph) { DirectedGraph.new }
+  let(:one) { VertexID.new(1) }
+  let(:two) { VertexID.new(2) }
+  let(:three) { VertexID.new(3) }
+  let(:four) { VertexID.new(4) }
 
   before do
-    @graph = DirectedGraph.new
-    @graph.addEdge(1, 2, "foo")
-    @graph.addEdge(2, 3, "foo")
+    @edge_count = 0
+    add_edge(one, two, "foo")
+    add_edge(two, three, "foo")
   end
 
   # hasNext method doesn't use the source or destination of iterator at all
@@ -18,12 +25,12 @@ describe "DataIterator" do
     context "edges of given type" do
 
       it "returns true if the iterator contains an edge of given type" do
-        iterator = DataIterator.new(@graph.edges(), "foo", true, false)
+        iterator = DataIterator.new(*edges, "foo", true, false)
         expect(iterator.hasNext).to eq true
       end
 
       it "returns false if the iterator does not contain any edge of given type" do
-        iterator = DataIterator.new(@graph.edges(), "bar", true, false)
+        iterator = DataIterator.new(*edges, "bar", true, false)
         expect(iterator.hasNext).to eq false
       end
 
@@ -32,12 +39,12 @@ describe "DataIterator" do
     context "edges not of given type" do
 
       it "returns true if the iterator contains an edge not of given type" do
-        iterator = DataIterator.new(@graph.edges(), "bar", true, true)
+        iterator = DataIterator.new(*edges, "bar", true, true)
         expect(iterator.hasNext).to eq true
       end
 
       it "returns false if the iterator contains an edge of given type" do
-        iterator = DataIterator.new(@graph.edges(), "foo", true, true)
+        iterator = DataIterator.new(*edges, "foo", true, true)
         expect(iterator.hasNext).to eq false
       end
 
@@ -49,13 +56,13 @@ describe "DataIterator" do
 
         it "returns true if the iterator contains an edge of type nil" do
           # add an edge of type nil
-          @graph.addEdge(4,1,nil)
-          iterator = DataIterator.new(@graph.edges(), nil, true, false)
+          add_edge(four,one,nil)
+          iterator = DataIterator.new(*edges, nil, true, false)
           expect(iterator.hasNext).to eq true
         end
 
         it "returns false if the iterator does not contain any edge of type nil" do
-          iterator = DataIterator.new(@graph.edges(), nil, true, false)
+          iterator = DataIterator.new(*edges, nil, true, false)
           expect(iterator.hasNext).to eq false
         end
 
@@ -64,17 +71,17 @@ describe "DataIterator" do
       context "edges not of given type" do
 
         it "returns true if the iterator contains an edge not of type nil" do
-          iterator = DataIterator.new(@graph.edges(), nil, true, true)
+          iterator = DataIterator.new(*edges, nil, true, true)
           expect(iterator.hasNext).to eq true
         end
 
         it "returns false if the iterator contains all edges of type nil" do
           # remove existing edges not of type nil
-          @graph.removeEdge(1,2)
-          @graph.removeEdge(2,3)
+          remove_edge(one,two)
+          remove_edge(two,three)
           # add an edge of type nil
-          @graph.addEdge(4,1,nil)
-          iterator = DataIterator.new(@graph.edges(), nil, true, true)
+          add_edge(four,one,nil)
+          iterator = DataIterator.new(*edges, nil, true, true)
           expect(iterator.hasNext).to eq false
         end
 
@@ -86,16 +93,16 @@ describe "DataIterator" do
 
       it "returns true if the iterator contains an edge not of type nil" do
         # remove existing edges not of type nil
-        @graph.removeEdge(1,2)
-        @graph.removeEdge(2,3)
+        remove_edge(one,two)
+        remove_edge(two,three)
         # add an edge of type nil
-        @graph.addEdge(4,1,nil)
-        iterator = DataIterator.new(@graph.edges(), "foo", true, true)
+        add_edge(four,one,nil)
+        iterator = DataIterator.new(*edges, "foo", true, true)
         expect(iterator.hasNext).to eq true
       end
 
       it "returns false if the iterator contains all edges not of type nil" do
-        iterator = DataIterator.new(@graph.edges(), "foo", true, true)
+        iterator = DataIterator.new(*edges, "foo", true, true)
         expect(iterator.hasNext).to eq false
       end
     end
@@ -108,15 +115,15 @@ describe "DataIterator" do
 
       context "when asked for data of source vertex" do
         it "returns the data of the source of the edge" do
-          iterator = DataIterator.new(@graph.edges(), "foo", true, false)
-          expect([1, 2]).to include iterator.next
+          iterator = DataIterator.new(*edges, "foo", true, false)
+          expect([one, two]).to include iterator.next
         end
       end
 
       context "when asked for data of destination vertex" do
         it "returns the data of the destination of the edge" do
-          iterator = DataIterator.new(@graph.edges(), "foo", false, false)
-          expect([2, 3]).to include iterator.next
+          iterator = DataIterator.new(*edges, "foo", false, false)
+          expect([two, three]).to include iterator.next
         end
       end
     end
@@ -128,12 +135,12 @@ describe "DataIterator" do
       end
 
       it "throws NoSuchElementException for source data" do
-        iterator = DataIterator.new(@empty_graph.edges(), "foo", true, false)
+        iterator = DataIterator.new(@empty_graph.edges.to_array, 0, "foo", true, false)
         expect { iterator.next }.to raise_error NoSuchElementException
       end
 
       it "throws NoSuchElementException for destination data" do
-        iterator = DataIterator.new(@empty_graph.edges(), "foo", false, false)
+        iterator = DataIterator.new(@empty_graph.edges.to_array, 0, "foo", false, false)
         expect { iterator.next }.to raise_error NoSuchElementException
       end
     end
@@ -142,7 +149,7 @@ describe "DataIterator" do
   describe "remove" do
 
     it "throws UnsupportedOperationException exception" do
-      iterator = DataIterator.new(@graph.edges(), "foo", true, false)
+      iterator = DataIterator.new(graph.edges.to_array, 0, "foo", true, false)
       expect { iterator.remove }.to raise_error Java::JavaLang::UnsupportedOperationException
     end
   end


=====================================
spec/directed_graph_spec.rb
=====================================
@@ -1,89 +1,101 @@
 require 'dirgra-0.3.jar'
 import 'org.jruby.dirgra.DirectedGraph'
 
+require 'vertex_id_helper'
+
 # This is spec for Directed Graph Library
 
 describe "Directed Graph Utility" do
 
+  let(:graph) { DirectedGraph.new }
+  let(:one) { VertexID.new(1) }
+  let(:two) { VertexID.new(2) }
+  let(:three) { VertexID.new(3) }
+  let(:four) { VertexID.new(4) }
+  let(:five) { VertexID.new(5) }
+  let(:six) { VertexID.new(6) }
+  let(:hundred) { VertexID.new(100) }
+  let(:foo) { VertexID.new("foo") }
+  let(:bar) { VertexID.new("bar") }
+
   before do
-    @graph = DirectedGraph.new
+    @edge_count = 0
   end
 
   it "adds an edge to newly created graph" do
-    @graph.edges.size.should be 0
-    @graph.addEdge(1,2,'foo')
-    @graph.addEdge(4,5,'bar')
-    @graph.edges.size.should be 2
+    expect(graph.edges.size).to eq 0
+    add_edge(one,two,'foo')
+    add_edge(four,five,'bar')
+    expect(graph.edges.size).to eq 2
   end
 
   it "removes an existing edge from a graph" do
-    @graph.addEdge(1,2,'foo')
-    @graph.addEdge(4,5,'bar')
-    @graph.removeEdge(4,5)
-    @graph.edges.size.should be 1
-    @graph.removeEdge(@graph.edges.to_a.last)
-    @graph.edges.size.should be 0
+    add_edge(one,two,'foo')
+    add_edge(four,five,'bar')
+    remove_edge(four,five)
+    expect(graph.edges.size).to eq 1
+    graph.removeEdge(graph.edges.to_a.last)
+    expect(graph.edges.size).to eq 0
   end
 
   it "does not delete a non-existent edge from the graph" do
-    @graph.removeEdge(2,1)
-    @graph.edges.size.should be 0
+    remove_edge(two,one)
+    expect(graph.edges.size).to eq 0
   end
 
   it "removes a vertex and its associated edges" do
-    @graph.removeVertexFor(3)
-    @graph.vertices.size.should be 0
-    @graph.addEdge(1,2,'foo')
-    @graph.addEdge(4,5,'bar')
-    @graph.removeVertexFor(2)
-    @graph.vertices.size.should be 3
-    @graph.edges.size.should be 1
+    graph.removeVertexFor(three)
+    expect(graph.vertices.size).to eq 0
+    add_edge(one,two,'foo')
+    add_edge(four,five,'bar')
+    graph.removeVertexFor(two)
+    expect(graph.vertices.size).to eq 3
+    expect(graph.edges.size).to eq 1
   end
 
   it "gives vertex for given data" do
-    @graph.addEdge(1,2,'foo')
-    @graph.findOrCreateVertexFor(2).getData().should be 2
+    add_edge(one,two,'foo')
+    expect(graph.findOrCreateVertexFor(two).getData()).to eq two
   end
 
   it "creates a new vertex if it is not present" do
-    @graph.findOrCreateVertexFor(100).getData().should be 100
+    expect(graph.findOrCreateVertexFor(hundred).getData()).to eq hundred
   end
 
   it "finds already existing vertex" do
-    @graph.findVertexFor(100).should be_nil
-    @graph.addEdge(1,2,'foo')
-    @graph.findVertexFor(1).getData().should be 1
+    expect(graph.findVertexFor(hundred)).to eq nil
+    add_edge(one,two,'foo')
+    expect(graph.findVertexFor(one).getData()).to eq one
   end
 
   it "gives correct size of graph" do
-    @graph.removeEdge(1,2)
-    @graph.size.should be 0
-    @graph.addEdge(5,6,'baz')
-    @graph.size.should be 2
-    @graph.addEdge('foo','bar','baz')
-    @graph.size.should be 4
+    remove_edge(one,two)
+    expect(graph.size).to eq 0
+    add_edge(five,six,'baz')
+    expect(graph.size).to eq 2
+    add_edge(foo,bar,'baz')
+    expect(graph.size).to eq 4
   end
 
   it "gives all data in the graph" do
-    @graph.allData.size.should be 0
-    @graph.addEdge(1,2,'baz')
-    @graph.allData.each do |key|
-      @graph.findVertexFor(key).should_not be_nil
+    expect(graph.allData.size).to eq 0
+    add_edge(one,two,'baz')
+    graph.allData.each do |key|
+      expect(graph.findVertexFor(key)).to_not eq nil
     end
-    @graph.removeVertexFor(1)
-    @graph.allData.each do |key|
-      @graph.findVertexFor(key).should_not be_nil
+    graph.removeVertexFor(one)
+    graph.allData.each do |key|
+      expect(graph.findVertexFor(key)).to_not eq nil
     end
   end
 
   it "gives data in the graph in the order in which it was inserted" do
-    @graph.getInorderData.to_a.size.should be 0
-    @graph.findOrCreateVertexFor(1)
-    @graph.getInorderData.to_a.should eq [1]
-    @graph.addEdge('foo','bar','baz')
-    @graph.getInorderData.to_a.should eq [1,'foo','bar']
-    @graph.removeVertexFor('foo')
-    @graph.getInorderData.to_a.should eq [1,'bar']
+    expect(graph.getInorderData.to_a.size).to eq 0
+    graph.findOrCreateVertexFor(one)
+    expect(graph.getInorderData.to_a).to eq [one]
+    add_edge(foo,bar,'baz')
+    expect(graph.getInorderData.to_a).to eq [one,foo,bar]
+    graph.removeVertexFor(foo)
+    expect(graph.getInorderData.to_a).to eq [one,bar]
   end
-
 end


=====================================
spec/edge_spec.rb
=====================================
@@ -4,23 +4,25 @@ import 'org.jruby.dirgra.Edge'
 import 'org.jruby.dirgra.Vertex'
 import 'org.jruby.dirgra.DirectedGraph'
 
+require 'vertex_id_helper'
+
 describe "Edge" do
 
-  before do
-    @graph = DirectedGraph.new
-  end
+  let(:graph) { DirectedGraph.new }
+  let(:foo) { VertexID.new(1) }
+  let(:bar) { VertexID.new(2) }
 
   describe "toString" do
     context "When edge type is not null" do
       it "represents edge with type" do
-        edge  = Edge.new(Vertex.new(@graph, "foo", 1), Vertex.new(@graph, "bar", 2), "baz")
+        edge  = Edge.new(Vertex.new(graph, foo, 1), Vertex.new(graph, bar, 2), "baz")
         expect(edge.toString).to eq "<1 --> 2> (baz)"
       end
     end
 
     context "When edge type is null" do
       it "represents edge without type" do
-        edge  = Edge.new(Vertex.new(@graph, "foo", 1), Vertex.new(@graph, "bar", 2), nil)
+        edge  = Edge.new(Vertex.new(graph, foo, 1), Vertex.new(graph, bar, 2), nil)
         expect(edge.toString).to eq "<1 --> 2>"
       end
     end


=====================================
spec/edge_type_iterator_spec.rb
=====================================
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/helpers"
 require 'dirgra-0.3.jar'
 
 require 'edge_helpers'
+require 'vertex_id_helper'
 
 import 'org.jruby.dirgra.DirectedGraph'
 import 'org.jruby.dirgra.EdgeTypeIterator'
@@ -10,10 +11,16 @@ import 'java.util.NoSuchElementException'
 
 describe "EdgeTypeIterable" do
 
+  let(:graph) { DirectedGraph.new }
+  let(:one) { VertexID.new(1) }
+  let(:two) { VertexID.new(2) }
+  let(:three) { VertexID.new(3) }
+  let(:four) { VertexID.new(4) }
+
   before do
-    @graph = DirectedGraph.new
-    @graph.addEdge(1, 2, "foo")
-    @graph.addEdge(2, 3, "foo")
+    @edge_count = 0
+    add_edge(one, two, "foo")
+    add_edge(two, three, "foo")
   end
 
   describe "hasNext" do
@@ -21,12 +28,12 @@ describe "EdgeTypeIterable" do
     context "edges of given type" do
 
       it "returns true if the iterator contains an edge of given type" do
-        iterator = EdgeTypeIterator.new(@graph.edges(), "foo", false)
+        iterator = EdgeTypeIterator.new(*edges, "foo", false)
         expect(iterator.hasNext).to eq true
       end
 
       it "returns false if the iterator does not contain any edge of given type" do
-        iterator = EdgeTypeIterator.new(@graph.edges(), "bar", false)
+        iterator = EdgeTypeIterator.new(*edges, "bar", false)
         expect(iterator.hasNext).to eq false
       end
 
@@ -35,12 +42,12 @@ describe "EdgeTypeIterable" do
     context "edges not of given type" do
 
       it "returns true if the iterator contains an edge not of given type" do
-        iterator = EdgeTypeIterator.new(@graph.edges(), "bar", true)
+        iterator = EdgeTypeIterator.new(*edges, "bar", true)
         expect(iterator.hasNext).to eq true
       end
 
       it "returns false if the iterator contains an edge of given type" do
-        iterator = EdgeTypeIterator.new(@graph.edges(), "foo", true)
+        iterator = EdgeTypeIterator.new(*edges, "foo", true)
         expect(iterator.hasNext).to eq false
       end
 
@@ -52,13 +59,13 @@ describe "EdgeTypeIterable" do
 
         it "returns true if the iterator contains an edge of type nil" do
           # add an edge of type nil
-          @graph.addEdge(4,1,nil)
-          iterator = EdgeTypeIterator.new(@graph.edges(), nil, false)
+          add_edge(four,one,nil)
+          iterator = EdgeTypeIterator.new(*edges, nil, false)
           expect(iterator.hasNext).to eq true
         end
 
         it "returns false if the iterator does not contain any edge of type nil" do
-          iterator = EdgeTypeIterator.new(@graph.edges(), nil, false)
+          iterator = EdgeTypeIterator.new(*edges, nil, false)
           expect(iterator.hasNext).to eq false
         end
 
@@ -67,17 +74,17 @@ describe "EdgeTypeIterable" do
       context "edges not of given type" do
 
         it "returns true if the iterator contains an edge not of type nil" do
-          iterator = EdgeTypeIterator.new(@graph.edges(), nil, true)
+          iterator = EdgeTypeIterator.new(*edges, nil, true)
           expect(iterator.hasNext).to eq true
         end
 
         it "returns false if the iterator contains all edges of type nil" do
           # remove existing edges not of type nil
-          @graph.removeEdge(1,2)
-          @graph.removeEdge(2,3)
+          remove_edge(one,two)
+          remove_edge(two,three)
           # add an edge of type nil
-          @graph.addEdge(4,1,nil)
-          iterator = EdgeTypeIterator.new(@graph.edges(), nil, true)
+          add_edge(four,one,nil)
+          iterator = EdgeTypeIterator.new(*edges, nil, true)
           expect(iterator.hasNext).to eq false
         end
 
@@ -89,16 +96,16 @@ describe "EdgeTypeIterable" do
 
       it "returns true if the iterator contains an edge not of type nil" do
         # remove existing edges not of type nil
-        @graph.removeEdge(1,2)
-        @graph.removeEdge(2,3)
+        remove_edge(one,two)
+        remove_edge(two,three)
         # add an edge of type nil
-        @graph.addEdge(4,1,nil)
-        iterator = EdgeTypeIterator.new(@graph.edges(), "foo", true)
+        add_edge(four,one,nil)
+        iterator = EdgeTypeIterator.new(*edges, "foo", true)
         expect(iterator.hasNext).to eq true
       end
 
       it "returns false if the iterator contains all edges not of type nil" do
-        iterator = EdgeTypeIterator.new(@graph.edges(), "foo", true)
+        iterator = EdgeTypeIterator.new(*edges, "foo", true)
         expect(iterator.hasNext).to eq false
       end
     end
@@ -110,7 +117,7 @@ describe "EdgeTypeIterable" do
     context "when the iterator has next edge" do
 
       it "returns the next edge" do
-        iterator = EdgeTypeIterator.new(@graph.edges(), "foo", false)
+        iterator = EdgeTypeIterator.new(*edges, "foo", false)
         expect(iterator.next).to have_type("foo")
       end
     end
@@ -118,7 +125,7 @@ describe "EdgeTypeIterable" do
     context "when the iterator does not have next edge" do
       it "throws NoSuchElementException" do
         empty_graph = DirectedGraph.new
-        iterator = EdgeTypeIterator.new(empty_graph.edges(), "foo", false)
+        iterator = EdgeTypeIterator.new(empty_graph.edges().to_array(), 0, "foo", false)
         expect { iterator.next }.to raise_error NoSuchElementException
       end
     end
@@ -127,7 +134,7 @@ describe "EdgeTypeIterable" do
   describe "remove" do
 
     it "throws UnsupportedOperationException exception" do
-      iterator = EdgeTypeIterator.new(@graph.edges(), "foo", false)
+      iterator = EdgeTypeIterator.new(*edges, "foo", false)
       expect { iterator.remove }.to raise_error Java::JavaLang::UnsupportedOperationException
     end
   end


=====================================
spec/helpers/vertex_id_helper.rb
=====================================
@@ -0,0 +1,30 @@
+
+class VertexID
+  include org.jruby.dirgra.ExplicitVertexID
+
+  def initialize(id)
+    @id = id;
+  end
+
+  def getID
+    @id
+  end
+
+  def to_s
+    @id
+  end
+end
+
+def add_edge(vertex1, vertex2, type)
+  @edge_count += 1
+  graph.addEdge(vertex1, vertex2, type)
+end
+
+def remove_edge(vertex1, vertex2)
+  @edge_count -= 1
+  graph.removeEdge(vertex1, vertex2)
+end
+
+def edges
+  [graph.edges.to_array, @edge_count]
+end


=====================================
spec/vertex_spec.rb
=====================================
@@ -9,10 +9,13 @@ import 'org.jruby.dirgra.Vertex'
 
 describe "Vertex" do
 
+  let(:graph) { DirectedGraph.new }
+  let(:foo) { VertexID.new(1) }
+  let(:bar) { VertexID.new(2) }
+
   before do
-    @graph = DirectedGraph.new
-    @source = Vertex.new(@graph, "foo", 1)
-    @dest   = Vertex.new(@graph, "bar", 2)
+    @source = Vertex.new(graph, foo, 1)
+    @dest   = Vertex.new(graph, bar, 2)
   end
 
   describe "Adding an edge from source to destination" do
@@ -30,17 +33,17 @@ describe "Vertex" do
     end
 
     it "adds the edge to the graph containing source" do
-      expect(@graph.edges()).not_to be nil
+      expect(graph.edges()).not_to be nil
     end
 
     it "sets edge type to null if is not provided" do
-      expect(@graph.edges().first).to have_type(nil)
+      expect(graph.edges().first).to have_type(nil)
     end
 
     it "sets edge type to the given value if is provided" do
       @source.remove_edge(:to => @dest)
       @source.add_edge(:to => @dest, :type => "foobar")
-      expect(@graph.edges.first).to have_type("foobar")
+      expect(graph.edges.first).to have_type("foobar")
     end
 
   end
@@ -67,7 +70,7 @@ describe "Vertex" do
 
     context "Destination of all of the outgoing edges from the current vertex doesn't match with given destination" do
       it "returns false" do
-        non_existent_destination = Vertex.new(@graph, "baz", 3)
+        non_existent_destination = Vertex.new(graph, "baz", 3)
         expect(@source.remove_edge(:to => non_existent_destination)).to be false
       end
     end
@@ -77,7 +80,7 @@ describe "Vertex" do
   describe "Remove all incoming edges" do
 
     before do
-      @interim = Vertex.new(@graph, "interim", 3)
+      @interim = Vertex.new(graph, "interim", 3)
       @dest.add_edge(:to => @source)
       @interim.add_edge(:to => @source)
     end
@@ -92,7 +95,7 @@ describe "Vertex" do
   describe "Remove all outgoing edges" do
 
     before do
-      @interim = Vertex.new(@graph, "interim", 3)
+      @interim = Vertex.new(graph, "interim", 3)
       @source.add_edge(:to => @dest)
       @source.add_edge(:to => @interim)
     end
@@ -107,7 +110,7 @@ describe "Vertex" do
   describe "Remove all edges" do
 
     before do
-      @interim = Vertex.new(@graph, "interim", 3)
+      @interim = Vertex.new(graph, "interim", 3)
       @source.add_edge(:to => @dest)
       @source.add_edge(:to => @interim)
       @dest.add_edge(:to => @source)
@@ -129,7 +132,7 @@ describe "Vertex" do
   describe "getOutGoingEdge" do
 
     before do
-      @null_vertex = Vertex.new(@graph, "null", 3)
+      @null_vertex = Vertex.new(graph, "null", 3)
     end
 
     it "returns first outgoing edge from the vertex not of type 'null'" do
@@ -148,7 +151,7 @@ describe "Vertex" do
   describe "getIncomingEdge" do
 
     before do
-      @null_vertex = Vertex.new(@graph, "null", 3)
+      @null_vertex = Vertex.new(graph, "null", 3)
     end
 
     it "returns first incoming edge to the vertex not of type 'null'" do
@@ -203,7 +206,7 @@ describe "Vertex" do
     context "when there is atleast one incoming edge to the current vertex" do
       it "returns data of the source of that first incoming edge" do
         @source.add_edge(:to => @dest)
-        expect(@dest.data(:direction => :in)).to eq "foo"
+        expect(@dest.data(:direction => :in)).to eq foo
       end
     end
 
@@ -221,13 +224,13 @@ describe "Vertex" do
     context "when there is atleast one incoming edge to the current vertex of the given type" do
       it "returns data of the source of that first incoming edge of given type" do
         @source.add_edge(:to => @dest)
-        expect(@dest.data(:direction => :in, :type => nil)).to eq "foo"
+        expect(@dest.data(:direction => :in, :type => nil)).to eq foo
       end
     end
 
     context "when there is no incoming edge to the current vertex of given type" do
       it "returns null" do
-        @source.add_edge(:to => @dest, :type => "foo")
+        @source.add_edge(:to => @dest, :type => foo)
         expect(@dest.incoming_edge(:type => nil)).to eq nil
       end
     end
@@ -239,7 +242,7 @@ describe "Vertex" do
     context "when there is atleast one outgoing edge from the current vertex" do
       it "returns data of the destination of that first outgoing edge" do
         @source.add_edge(:to => @dest)
-        expect(@source.data(:direction => :out)).to eq "bar"
+        expect(@source.data(:direction => :out)).to eq bar
       end
     end
 
@@ -257,68 +260,16 @@ describe "Vertex" do
     context "when there is atleast one outgoing edge from the current vertex of the given type" do
       it "returns data of the source of that first outgoing edge of given type" do
         @source.add_edge(:to => @dest)
-        expect(@source.data(:direction => :out, :type => nil)).to eq "bar"
+        expect(@source.data(:direction => :out, :type => nil)).to eq bar
       end
     end
 
     context "when there is no outgoing edge from the current vertex of given type" do
       it "returns null" do
-        @source.add_edge(:to => @dest, :type => "foo")
+        @source.add_edge(:to => @dest, :type => foo)
         expect(@source.data(:direction => :out, :type => nil)).to be nil
       end
     end
 
   end
-
-  describe "toString" do
-
-    before do
-      @interim = Vertex.new(@graph, "interim", 3)
-    end
-
-    context "when vertex has no edges" do
-      it "returns string representation of the vertex" do
-        expect(@source.toString).to eq "foo:\n"
-      end
-    end
-
-    context "when vertex has only one outgoing edge" do
-      it "returns string representation of the vertex" do
-        @source.add_edge(:to => @dest)
-        expect(@source.toString).to eq "foo:>[2]\n"
-      end
-    end
-
-    context "when vertex has many outgoing edges" do
-      it "returns string representation of the vertex" do
-        @source.add_edge(:to => @dest)
-        @source.add_edge(:to => @interim)
-        expect(["foo:>[2,3]\n", "foo:>[3,2]\n"]).to include @source.toString
-      end
-    end
-
-    context "when vertex has only one incoming edge" do
-      it "returns string representation of the vertex" do
-        @source.add_edge(:to => @dest)
-        expect(@dest.toString).to eq "bar:<[1]\n"
-      end
-    end
-
-    context "when vertex has many incoming edges" do
-      it "returns string representation of the vertex" do
-        @source.add_edge(:to => @dest)
-        @interim.add_edge(:to => @dest)
-        expect(["bar:<[1,3]\n", "bar:<[3,1]\n"]).to include @dest.toString
-      end
-    end
-
-    context "when vertex has both incoming and outgoing edges" do
-      it "returns string representation of the vertex" do
-        @source.add_edge(:to => @interim)
-        @interim.add_edge(:to => @dest)
-        expect(@interim.toString).to eq "interim:>[2], <[1]\n"
-      end
-    end
-
-  end
 end


=====================================
src/module-info.java
=====================================
@@ -0,0 +1,5 @@
+module org.jruby.dirgra {
+    requires java.base;
+
+    exports org.jruby.dirgra;
+}
\ No newline at end of file


=====================================
src/org/jruby/dirgra/DirectedGraph.java
=====================================
@@ -107,6 +107,9 @@ public class DirectedGraph<T extends ExplicitVertexID> {
     }
 
     /**
+     * Find existing vertex and if it is not present create it.
+     * 
+     * @param data to find a vertex for
      * @return vertex for given data. If vertex is not present it creates vertex and returns it.
      */
     public Vertex<T> findOrCreateVertexFor(T data) {



View it on GitLab: https://salsa.debian.org/java-team/dirgra/-/commit/63c7099c8ae4163455d4a32140dac150d464032a

-- 
View it on GitLab: https://salsa.debian.org/java-team/dirgra/-/commit/63c7099c8ae4163455d4a32140dac150d464032a
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20231128/4c4fe8c2/attachment.htm>


More information about the pkg-java-commits mailing list