Class ConstraintsConverter
java.lang.Object
org.btrplace.json.model.constraint.ConstraintsConverter
public class ConstraintsConverter extends Object
Extensible converter for
Constraint
.- Author:
- Fabien Hermenier
-
Constructor Summary
Constructors Constructor Description ConstraintsConverter()
Make a new empty converter. -
Method Summary
Modifier and Type Method Description Constraint
fromJSON(Model mo, net.minidev.json.JSONObject in)
Convert a json-encoded constraint.Set<Class<? extends Constraint>>
getSupportedJavaConstraints()
Get the Java constraints that are supported by the converter.Set<String>
getSupportedJSONConstraints()
Get the JSON constraints that are supported by the converter.List<SatConstraint>
listFromJSON(Model mo, net.minidev.json.JSONArray in)
Convert a list of json-encoded sat-constraints.static ConstraintsConverter
newBundle()
Make a newConstraintsConverter
and fulfill it using a default converter for each supported constraint.void
register(ConstraintConverter<? extends Constraint> c)
Register a converter for a specific constraint.net.minidev.json.JSONArray
toJSON(Collection<SatConstraint> e)
Serialise a list of sat-constraints.net.minidev.json.JSONObject
toJSON(Constraint o)
Serialise a constraint.
-
Constructor Details
-
ConstraintsConverter
public ConstraintsConverter()Make a new empty converter.
-
-
Method Details
-
newBundle
Make a newConstraintsConverter
and fulfill it using a default converter for each supported constraint.- Returns:
- a fulfilled converter.
-
register
Register a converter for a specific constraint.- Parameters:
c
- the converter to register
-
getSupportedJavaConstraints
Get the Java constraints that are supported by the converter.- Returns:
- a set of classes derived from
Constraint
that may be empty
-
getSupportedJSONConstraints
Get the JSON constraints that are supported by the converter.- Returns:
- a set of constraints identifier that may be empty
-
fromJSON
Convert a json-encoded constraint.- Parameters:
mo
- the model to rely onin
- the constraint to decode- Returns:
- the resulting constraint
- Throws:
JSONConverterException
- if the conversion failed
-
toJSON
Serialise a constraint.- Parameters:
o
- the constraint- Returns:
- the resulting encoded constraint
- Throws:
JSONConverterException
- if the conversion failed
-
listFromJSON
public List<SatConstraint> listFromJSON(Model mo, net.minidev.json.JSONArray in) throws JSONConverterExceptionConvert a list of json-encoded sat-constraints.- Parameters:
mo
- the model to rely onin
- the constraints to decode- Returns:
- the constraint list. Might be empty
- Throws:
JSONConverterException
- if the conversion failed
-
toJSON
public net.minidev.json.JSONArray toJSON(Collection<SatConstraint> e) throws JSONConverterExceptionSerialise a list of sat-constraints.- Parameters:
e
- the list to serialise- Returns:
- the resulting encoded list
- Throws:
JSONConverterException
- if the conversion failed
-