Skip to content

Commit 653eeac

Browse files
committed
fix bug where listProperties couldn't be overridden
1 parent 4d60414 commit 653eeac

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

gremlin-scala/src/main/scala/gremlin/scala/ScalaVertex.scala

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ case class ScalaVertex(vertex: Vertex) extends ScalaElement[Vertex] {
2727
vertex
2828
}
2929

30-
override def removeProperty(key: Key[_]): Vertex = {
31-
val p = property(key)
32-
if (p.isPresent) p.remove()
30+
override def removeProperty(key: Key[_]): Vertex =
31+
removeProperty(key, Cardinality.single)
32+
33+
def removeProperty(key: Key[_], cardinality: Cardinality): Vertex = {
34+
cardinality match {
35+
case Cardinality.single =>
36+
val p = property(key)
37+
if (p.isPresent) p.remove
38+
case Cardinality.list | Cardinality.set =>
39+
vertex.properties(key.name).asScala.foreach { p: VertexProperty[_] =>
40+
p.remove
41+
}
42+
}
3343
vertex
3444
}
3545

@@ -114,7 +124,7 @@ case class ScalaVertex(vertex: Vertex) extends ScalaElement[Vertex] {
114124

115125
/** convenience function for `property` which normally requires to pass in key/value pairs as varargs */
116126
def setPropertyList[A <: AnyRef](key: String, values: List[A]): VertexProperty[A] = {
117-
removeProperty(Key[A](key))
127+
removeProperty(Key[A](key), Cardinality.list)
118128
values
119129
.map { value =>
120130
vertex.property(Cardinality.list, key, value)

gremlin-scala/src/test/scala/gremlin/scala/ElementSpec.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class ElementSpec extends TestBase {
6666
// gremlin-scala style
6767
v.setPropertyList(TestProperty, List("one", "two", "three"))
6868
graph.V(v).properties(TestProperty.name).count.head shouldBe 3
69+
70+
// can override
71+
v.setPropertyList(TestProperty, List("three", "four"))
72+
graph.V(v).properties(TestProperty.name).count.head shouldBe 2
6973
}
7074

7175
it("removes a property") {

0 commit comments

Comments
 (0)