Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class RequirementsFile(requirementsDirectory: File, requirementType: String, fil
requirement.file.getAbsolutePath.lastIndexOf(File.separator) + 1).replace(".java", "")

val requiresValue = if (requirement.requires != "") requirement.requires else className

val generatedName = className.replace(requirementType, "")
val generatedName = if(requirementType.equalsIgnoreCase("parameter")) className else className.replace(requirementType, "")

val methodNameValue = if (requirement.methodName != "") {
requirement.methodName.replace(" ", "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.codeoverflow.chatoverflow.requirement.parameter

import org.codeoverflow.chatoverflow.api.io.parameter.BooleanParameter
import org.codeoverflow.chatoverflow.registry.Impl
import java.lang.Boolean

/**
* A parameter holding a boolean value.
*/
@Impl(impl = classOf[BooleanParameter])
class BooleanParameterImpl extends BooleanParameter {
private var value: Boolean = null

override def getType: Class[Boolean] = classOf[Boolean]

override def serialize(): String = get().toString

override def get(): Boolean = value

override def deserialize(value: String): Unit = {
set(Boolean.parseBoolean(value))
}

override def set(value: Boolean): Unit = this.value = value

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.codeoverflow.chatoverflow.requirement.parameter

import org.codeoverflow.chatoverflow.api.io.parameter.DoubleParameter
import org.codeoverflow.chatoverflow.registry.Impl
import java.lang.Double

/**
* A parameter holding a double value.
*/
@Impl(impl = classOf[DoubleParameter])
class DoubleParameterImpl extends DoubleParameter {

private var value: Double = null

override def getType: Class[Double] = classOf[Double]

override def serialize(): String = get().toString

override def get(): Double = value

override def deserialize(value: String): Unit = {
try {
set(Double.valueOf(value))
}
}

override def set(value: Double): Unit = this.value = value
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.codeoverflow.chatoverflow.requirement.parameter

import org.codeoverflow.chatoverflow.api.io.parameter.IntegerParameter
import org.codeoverflow.chatoverflow.registry.Impl

/**
* A parameter holding a int value.
*/
@Impl(impl = classOf[IntegerParameter])
class IntegerParameterImpl extends IntegerParameter {
private var value: Integer = null

override def getType: Class[Integer] = classOf[Integer]

override def serialize(): String = get().toString

override def get(): Integer = value

override def deserialize(value: String): Unit = {
try {
set(Integer.valueOf(value))
}
}

override def set(value: Integer): Unit = this.value = value

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.codeoverflow.chatoverflow.requirement.parameter

import java.util.Collections
import java.util.List

import collection.JavaConverters._
import org.codeoverflow.chatoverflow.api.io.parameter.ListParameter
import org.codeoverflow.chatoverflow.registry.Impl

import scala.collection.mutable.ListBuffer

/**
* A parameter holding a List<String> value.
*/
@Impl(impl = classOf[ListParameter])
class ListParameterImpl extends ListParameter {
private var value: List[String] = null

override def getType: Class[List[String]] = classOf[List[String]]

override def serialize(): String = {
var out = ""
for (part <- value.toArray()) {
if (out == "") {
out = out + part
} else {
out = out + "," + part
}
}
out
}

override def get(): List[String] = value

override def deserialize(value: String): Unit = {
var splits = value.split(",");
if (splits.length == 1) {
set(Collections.singletonList[String](splits(0)))
} else {
var list: ListBuffer[String] = ListBuffer[String]()
for (part <- splits) {
list += part
}
set(mutableSeqAsJavaList[String](list))
}
}

override def set(value: List[String]): Unit = this.value = value

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.codeoverflow.chatoverflow.requirement.parameter

import java.util.{Collections, List}

import org.codeoverflow.chatoverflow.registry.Impl
import org.codeoverflow.chatoverflow.api.io.parameter.MapParameter

import collection.JavaConverters._
import java.util.Map
/**
* A parameter holding a Map<String, String> value.
*/
@Impl(impl = classOf[MapParameter])
class MapParameterImpl extends MapParameter{
private var value: Map[String, String] = null

override def getType: Class[Map[String, String]] = classOf[Map[String, String]]

override def serialize(): String = {
var out = ""
value.keySet().forEach(key => {
var valueSet = value.get(key)
if(out == ""){
out = out + "("+key+";"+valueSet+")"
}else{
out = out + ",("+key+";"+valueSet+")"
}
})
out
}

override def get(): Map[String, String] = value

override def deserialize(value: String): Unit = {
var splits = value.split(",");
if (splits.length == 1) {
var obj = splits(0)
obj = obj.replaceAll("\\(" ,"").replaceAll("\\)","").trim
splits = obj.split(";")
if(splits.length == 2){
set(Collections.singletonMap[String, String](splits(0), splits(1)))
}
} else {
var map = scala.collection.mutable.Map[String, String]()
for (part <- splits) {
var obj: String = part.replaceAll("\\(" ,"").replaceAll("\\)","").trim
var parts = obj.split(";")
if(parts.length == 2){
map += (parts(0) -> parts(1))
}
}
if(map.nonEmpty) set(mutableMapAsJavaMap[String, String](map))
}
}

override def set(value: Map[String, String]): Unit = this.value = value

}