public code v1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>flintstones.group</groupId>
|
||||
<artifactId>flintstones.bundles</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>flintstones.helper.chainvalidator</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
<name>[bundle] Chainvalidator</name>
|
||||
</project>
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>flintstones.helper.chainvalidator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1779484362604</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,25 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Chainvalidator
|
||||
Bundle-SymbolicName: flintstones.helper.chainvalidator
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Automatic-Module-Name: flintstones.helper.chainvalidator
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Export-Package: flintstones.helper.chainvalidator,
|
||||
flintstones.helper.chainvalidator.operation,
|
||||
flintstones.helper.chainvalidator.operation.method,
|
||||
flintstones.helper.chainvalidator.pseudocode
|
||||
Require-Bundle: javax.inject,
|
||||
org.eclipse.e4.core.di,
|
||||
org.eclipse.e4.core.contexts,
|
||||
org.eclipse.e4.core.services,
|
||||
org.eclipse.swt,
|
||||
flintstones.entity.domain,
|
||||
flintstones.helper.ui,
|
||||
flintstones.domain.fuzzyset,
|
||||
flintstones.helper.data,
|
||||
javax.annotation,
|
||||
flintstones.model.ui.service,
|
||||
flintstones.entity.valuation,
|
||||
org.apache.commons.lang,
|
||||
flintstones.engine.R
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
package flintstones.helper.chainvalidator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class ChainMessage.
|
||||
*/
|
||||
public class ChainMessage {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The type sucess/error/operator. */
|
||||
private String type = ""; //$NON-NLS-1$
|
||||
|
||||
/** The Constant type_success. */
|
||||
private static final String type_success = Messages.Success;
|
||||
|
||||
/** The Constant type_error. */
|
||||
private static final String type_error = Messages.Error;
|
||||
|
||||
/** The Constant type_operator. */
|
||||
public static final String type_operator = Messages.Operator;
|
||||
|
||||
/** The message. */
|
||||
private String message = ""; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Instantiates a new chain message.
|
||||
*
|
||||
* @param msg the message
|
||||
* @param type the type
|
||||
*/
|
||||
public ChainMessage(String msg, String type) {
|
||||
this.message = msg;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new chain message.
|
||||
*
|
||||
* @param msg the msg
|
||||
* @param status the status (success/error) -> type
|
||||
*/
|
||||
public ChainMessage(String msg, boolean status) {
|
||||
this.message = msg;
|
||||
this.type = status ? ChainMessage.type_success : ChainMessage.type_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is right.
|
||||
*
|
||||
* @return true, if is right
|
||||
*/
|
||||
public boolean isSuccessful() {
|
||||
return this.type.equals(ChainMessage.type_success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the message is an error.
|
||||
*
|
||||
* @return true, if is wrong
|
||||
*/
|
||||
public boolean isWrong() {
|
||||
return this.type.equals(ChainMessage.type_error);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return this.message;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message text.
|
||||
*
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return this.toString();
|
||||
}
|
||||
}
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
package flintstones.helper.chainvalidator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
import flintstones.helper.chainvalidator.operation.And;
|
||||
import flintstones.helper.chainvalidator.operation.BaseOperation;
|
||||
import flintstones.helper.chainvalidator.operation.Or;
|
||||
import flintstones.helper.chainvalidator.operation.binary.Equals;
|
||||
import flintstones.helper.chainvalidator.operation.binary.GreaterOrEqualThan;
|
||||
import flintstones.helper.chainvalidator.operation.binary.GreaterThan;
|
||||
import flintstones.helper.chainvalidator.operation.binary.IsTrue;
|
||||
import flintstones.helper.chainvalidator.operation.binary.LowerOrEqualThan;
|
||||
import flintstones.helper.chainvalidator.operation.binary.LowerThan;
|
||||
import flintstones.helper.chainvalidator.operation.binary.NotEquals;
|
||||
|
||||
/**
|
||||
* The Class ChainValidator.
|
||||
*/
|
||||
public class ChainValidator {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
/** The messages. */
|
||||
private final ArrayList<ChainMessage> chainMessages = new ArrayList<>();
|
||||
|
||||
/** The statement. */
|
||||
private Statement statement;
|
||||
|
||||
/** The last operation. */
|
||||
private BaseOperation lastOperation;
|
||||
|
||||
/** The operator. */
|
||||
private String operator;
|
||||
|
||||
/**
|
||||
* Instantiates a new chain validator.
|
||||
*/
|
||||
public ChainValidator() {
|
||||
};
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
this.operator = this.messages.And;
|
||||
this.statement = ContextInjectionFactory.make(Statement.class, this.context);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate.
|
||||
*
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean validate() {
|
||||
return this.statement.evaluate();
|
||||
};
|
||||
|
||||
/**
|
||||
* Named.
|
||||
*
|
||||
* @param args the args
|
||||
* @return the chain validator
|
||||
*/
|
||||
public ChainValidator named(String... args) {
|
||||
IntStream.range(0, args.length)
|
||||
.forEach(i -> this.lastOperation.addVariableName(args[i]));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Or.
|
||||
*
|
||||
* @return the chain validator
|
||||
*/
|
||||
public ChainValidator or() {
|
||||
|
||||
this.operator = this.messages.Or;
|
||||
ChainMessage cm = new ChainMessage(this.messages.Or_hr, ChainMessage.type_operator);
|
||||
ContextInjectionFactory.inject(cm, this.context);
|
||||
this.chainMessages.add(cm);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update statement.
|
||||
*/
|
||||
private void updateStatement() {
|
||||
if (this.operator.equals(this.messages.And)) {
|
||||
And and = ContextInjectionFactory.make(And.class, this.context);
|
||||
this.statement.add(and);
|
||||
} else if (this.operator.equals(this.messages.Or)) {
|
||||
Or or = ContextInjectionFactory.make(Or.class, this.context);
|
||||
this.statement.add(or);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate item.
|
||||
*
|
||||
* @param op the op
|
||||
*/
|
||||
private void evaluateItem(BaseOperation op) {
|
||||
|
||||
// Get values
|
||||
boolean lastResult = op.evaluate();
|
||||
String msg = op.getValidationMessage();
|
||||
|
||||
// Make a human readable message
|
||||
ChainMessage message = new ChainMessage(msg, lastResult);
|
||||
ContextInjectionFactory.inject(message, this.context);
|
||||
|
||||
this.chainMessages.add(message);
|
||||
|
||||
// Update the if-statement
|
||||
this.statement.add(op);
|
||||
this.statement.updateResult(this.operator, lastResult);
|
||||
this.operator = this.messages.And;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the first operand
|
||||
* @param b the second operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator equals(String entity, Object a, Object b) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new Equals(entity, a, b);
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Greater than operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the first operand
|
||||
* @param b the second operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator greaterThan(String entity, Object a, Object b) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new GreaterThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString()));
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Greater or equals than operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the first operand
|
||||
* @param b the second operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator greaterOrEqualsThan(String entity, Object a, Object b) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new GreaterOrEqualThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString()));
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower than operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the first operand
|
||||
* @param b the second operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator lowerThan(String entity, Object a, Object b) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new LowerThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString()));
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower or equals than operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the first operand
|
||||
* @param b the second operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator lowerOrEqualsThan(String entity, Object a, Object b) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new LowerOrEqualThan(entity, Double.valueOf(a.toString()), Double.valueOf(b.toString()));
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is true operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the only operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator isTrue(String entity, Object a) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new IsTrue(entity, Boolean.valueOf(a.toString()));
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not Equals operator shortcut.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param a the first operand
|
||||
* @param b the second operand
|
||||
* @return An instance of this class to allow chaining more validations
|
||||
*/
|
||||
public ChainValidator notEquals(String entity, Object a, Object b) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = new NotEquals(entity, a, b);
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry-point for adding custom operators.
|
||||
*
|
||||
* @param operation the operation
|
||||
* @return the chain validator
|
||||
*/
|
||||
public ChainValidator custom(BaseOperation operation) {
|
||||
this.updateStatement();
|
||||
this.lastOperation = operation;
|
||||
ContextInjectionFactory.inject(this.lastOperation, this.context);
|
||||
this.evaluateItem(this.lastOperation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the statement.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
public Statement getStatement() {
|
||||
return this.statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the messages.
|
||||
*
|
||||
* @return the messages
|
||||
*/
|
||||
public ArrayList<ChainMessage> getChainMessages() {
|
||||
return this.chainMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the return value of the statement.
|
||||
*
|
||||
* @param text the text
|
||||
* @return the chain validator
|
||||
*/
|
||||
public ChainValidator setReturn(String text) {
|
||||
this.statement.setReturnValue(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package flintstones.helper.chainvalidator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
import flintstones.helper.chainvalidator.operation.BaseOperation;
|
||||
|
||||
/**
|
||||
* The Class Statement.
|
||||
*/
|
||||
public class Statement {
|
||||
|
||||
/** The messages. */
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The context. */
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
/** The operations. */
|
||||
private final ArrayList<BaseOperation> operations = new ArrayList<>();
|
||||
|
||||
/** The return value. */
|
||||
private String returnValue = ""; //$NON-NLS-1$
|
||||
|
||||
/** The result. */
|
||||
private boolean result = true;
|
||||
|
||||
/**
|
||||
* Instantiates a new statement.
|
||||
*/
|
||||
public Statement() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the operations.
|
||||
*
|
||||
* @return the operations
|
||||
*/
|
||||
public ArrayList<BaseOperation> getOperations() {
|
||||
return this.operations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the operations.
|
||||
*
|
||||
* @param ops the new operations
|
||||
*/
|
||||
public void setOperations(ArrayList<BaseOperation> ops) {
|
||||
for (BaseOperation op : ops)
|
||||
this.operations.add(op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param op the op
|
||||
*/
|
||||
public void add(BaseOperation op) {
|
||||
this.operations.add(op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the return value.
|
||||
*
|
||||
* @return the return value
|
||||
*/
|
||||
public String getReturnValue() {
|
||||
return this.returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the return value.
|
||||
*
|
||||
* @param returnValue the new return value
|
||||
*/
|
||||
public void setReturnValue(String returnValue) {
|
||||
this.returnValue = returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate.
|
||||
*
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean evaluate() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the result.
|
||||
*
|
||||
* @param lastResult the new result
|
||||
*/
|
||||
public void setResult(boolean lastResult) {
|
||||
this.result = lastResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
public Statement copy() {
|
||||
Statement clone = ContextInjectionFactory.make(Statement.class, this.context);
|
||||
clone.setOperations(this.operations);
|
||||
clone.setReturnValue(this.returnValue);
|
||||
clone.setResult(this.result);
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update result.
|
||||
*
|
||||
* @param operator the operator
|
||||
* @param lastResult the last result
|
||||
*/
|
||||
public void updateResult(String operator, boolean lastResult) {
|
||||
if (operator.equals(this.messages.And))
|
||||
this.result = this.result && lastResult;
|
||||
else if (operator.equals(this.messages.Or))
|
||||
this.result = this.result || lastResult;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
// This file has been auto-generated
|
||||
package flintstones.helper.chainvalidator.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public static String Success;
|
||||
public static String Error;
|
||||
public static String Operator;
|
||||
public String MessageTemplate;
|
||||
public String And;
|
||||
public String Or_hr;
|
||||
public String Or;
|
||||
public String and_label;
|
||||
public String and_pseudo;
|
||||
public String or_label;
|
||||
public String or_pseudo;
|
||||
public String BaseBinaryOperation_pseudo;
|
||||
public String Equals_label;
|
||||
public String Equals_failed;
|
||||
public String Equals_passed;
|
||||
public String Equals_operator;
|
||||
public String Not_Equals_label;
|
||||
public String Not_Equals_failed;
|
||||
public String Not_Equals_passed;
|
||||
public String Not_Equals_operator;
|
||||
public String GreaterOrEqualThan_label;
|
||||
public String GreaterOrEqualThan_failedTemplate;
|
||||
public String GreaterOrEqualThan_passedTemplate;
|
||||
public String GreaterOrEqualThan_Operator;
|
||||
public String GreaterThan_label;
|
||||
public String GreaterThan_failed;
|
||||
public String GreaterThan_passed;
|
||||
public String GreaterThan_operator;
|
||||
public String IsTrue_label;
|
||||
public String IsTrue_failed;
|
||||
public String IsTrue_passed;
|
||||
public String IsTrue_value;
|
||||
public String IsTrue_operator;
|
||||
public String LowerOrEqualThan_label;
|
||||
public String LowerOrEqualThan_failed;
|
||||
public String LowerOrEqualThan_passed;
|
||||
public String LowerOrEqualThan_operator;
|
||||
public String LowerThan_label;
|
||||
public String LowerThan_failed;
|
||||
public String LowerThan_passed;
|
||||
public String LowerThan_operator;
|
||||
public String BaseMethodOperation_pseudo;
|
||||
public String ValidFuzzysetDomainsOperations_methodLabel;
|
||||
public String ValidFuzzysetDomainsOperations_operationLabel;
|
||||
public String ValidFuzzysetDomainsOperations_failed;
|
||||
public String ValidFuzzysetDomainsOperations_passed;
|
||||
public String ValidFuzzysetDomainsOperations_invalidDomain;
|
||||
public String ValidFuzzysetDomainsOperations_description;
|
||||
public String Generator_headerVariables;
|
||||
public String Generator_headerAlgorith;
|
||||
public String All_domains_are;
|
||||
public String Domain;
|
||||
public String Domain_not_type;
|
||||
public String Domains;
|
||||
public String Domains_same_type;
|
||||
public String Domains_type_are;
|
||||
public String Domain_is_valid_BLTS;
|
||||
public String All_domains_must_be_BLTS;
|
||||
public String Not_BLTS_domain;
|
||||
public String All_domains_are_BLTS;
|
||||
public String Cardinalities_are_matched;
|
||||
public String Domains_BLTS_with_match_cardinalities;
|
||||
public String Domain_cardinality_repeated;
|
||||
public String Possible_to_create_LH;
|
||||
public String Domains_must_follow_sequence;
|
||||
public String Domain_not_satisfy_sequence;
|
||||
public String Sequence_valid;
|
||||
|
||||
|
||||
// ValuationType
|
||||
public String ValuationType_Description;
|
||||
public String ValuationType_Invalid_Valuation_type;
|
||||
public String ValuationType_Invalid_Valuation_type_Not_Assigned;
|
||||
public String ValuationType_All_Valuations_Valid;
|
||||
|
||||
// RLibTest
|
||||
public String RLibTest_Description;
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
And=AND
|
||||
entity=entity
|
||||
Error=Error
|
||||
MessageTemplate={1}
|
||||
Operator=Operator
|
||||
Or=OR
|
||||
Or_hr=o bien
|
||||
Success=Success
|
||||
and_label=and
|
||||
and_pseudo=AND
|
||||
or_label=or
|
||||
or_pseudo=OR
|
||||
BaseBinaryOperation_pseudo={0} {1} {2}
|
||||
Equals_failed={0} is {1}, should be {2}
|
||||
Equals_label=equals
|
||||
Equals_operator==
|
||||
Equals_passed={0} is {1}, is correct
|
||||
Not_Equals_failed={0} is {1}, should not be {1}
|
||||
Not_Equals_label=different
|
||||
Not_Equals_operator=!=
|
||||
Not_Equals_passed={0} is not {2}, is correct
|
||||
GreaterOrEqualThan_failedTemplate={0} is {1}, should be greater or equals than {2}
|
||||
GreaterOrEqualThan_label=greater or equal than
|
||||
GreaterOrEqualThan_Operator=>=
|
||||
GreaterOrEqualThan_passedTemplate={0} is {1}, is correct (Greater or equal than {2})
|
||||
GreaterThan_failed={0} is {1}, should be greater than {2}
|
||||
GreaterThan_label=greater than
|
||||
GreaterThan_operator=>
|
||||
GreaterThan_passed={0} is {1}, is correct (Greater than {2})
|
||||
IsTrue_failed={0} is false, should be true
|
||||
IsTrue_label=is true
|
||||
IsTrue_operator===
|
||||
IsTrue_passed={0} is true, is correct
|
||||
IsTrue_value=true
|
||||
LowerOrEqualThan_failed={0} is {1}, should be less or equal than {2}
|
||||
LowerOrEqualThan_label=lower or equal than
|
||||
LowerOrEqualThan_operator=<=
|
||||
LowerOrEqualThan_passed={0} is {1}, is correct (Less or equal than {2})
|
||||
LowerThan_failed={0} is {1}, should be less than {2}
|
||||
LowerThan_label=lower than
|
||||
LowerThan_operator=<
|
||||
LowerThan_passed={0} is {1}, is correct_ (Less than {2})
|
||||
BaseMethodOperation_pseudo={0}({1})
|
||||
Domain_not_satisfy_sequence=The domain {0} not satisfy the sequence (card {1})
|
||||
Domains_must_follow_sequence=The domains must follow the cardinality sequence [XXXX]
|
||||
Possible_to_create_LH=It is possible to create a LH
|
||||
Sequence_valid=The domains follow a valid cardinality sequence
|
||||
All_domains_are_BLTS=All domains are BLTS
|
||||
All_domains_must_be_BLTS=All domains must be BLTS \n description of BLTS \n Pseudo Code \n xxxx
|
||||
Domain_is_valid_BLTS=Domain is valid BLTS
|
||||
Not_BLTS_domain=The domain {0} is not BLTS
|
||||
ValidFuzzysetDomainsOperations_description=Check if all the available domains are FuzzySet and their cardinality is 2n-1
|
||||
ValidFuzzysetDomainsOperations_failed=The domains {0} do not correspond to a valid sequence
|
||||
ValidFuzzysetDomainsOperations_invalidDomain=The domain {0} is not FuzzySet
|
||||
ValidFuzzysetDomainsOperations_methodLabel=ValidFuzzysetDomains
|
||||
ValidFuzzysetDomainsOperations_operationLabel=Domains are valid FuzzySet domains
|
||||
ValidFuzzysetDomainsOperations_passed=Domains correspond to a valid sequence
|
||||
Generator_headerAlgorith=\# Algorithm to select the suitable CWW methodology \#\n
|
||||
Generator_headerVariables=\# Required values \#\n
|
||||
All_domains_are= The domains are {0}
|
||||
Cardinalities_are_matched=Compatible cardinals
|
||||
Domain_cardinality_repeated=Domain cardinality repeated: {0} ({1} card)
|
||||
Domains_BLTS_with_match_cardinalities=Domains must be BLTS FuzzySet with compatible cardinals
|
||||
Domain=domain
|
||||
Domain_not_type=The type of the domain {0} is not {1}, but {2}
|
||||
Domains=domains
|
||||
Domains_same_type=All the domains must have the same type
|
||||
Domains_type_are=The type of the domains are {0}
|
||||
|
||||
ValuationType_Description =Check if the valuation types are compatible
|
||||
ValuationType_Invalid_Valuation_type=The valuation {0} type is not valid. (Valid types are {1})
|
||||
ValuationType_Invalid_Valuation_type_Not_Assigned=The valuation {0} has not been assigned (Valid types are {1})
|
||||
ValuationType_All_Valuations_Valid=All the valuations are valid
|
||||
RLibTest_Description=Check R library installation
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
And=AND
|
||||
And=AND
|
||||
entity=entity
|
||||
Error=Error
|
||||
MessageTemplate=[{0}] {1}
|
||||
Operator=Operator
|
||||
Or=OR
|
||||
Or=OR
|
||||
Or_hr=o bien
|
||||
Success=Success
|
||||
and_label=y
|
||||
and_pseudo=Y
|
||||
or_label=o
|
||||
or_pseudo=O
|
||||
BaseBinaryOperation_pseudo={0} {1} {2}
|
||||
Equals_failed={0} es {1}, debería ser {2}.
|
||||
Equals_label=equals
|
||||
Equals_operator=\==
|
||||
Equals_passed={0} es {1}, debería ser {2}. Es correcto.
|
||||
Not_Equals_failed={0} es {1}, no debería ser {2}
|
||||
Not_Equals_label=diferente
|
||||
Not_Equals_operator=!=
|
||||
Not_Equals_passed={0} no es {2}, is correct
|
||||
GreaterOrEqualThan_failedTemplate={0} es {1}, debería ser mayor o igual que {2}.
|
||||
GreaterOrEqualThan_label=greater or equal than
|
||||
GreaterOrEqualThan_Operator=>=
|
||||
GreaterOrEqualThan_passedTemplate={0} es {1}, es correcto. (Mayor o igual que {2})
|
||||
GreaterThan_failed={0} es {1}, debería ser mayor que {2}.
|
||||
GreaterThan_label=greater than
|
||||
GreaterThan_operator=>
|
||||
GreaterThan_passed={0} es {1}, es correcto. (Mayor que {2})
|
||||
IsTrue_failed={0} es falso, debería ser verdadero.
|
||||
IsTrue_label=is true
|
||||
IsTrue_operator= ==
|
||||
IsTrue_passed={0} es verdadero, es correcto.
|
||||
IsTrue_value=true
|
||||
LowerOrEqualThan_failed={0} es {1}, deber�a ser menor o igual que {2}.
|
||||
LowerOrEqualThan_label=lower or equal than
|
||||
LowerOrEqualThan_operator=<=
|
||||
LowerOrEqualThan_passed={0} es {1}, es correcto. (Menor o igual que {2})
|
||||
LowerThan_failed={0} es {1}, deber�a ser menor que {2}.
|
||||
LowerThan_label=lower than
|
||||
LowerThan_operator=<
|
||||
LowerThan_passed={0} es {1}, es correcto. (Menor que {2})
|
||||
BaseMethodOperation_pseudo={0}({1})
|
||||
Domain_not_satisfy_sequence=El dominio {0} no cumple con la secuencia (card {1})
|
||||
Domains_must_follow_sequence=Los dominios deben seguir la secuencia [XXXX]
|
||||
Possible_to_create_LH=Es posible crear una LH con los dominios
|
||||
Sequence_valid=Los dominios forman una secuencia valida
|
||||
All_domains_are_BLTS=Todos los dominios son BLTS
|
||||
All_domains_must_be_BLTS=Todos los dominios deben ser BLTS \n Descripción de las condiciones de un dominio BLTS \n Pseudo Código \n xxxx
|
||||
Domain_is_valid_BLTS=El dominio es BLTS
|
||||
Not_BLTS_domain=El dominio {0} no es BLTS
|
||||
ValidFuzzysetDomainsOperations_description=Comprueba si todos los dominios disponibles son FuzzySet y si la cardinalidad de los m�smos es 2n-1
|
||||
ValidFuzzysetDomainsOperations_failed=Los dominios {0} no se corresponden con una secuencia valida
|
||||
ValidFuzzysetDomainsOperations_invalidDomain=El dominio {0} no es FuzzySet
|
||||
ValidFuzzysetDomainsOperations_methodLabel=ValidFuzzysetDomains
|
||||
ValidFuzzysetDomainsOperations_operationLabel=Son dominios FuzzySet válidos
|
||||
ValidFuzzysetDomainsOperations_passed=Los dominios se corresponden con una secuencia valida
|
||||
Generator_headerAlgorith=\# Algoritmo para seleccionar la metodolog�a CWW adecuada \#\n
|
||||
Generator_headerVariables=\# Valores requeridos \#\n
|
||||
All_domains_are=Todos los dominios son {0}
|
||||
Cardinalities_are_matched=Las cardinalidades son compatibles
|
||||
Domain_cardinality_repeated=La cardinalidad del dominio está repetida: {0} ({1} card)
|
||||
Domains_BLTS_with_match_cardinalities=Los dominios deben ser FuzzySet, BLTS y con cardinalidades compatibles
|
||||
Domain=dominio
|
||||
Domain_not_type=El dominio {0} no es del tipo {1}, es del tipo {2}
|
||||
Domains=dominios
|
||||
Domains_same_type=Los dominios deben ser del tipo
|
||||
Domains_type_are=Los dominios son del tipo {0}
|
||||
ValuationType_Description =Comprueba si las valoraciones son compatibles
|
||||
ValuationType_Invalid_Valuation_type=El tipo de la valoración {0} no es valido. (Los tipos validos son {1})
|
||||
ValuationType_Invalid_Valuation_type_Not_Assigned=La valoración {0} no ha sido asignada. (Los tipos válidos son {1})
|
||||
ValuationType_All_Valuations_Valid=Todas las valoraciones son correctas
|
||||
RLibTest_Description=Comprueba si se encuentra instalada la librería de R
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package flintstones.helper.chainvalidator.operation;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class And.
|
||||
*/
|
||||
public class And extends BaseOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new and.
|
||||
*/
|
||||
public And() {
|
||||
super();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
public String getOperationHumanName() {
|
||||
return this.messages.and_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
public String getFailedValidationTemplate() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
public String getPassedValidationTemplate() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getValidationMessage() */
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return this.getPseudoCodeTemplate();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPseudoCodeTemplate() */
|
||||
@Override
|
||||
protected String getPseudoCodeTemplate() {
|
||||
return this.messages.and_pseudo;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() */
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
package flintstones.helper.chainvalidator.operation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import flintstones.helper.chainvalidator.operation.method.BaseMethodOperation;
|
||||
|
||||
/**
|
||||
* The Class BaseOperation.
|
||||
*/
|
||||
public abstract class BaseOperation {
|
||||
|
||||
private String entity = ""; //$NON-NLS-1$
|
||||
|
||||
private Object[] args;
|
||||
|
||||
private final ArrayList<String> variableNames = new ArrayList<>();
|
||||
|
||||
protected BaseOperation() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
protected BaseOperation(String entity, Object... args) {
|
||||
this.entity = entity;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity name.
|
||||
*
|
||||
* @return the entity
|
||||
*/
|
||||
protected String getEntity() {
|
||||
return this.entity;
|
||||
}
|
||||
|
||||
protected void setEntity(String entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
protected void setArgs(Object... args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the name.
|
||||
*
|
||||
* @param index the index
|
||||
* @param value the value
|
||||
*/
|
||||
public void addVariableName(String value) {
|
||||
this.variableNames.add(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variable name.
|
||||
*
|
||||
* @param index the index
|
||||
* @return the variable name
|
||||
*/
|
||||
protected String getVariableName(int index) {
|
||||
return (this.variableNames.size() > index) ? this.variableNames.get(index) : "[Nombre de variable no definido para " + this.entity + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the variable names.
|
||||
*
|
||||
* @return the variable names
|
||||
*/
|
||||
public ArrayList<String> getVariableNames() {
|
||||
return this.variableNames;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the variables.
|
||||
*
|
||||
* @return the variables
|
||||
*/
|
||||
public HashMap<String, String> getVariables() {
|
||||
|
||||
HashMap<String, String> namesKV = new HashMap<>();
|
||||
|
||||
// ars[0] should be an Object[] but ars[] == Object[]
|
||||
if( args != null && args.length > getVariableNames().size() && getVariableNames().size() == 1 && this instanceof BaseMethodOperation ) {
|
||||
Object[] items = args;
|
||||
args = new Object[1];
|
||||
args[0] = items;
|
||||
}
|
||||
|
||||
for (int index = 0; index < this.getVariableNames().size(); index++) {
|
||||
String key = this.variableNames.get(index);
|
||||
String value = ( args.length > index ) ? this.getVariableValue(this.args[index]) : "";
|
||||
|
||||
namesKV.put(key, value);
|
||||
}
|
||||
|
||||
return namesKV;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the readable name of the operationsss.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
protected abstract String getOperationHumanName();
|
||||
|
||||
/**
|
||||
* Gets the pseudo code.
|
||||
*
|
||||
* @return the pseudo code
|
||||
*/
|
||||
public abstract String getPseudoCode();
|
||||
|
||||
/**
|
||||
* Gets the readable message.
|
||||
*
|
||||
* @return the message
|
||||
*/
|
||||
public abstract String getValidationMessage();
|
||||
|
||||
/**
|
||||
* Gets the human readable description.
|
||||
*
|
||||
* @return the description of the operation
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* Gets the template for the wrong message.
|
||||
*
|
||||
* @return the wrong template
|
||||
*/
|
||||
protected abstract String getFailedValidationTemplate();
|
||||
|
||||
/**
|
||||
* Gets the template for the message when validation pass.
|
||||
*
|
||||
* @return the right template
|
||||
*/
|
||||
protected abstract String getPassedValidationTemplate();
|
||||
|
||||
/**
|
||||
* Gets the pseudo code template.
|
||||
*
|
||||
* @return the pseudo code template
|
||||
*/
|
||||
protected abstract String getPseudoCodeTemplate();
|
||||
|
||||
/**
|
||||
* Evaluate.
|
||||
*
|
||||
* @return true, if successful
|
||||
*/
|
||||
public abstract boolean evaluate();
|
||||
|
||||
/**
|
||||
* Return how the variable will be displayed. Can be overrided.
|
||||
* @param var variable
|
||||
* @return
|
||||
*/
|
||||
protected String getVariableValue(Object var) {
|
||||
|
||||
if(var == null)
|
||||
return "NULL";
|
||||
else if( var.getClass().isArray() ) {
|
||||
|
||||
Object[] items = (Object[]) var;
|
||||
|
||||
ArrayList<String> texts = new ArrayList<>();
|
||||
for( Object item : items ) {
|
||||
texts.add(item.toString());
|
||||
}
|
||||
return String.join(", ", texts);
|
||||
} else {
|
||||
return var.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package flintstones.helper.chainvalidator.operation;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class Or.
|
||||
*/
|
||||
public class Or extends BaseOperation {
|
||||
|
||||
/** The messages. */
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new or.
|
||||
*/
|
||||
public Or() {
|
||||
super();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName()
|
||||
*/
|
||||
@Override
|
||||
public String getOperationHumanName() {
|
||||
return this.messages.or_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
public String getFailedValidationTemplate() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
public String getPassedValidationTemplate() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage()
|
||||
*/
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode()
|
||||
*/
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return this.getPseudoCodeTemplate();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCodeTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getPseudoCodeTemplate() {
|
||||
return this.messages.or_pseudo;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate()
|
||||
*/
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
import flintstones.helper.chainvalidator.operation.BaseOperation;
|
||||
|
||||
/**
|
||||
* The Class BaseBinaryOperation.
|
||||
*/
|
||||
public abstract class BaseBinaryOperation extends BaseOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
private Object paramA;
|
||||
private Object paramB;
|
||||
|
||||
/**
|
||||
* Instantiates a new base binary operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public BaseBinaryOperation(String entity, Object... args) {
|
||||
super(entity, args);
|
||||
|
||||
this.paramA = args[0];
|
||||
this.paramB = args[1];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key.
|
||||
*
|
||||
* @return the key
|
||||
*/
|
||||
public abstract String getKey();
|
||||
|
||||
/**
|
||||
* Gets the value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public abstract String getValue();
|
||||
|
||||
/**
|
||||
* Gets the operator.
|
||||
*
|
||||
* @return the operator
|
||||
*/
|
||||
public abstract String getOperator();
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPseudoCodeTemplate() */
|
||||
@Override
|
||||
public String getPseudoCodeTemplate() {
|
||||
return this.messages.BaseBinaryOperation_pseudo;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getValidationMessage() */
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if (this.evaluate()) {
|
||||
return MessageFormat.format(this.getPassedValidationTemplate(), this.getEntity(), paramA, paramB)
|
||||
.toString();
|
||||
}
|
||||
return MessageFormat.format(this.getFailedValidationTemplate(), this.getEntity(), paramA, paramB)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getDescription() */
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class Equals.
|
||||
*/
|
||||
public class Equals extends BaseBinaryOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The first operand. */
|
||||
private final Object a;
|
||||
|
||||
/** The second operand. */
|
||||
private final Object b;
|
||||
|
||||
/**
|
||||
* Instantiates a new equals.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public Equals(String entity, Object... args) {
|
||||
|
||||
super(entity, args);
|
||||
|
||||
this.a = args[0];
|
||||
this.b = args[1];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
public String getOperationHumanName() {
|
||||
return this.messages.Equals_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
public String getFailedValidationTemplate() {
|
||||
return this.messages.Equals_failed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
public String getPassedValidationTemplate() {
|
||||
return this.messages.Equals_passed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.a, this.b)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (this.a.equals(this.b))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.b.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.Equals_operator;
|
||||
}
|
||||
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class GreaterOrEqualThan.
|
||||
*/
|
||||
public class GreaterOrEqualThan extends BaseBinaryOperation {
|
||||
|
||||
/** The first operand. */
|
||||
private final Double a;
|
||||
|
||||
/** The second operand. */
|
||||
private final Double b;
|
||||
|
||||
private final String aS;
|
||||
|
||||
private final String bS;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new greater or equal than.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public GreaterOrEqualThan(String entity, Double... args) {
|
||||
|
||||
super(entity, (Object[]) args);
|
||||
|
||||
this.a = args[0];
|
||||
this.b = args[1];
|
||||
|
||||
NumberFormat nf = new DecimalFormat("##.##");
|
||||
|
||||
this.aS = nf.format(a);
|
||||
this.bS = nf.format(b);
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return this.messages.GreaterOrEqualThan_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return this.messages.GreaterOrEqualThan_failedTemplate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return this.messages.GreaterOrEqualThan_passedTemplate;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (this.a.compareTo(this.b) >= 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.bS;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.GreaterOrEqualThan_Operator;
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class GreaterThan.
|
||||
*/
|
||||
public class GreaterThan extends BaseBinaryOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The a. */
|
||||
private final Double a;
|
||||
|
||||
/** The b. */
|
||||
private final Double b;
|
||||
|
||||
private final String aS;
|
||||
|
||||
private final String bS;
|
||||
|
||||
/**
|
||||
* Instantiates a new greater than operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public GreaterThan(String entity, Double... args) {
|
||||
|
||||
super(entity, (Object[]) args);
|
||||
|
||||
this.a = args[0];
|
||||
this.b = args[1];
|
||||
|
||||
NumberFormat nf = new DecimalFormat("##.##");
|
||||
|
||||
this.aS = nf.format(a);
|
||||
this.bS = nf.format(b);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
public String getOperationHumanName() {
|
||||
return this.messages.GreaterThan_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
public String getFailedValidationTemplate() {
|
||||
return this.messages.GreaterThan_failed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
public String getPassedValidationTemplate() {
|
||||
return this.messages.GreaterThan_passed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (this.a.compareTo(this.b) > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.bS;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.GreaterThan_operator;
|
||||
}
|
||||
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class IsTrue.
|
||||
*/
|
||||
public class IsTrue extends BaseBinaryOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The value. */
|
||||
private final Boolean a;
|
||||
|
||||
/**
|
||||
* Instantiates a new checks if is true.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public IsTrue(String entity, Boolean... args) {
|
||||
|
||||
super(entity, args, true);
|
||||
|
||||
this.a = args[0];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
public String getOperationHumanName() {
|
||||
return this.messages.IsTrue_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
public String getFailedValidationTemplate() {
|
||||
return this.messages.IsTrue_failed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
public String getPassedValidationTemplate() {
|
||||
return this.messages.IsTrue_passed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.a)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (this.a)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.messages.IsTrue_value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.IsTrue_operator;
|
||||
}
|
||||
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class LowerOrEqualThan Operation.
|
||||
*/
|
||||
public class LowerOrEqualThan extends BaseBinaryOperation {
|
||||
|
||||
/** The messages. */
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The a. */
|
||||
private final Double a;
|
||||
|
||||
/** The b. */
|
||||
private final Double b;
|
||||
|
||||
private final String aS;
|
||||
|
||||
private final String bS;
|
||||
|
||||
/**
|
||||
* Instantiates a new lower or equal than operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public LowerOrEqualThan(String entity, Double... args) {
|
||||
|
||||
super(entity, (Object[]) args);
|
||||
|
||||
this.a = args[0];
|
||||
this.b = args[1];
|
||||
|
||||
NumberFormat nf = new DecimalFormat("##.##");
|
||||
|
||||
this.aS = nf.format(a);
|
||||
this.bS = nf.format(b);
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return this.messages.LowerOrEqualThan_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return this.messages.LowerOrEqualThan_failed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return this.messages.LowerOrEqualThan_passed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (this.a.compareTo(this.b) < 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.bS;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.LowerOrEqualThan_operator;
|
||||
}
|
||||
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class LowerThan.
|
||||
*/
|
||||
public class LowerThan extends BaseBinaryOperation {
|
||||
|
||||
/** The messages. */
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The a. */
|
||||
private final Double a;
|
||||
|
||||
/** The b. */
|
||||
private final Double b;
|
||||
|
||||
private final String aS;
|
||||
|
||||
private final String bS;
|
||||
|
||||
/**
|
||||
* Instantiates a new lower than operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public LowerThan(String entity, Double... args) {
|
||||
|
||||
super(entity, (Object[]) args);
|
||||
|
||||
this.a = args[0];
|
||||
this.b = args[1];
|
||||
|
||||
NumberFormat nf = new DecimalFormat("##.##");
|
||||
|
||||
this.aS = nf.format(a);
|
||||
this.bS = nf.format(b);
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return this.messages.LowerThan_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return this.messages.LowerThan_failed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return this.messages.LowerThan_passed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.aS, this.bS)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (this.a.compareTo(this.b) <= 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.bS;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.LowerThan_operator;
|
||||
}
|
||||
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package flintstones.helper.chainvalidator.operation.binary;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class Equals.
|
||||
*/
|
||||
public class NotEquals extends BaseBinaryOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The first operand. */
|
||||
private final Object a;
|
||||
|
||||
/** The second operand. */
|
||||
private final Object b;
|
||||
|
||||
/**
|
||||
* Instantiates a new equals.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public NotEquals(String entity, Object... args) {
|
||||
|
||||
super(entity, args);
|
||||
|
||||
this.a = args[0];
|
||||
this.b = args[1];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getOperationLabel(
|
||||
* ) */
|
||||
@Override
|
||||
public String getOperationHumanName() {
|
||||
return this.messages.Not_Equals_label;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getFailedValidationTemplate() */
|
||||
@Override
|
||||
public String getFailedValidationTemplate() {
|
||||
return this.messages.Not_Equals_failed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPassedValidationTemplate() */
|
||||
@Override
|
||||
public String getPassedValidationTemplate() {
|
||||
return this.messages.Not_Equals_passed;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode() */
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.a, this.b)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate() */
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
if (!this.a.equals(this.b))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#getKey
|
||||
* () */
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.getVariableName(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getValue() */
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.b.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation#
|
||||
* getOperator() */
|
||||
@Override
|
||||
public String getOperator() {
|
||||
return this.messages.Not_Equals_operator;
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
import flintstones.helper.chainvalidator.operation.BaseOperation;
|
||||
|
||||
/**
|
||||
* The Class BaseMethodOperation.
|
||||
*/
|
||||
public abstract class BaseMethodOperation extends BaseOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The args. */
|
||||
private final Object[] args;
|
||||
|
||||
/**
|
||||
* Instantiates a new base method operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public BaseMethodOperation(String entity, Object... args) {
|
||||
super(entity, args);
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method name.
|
||||
*
|
||||
* @return the method name
|
||||
*/
|
||||
public abstract String getOperationName();
|
||||
|
||||
/**
|
||||
* Gets the args.
|
||||
*
|
||||
* @return the args
|
||||
*/
|
||||
public Object[] getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the args textual.
|
||||
*
|
||||
* @return the args textual
|
||||
*/
|
||||
public String[] getArgsTextual() {
|
||||
return this.getVariableNames()
|
||||
.toArray(new String[this.getVariableNames()
|
||||
.size()]);
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#
|
||||
* getPseudoCodeTemplate() */
|
||||
@Override
|
||||
public String getPseudoCodeTemplate() {
|
||||
return this.messages.BaseMethodOperation_pseudo;
|
||||
}
|
||||
|
||||
}
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class BuildableLinguisticHerarchyOperation.
|
||||
*/
|
||||
public class BuildableLinguisticHierarchyOperation extends BaseMethodOperation {
|
||||
|
||||
|
||||
/** The params. */
|
||||
private final String params;
|
||||
|
||||
/** The domains. */
|
||||
private final Domain[] domains;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new buildable linguistic herarchy operation check.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param args the args
|
||||
*/
|
||||
public BuildableLinguisticHierarchyOperation(String entity, Object[] args) {
|
||||
super(entity, args);
|
||||
|
||||
if( args.length == 1 ) {
|
||||
domains = new Domain[1];
|
||||
domains[0] = (Domain)args[0];
|
||||
} else if( args.length > 1 ) {
|
||||
ArrayList<Domain> domainsL = new ArrayList<>();
|
||||
for(Object arg : args) {
|
||||
domainsL.add((Domain)arg);
|
||||
}
|
||||
domains = domainsL.toArray(new Domain[domainsL.size()]);
|
||||
} else {
|
||||
domains = new Domain[0];
|
||||
}
|
||||
|
||||
params = (domains.length > 1 ? "domains" : "domain"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.method.BaseMethodOperation#getOperationName()
|
||||
*/
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return "BuildableLinguisticHerarchy"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName()
|
||||
*/
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return messages.Possible_to_create_LH;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode()
|
||||
*/
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), params);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage()
|
||||
*/
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if( evaluate() )
|
||||
return messages.Possible_to_create_LH;
|
||||
|
||||
|
||||
Domain firstInvalidDomain = findFirstInvalid();
|
||||
if(firstInvalidDomain != null)
|
||||
return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName(), ((FuzzySet)firstInvalidDomain).getLabelSet().getCardinality());
|
||||
return getDescription();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return messages.Domains_must_follow_sequence;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return messages.Domain_not_satisfy_sequence;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return messages.Sequence_valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find first invalid.
|
||||
*
|
||||
* @return the domain
|
||||
*/
|
||||
private Domain findFirstInvalid() {
|
||||
|
||||
ArrayList<Integer> cardinalities = new ArrayList<>();
|
||||
|
||||
for(Domain d : domains) {
|
||||
if( !(d instanceof FuzzySet))
|
||||
return null;
|
||||
|
||||
FuzzySet fuzzyDomain = (FuzzySet) d;
|
||||
if(!fuzzyDomain.isBLTS())
|
||||
return null;
|
||||
|
||||
cardinalities.add(((FuzzySet) d).getLabelSet().getCardinality());
|
||||
}
|
||||
|
||||
Collections.sort(cardinalities);
|
||||
|
||||
Domain[] orderedByCardinalityDomains = Arrays.stream(domains)
|
||||
.map(k -> (FuzzySet)k)
|
||||
.sorted( (d1,d2) -> d1.getLabelSet().getCardinality() > d2.getLabelSet().getCardinality() ? 1 : 0 )
|
||||
.toArray(Domain[]::new);
|
||||
|
||||
for(int c = 0; c < cardinalities.size() - 1; c++) {
|
||||
|
||||
int cardinality = cardinalities.get(c);
|
||||
int nextCardinality = cardinalities.get(c + 1);
|
||||
|
||||
// card(Actual) * 2 - 1 == card(Siguiente)
|
||||
if( (cardinality * 2) - 1 != nextCardinality ) {
|
||||
return orderedByCardinalityDomains[c];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate()
|
||||
*/
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
|
||||
if( domains.length == 0 )
|
||||
return false;
|
||||
|
||||
for(Domain d : domains) {
|
||||
if( !(d instanceof FuzzySet))
|
||||
return false;
|
||||
|
||||
FuzzySet fuzzyDomain = (FuzzySet) d;
|
||||
if(!fuzzyDomain.isBLTS())
|
||||
return false;
|
||||
}
|
||||
|
||||
Domain invalidDomain = findFirstInvalid();
|
||||
if(invalidDomain != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
public class CompatibleCardinalitiesOperation extends BaseMethodOperation {
|
||||
|
||||
private final String params;
|
||||
private final Domain[] domains;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
Messages messages;
|
||||
|
||||
public CompatibleCardinalitiesOperation(String entity, Object[] args) {
|
||||
super(entity, args);
|
||||
|
||||
if( args.length == 1 ) {
|
||||
domains = new Domain[1];
|
||||
domains[0] = (Domain)args[0];
|
||||
} else if( args.length > 1 ) {
|
||||
ArrayList<Domain> domainsL = new ArrayList<>();
|
||||
for(Object arg : args) {
|
||||
domainsL.add((Domain)arg);
|
||||
}
|
||||
domains = domainsL.toArray(new Domain[domainsL.size()]);
|
||||
} else {
|
||||
domains = new Domain[0];
|
||||
}
|
||||
|
||||
params = (domains.length > 1 ? "domains" : "domain"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return "CompatibleCardinalities"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return messages.Cardinalities_are_matched;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if( evaluate() ) {
|
||||
return messages.Cardinalities_are_matched;
|
||||
}
|
||||
|
||||
Domain firstInvalidDomain = findFirstInvalid();
|
||||
if(firstInvalidDomain != null)
|
||||
return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName(), ((FuzzySet)firstInvalidDomain).getLabelSet().getCardinality());
|
||||
return getDescription();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return messages.Domains_BLTS_with_match_cardinalities;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return messages.Domain_cardinality_repeated;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return messages.Cardinalities_are_matched;
|
||||
}
|
||||
|
||||
private Domain findFirstInvalid() {
|
||||
|
||||
ArrayList<Integer> cardinalities = new ArrayList<>();
|
||||
for(Domain d : domains) {
|
||||
|
||||
if( !(d instanceof FuzzySet))
|
||||
return null;
|
||||
|
||||
FuzzySet fuzzyDomain = (FuzzySet) d;
|
||||
if(!fuzzyDomain.isBLTS())
|
||||
return null;
|
||||
|
||||
int cardinality = fuzzyDomain.getLabelSet().getCardinality();
|
||||
if( cardinalities.contains(cardinality) )
|
||||
return d;
|
||||
cardinalities.add(cardinality);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
|
||||
if( domains.length == 0 )
|
||||
return false;
|
||||
|
||||
for(Domain d : domains) {
|
||||
if( !(d instanceof FuzzySet))
|
||||
return false;
|
||||
|
||||
FuzzySet fuzzyDomain = (FuzzySet) d;
|
||||
if(!fuzzyDomain.isBLTS())
|
||||
return false;
|
||||
}
|
||||
|
||||
Domain invalidDomain = findFirstInvalid();
|
||||
if(invalidDomain != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class DomainTypeOperation checks the type of a given domain.
|
||||
*/
|
||||
public class DomainTypeOperation extends BaseMethodOperation {
|
||||
|
||||
/** The domain type. */
|
||||
final String domainType;
|
||||
|
||||
/** The domains. */
|
||||
final Domain[] domains;
|
||||
|
||||
/** The params. */
|
||||
final String params;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new domain type operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param type the type
|
||||
* @param args the args
|
||||
*/
|
||||
public DomainTypeOperation(String entity, String type, Domain[] args) {
|
||||
super(entity, type, args);
|
||||
|
||||
domainType = type;
|
||||
|
||||
ArrayList<Domain> domainsL = new ArrayList<>();
|
||||
for (Object arg : args)
|
||||
domainsL.add((Domain) arg);
|
||||
|
||||
domains = domainsL.toArray(new Domain[domainsL.size()]);
|
||||
|
||||
params = domainType + ", " + (domains.length > 1 ? "domains" : "domain");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new domain type operation.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param type the type
|
||||
* @param args the args
|
||||
*/
|
||||
public DomainTypeOperation(String entity, String type, Domain args) {
|
||||
super(entity, type, args);
|
||||
|
||||
domainType = type;
|
||||
|
||||
domains = new Domain[1];
|
||||
domains[0] = args;
|
||||
|
||||
params = domainType + ", " + (domains.length > 1 ? "domains" : "domain");
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.method.BaseMethodOperation#getOperationName()
|
||||
*/
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return "DomainType";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName()
|
||||
*/
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return messages.Domains_type_are;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode()
|
||||
*/
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), params);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage()
|
||||
*/
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if (evaluate())
|
||||
return MessageFormat.format(getPassedValidationTemplate(), domainType);
|
||||
|
||||
Domain firstInvalidDomain = findFirstInvalid();
|
||||
if (firstInvalidDomain != null)
|
||||
return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName(), domainType, firstInvalidDomain.getClass()
|
||||
.getSimpleName());
|
||||
return getDescription();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return messages.Domains_same_type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return messages.Domain_not_type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return messages.All_domains_are;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find first invalid.
|
||||
*
|
||||
* @return the domain
|
||||
*/
|
||||
private Domain findFirstInvalid() {
|
||||
for (Domain d : domains) {
|
||||
if (!d.getClass().getSimpleName().equals(domainType)
|
||||
&& !d.getClass().getSuperclass().getSimpleName().equals(domainType))
|
||||
return d;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate()
|
||||
*/
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
|
||||
if (domains.length == 0)
|
||||
return false;
|
||||
|
||||
Domain firstInvalidDomain = findFirstInvalid();
|
||||
if (firstInvalidDomain != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.rosuda.JRI.Rengine;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* Method operation to test installed R libraries
|
||||
* @author jcfer
|
||||
*
|
||||
*/
|
||||
public class RLibTestOperation extends BaseMethodOperation{
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
Messages messages;
|
||||
|
||||
/**
|
||||
* Libraries names
|
||||
*/
|
||||
private String[] libs;
|
||||
|
||||
/**
|
||||
* Instantiates object
|
||||
* @param entity Entity name
|
||||
* @param reqLib Required libraries names to test
|
||||
*/
|
||||
public RLibTestOperation(String entity, String... reqLibs) {
|
||||
super(entity, (Object[]) reqLibs);
|
||||
|
||||
libs = reqLibs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return operation name
|
||||
*/
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return "RLibTest";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Operation description
|
||||
*/
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return messages.RLibTest_Description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PseudoCode
|
||||
*/
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), "RLibTest, " + libs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Validation results
|
||||
*/
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if(evaluate()) {
|
||||
return MessageFormat.format(this.getPassedValidationTemplate(), "Rtesting", "passedTest");
|
||||
}
|
||||
return MessageFormat.format(this.getFailedValidationTemplate(), "Rtesting", "failedTest");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Operation description
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return messages.RLibTest_Description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Message template for failed evaluation
|
||||
*/
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return messages.BaseMethodOperation_pseudo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Message template for passed evaluation
|
||||
*/
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return messages.BaseMethodOperation_pseudo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates operation
|
||||
*/
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
// Set this property to true, so we can catch the exception
|
||||
System.setProperty("jri.ignore.ule", "yes");
|
||||
try {
|
||||
// Check if the JRI has been loaded and its version too
|
||||
if (Rengine.jriLoaded && Rengine.versionCheck()) {
|
||||
Rengine reng = Rengine.getMainEngine();
|
||||
// In case there's no engine, create a new one
|
||||
if(reng == null)
|
||||
reng = new Rengine(new String[] { "--no-save" }, false, null);
|
||||
// Test all the R libraries. In case any fails, mark R as not functional.
|
||||
for (String l : libs) {
|
||||
if(reng.eval("library(" + l + ")") == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else return false;
|
||||
}catch(UnsatisfiedLinkError e) {
|
||||
// R is not properly installed on the system, as Rengine couldn't load it.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
/**
|
||||
* The Class ValidBLTSDomainOperation.
|
||||
*/
|
||||
public class ValidBLTSDomainOperation extends BaseMethodOperation {
|
||||
|
||||
/** The domains. */
|
||||
final Domain[] domains;
|
||||
|
||||
/** The params. */
|
||||
final String params;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new valid BLTS domain operation check.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param d the d
|
||||
*/
|
||||
public ValidBLTSDomainOperation(String entity, Domain d) {
|
||||
|
||||
super(entity, d);
|
||||
|
||||
domains = new Domain[1];
|
||||
domains[0] = d;
|
||||
|
||||
params = "domain"; //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new valid BLTS domain operation check.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param domains the domains
|
||||
*/
|
||||
public ValidBLTSDomainOperation(String entity, Domain[] domains) {
|
||||
|
||||
super(entity, (Object[])domains);
|
||||
|
||||
ArrayList<Domain> domainsL = new ArrayList<>();
|
||||
for(Domain arg : domains) {
|
||||
domainsL.add(arg);
|
||||
}
|
||||
this.domains = domainsL.toArray(new Domain[domainsL.size()]);
|
||||
|
||||
params = "domains"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.method.BaseMethodOperation#getOperationName()
|
||||
*/
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return "ValidBLTSDomain"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getOperationHumanName()
|
||||
*/
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return messages.Domain_is_valid_BLTS;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPseudoCode()
|
||||
*/
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), params);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getValidationMessage()
|
||||
*/
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if( evaluate() ) {
|
||||
return messages.All_domains_are_BLTS;
|
||||
}
|
||||
Domain firstInvalidDomain = findFirstInvalid();
|
||||
if(firstInvalidDomain != null)
|
||||
return MessageFormat.format(getFailedValidationTemplate(), firstInvalidDomain.getName());
|
||||
return getDescription();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return messages.All_domains_must_be_BLTS;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getFailedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return messages.Not_BLTS_domain;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#getPassedValidationTemplate()
|
||||
*/
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return messages.All_domains_are_BLTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find first invalid.
|
||||
*
|
||||
* @return the domain
|
||||
*/
|
||||
private Domain findFirstInvalid() {
|
||||
|
||||
for(Domain d : domains) {
|
||||
|
||||
if( !(d instanceof FuzzySet))
|
||||
return d;
|
||||
|
||||
FuzzySet fuzzyDomain = (FuzzySet) d;
|
||||
if(!fuzzyDomain.isBLTS())
|
||||
return d;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see flintstones.helper.chainvalidator.operation.BaseOperation#evaluate()
|
||||
*/
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
|
||||
if( domains.length == 0 )
|
||||
return false;
|
||||
|
||||
Domain invalidDomain = findFirstInvalid();
|
||||
if(invalidDomain != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.domain.fuzzyset.FuzzySet;
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ValidFuzzysetDomainsOperation extends BaseMethodOperation {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
private final Domain[] domains;
|
||||
private final String domainsText;
|
||||
|
||||
public ValidFuzzysetDomainsOperation(String entity, Domain[] args) {
|
||||
super(entity, args, true);
|
||||
this.domains = Arrays.copyOf(args, args.length, Domain[].class);
|
||||
this.domainsText = Arrays.stream(this.domains)
|
||||
.map(k -> k.getName())
|
||||
.collect(Collectors.joining(",")) //$NON-NLS-1$
|
||||
.toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return this.messages.ValidFuzzysetDomainsOperations_methodLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return this.messages.ValidFuzzysetDomainsOperations_operationLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), this.getOperationName(), this.domainsText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
return this.messages.ValidFuzzysetDomainsOperations_failed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return this.messages.ValidFuzzysetDomainsOperations_passed;
|
||||
}
|
||||
|
||||
private String invalidDomainTypeTemplate() {
|
||||
return this.messages.ValidFuzzysetDomainsOperations_invalidDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
return this.getFirstErrorOrNull() == null;
|
||||
}
|
||||
|
||||
private String getFirstErrorOrNull() {
|
||||
for (Domain domain : this.domains)
|
||||
if (!(domain instanceof FuzzySet))
|
||||
return MessageFormat.format(this.invalidDomainTypeTemplate(), domain.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVariableValue(Object var) {
|
||||
|
||||
if (!(var instanceof Domain[]))
|
||||
return var.toString();
|
||||
|
||||
Domain[] domains = (Domain[]) var;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < domains.length; i++) {
|
||||
Domain domain = domains[i];
|
||||
sb.append("{"); //$NON-NLS-1$
|
||||
sb.append(domain.getName());
|
||||
|
||||
if ((domain instanceof FuzzySet)) {
|
||||
sb.append(","); //$NON-NLS-1$
|
||||
FuzzySet fuzzyDomain = (FuzzySet) domain;
|
||||
sb.append(fuzzyDomain.getLabelSet()
|
||||
.getCardinality());
|
||||
}
|
||||
sb.append("}"); //$NON-NLS-1$
|
||||
|
||||
if (i < domains.length - 1)
|
||||
sb.append(", "); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
if (this.evaluate())
|
||||
return this.getPassedValidationTemplate();
|
||||
return this.getFirstErrorOrNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.messages.ValidFuzzysetDomainsOperations_description;
|
||||
}
|
||||
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
package flintstones.helper.chainvalidator.operation.method;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
|
||||
import flintstones.entity.valuation.Valuation;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
|
||||
public class ValuationTypeOperation extends BaseMethodOperation {
|
||||
|
||||
String[] validTypes;
|
||||
|
||||
Valuation[] valuations;
|
||||
|
||||
Valuation invalidValuation;
|
||||
|
||||
String params;
|
||||
|
||||
Boolean superClass = null;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
public ValuationTypeOperation(String entity, String[] validTypes, Valuation[] valuations) {
|
||||
super(entity, validTypes, valuations);
|
||||
|
||||
this.validTypes = validTypes;
|
||||
this.valuations = valuations;
|
||||
|
||||
params = StringUtils.join(validTypes, ", ") + (validTypes.length > 1 ? "types" : "type");
|
||||
}
|
||||
|
||||
public ValuationTypeOperation(String entity, String validType, Valuation[] valuations) {
|
||||
super(entity, validType, valuations);
|
||||
|
||||
this.validTypes = new String[1];
|
||||
validTypes[0] = validType;
|
||||
this.valuations = valuations;
|
||||
|
||||
params = validType + " type";
|
||||
}
|
||||
|
||||
|
||||
public ValuationTypeOperation(String entity, String[] validTypes, Valuation[] valuations, boolean superClass) {
|
||||
super(entity, validTypes, valuations);
|
||||
|
||||
this.validTypes = validTypes;
|
||||
this.valuations = valuations;
|
||||
this.superClass = superClass;
|
||||
|
||||
params = StringUtils.join(validTypes, ", ") + (validTypes.length > 1 ? "types" : "type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperationName() {
|
||||
return "ValuationType";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getOperationHumanName() {
|
||||
return messages.ValuationType_Description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPseudoCode() {
|
||||
return MessageFormat.format(this.getPseudoCodeTemplate(), params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValidationMessage() {
|
||||
String types = StringUtils.join(validTypes, ", ");
|
||||
|
||||
if (evaluate())
|
||||
return MessageFormat.format(getPassedValidationTemplate(), types);
|
||||
|
||||
if (invalidValuation != null)
|
||||
return MessageFormat.format(getFailedValidationTemplate(), invalidValuation.getName(), types,
|
||||
invalidValuation.getClass().getSimpleName());
|
||||
return getDescription();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return messages.ValuationType_Description;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFailedValidationTemplate() {
|
||||
if(invalidValuation.isEvaluated())
|
||||
return messages.ValuationType_Invalid_Valuation_type;
|
||||
else
|
||||
return messages.ValuationType_Invalid_Valuation_type_Not_Assigned;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getPassedValidationTemplate() {
|
||||
return messages.ValuationType_All_Valuations_Valid;
|
||||
}
|
||||
|
||||
private Valuation findFirstInvalid() {
|
||||
|
||||
for (Valuation v : valuations) {
|
||||
|
||||
if(!v.isEvaluated())
|
||||
return v;
|
||||
|
||||
boolean found = false;
|
||||
for (String type : validTypes) {
|
||||
if(superClass != null) {
|
||||
if (v.getClass().getSimpleName().equals(type)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
} else if(v.getClass().getSimpleName().equals(type) || v.getClass().getSuperclass().getSimpleName().equals(type)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
return v;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean evaluate() {
|
||||
|
||||
if (valuations.length == 0)
|
||||
return false;
|
||||
|
||||
invalidValuation = findFirstInvalid();
|
||||
if (invalidValuation != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
package flintstones.helper.chainvalidator.pseudocode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
||||
import flintstones.helper.chainvalidator.Statement;
|
||||
import flintstones.helper.chainvalidator.messages.Messages;
|
||||
import flintstones.helper.chainvalidator.operation.And;
|
||||
import flintstones.helper.chainvalidator.operation.BaseOperation;
|
||||
import flintstones.helper.chainvalidator.operation.Or;
|
||||
import flintstones.helper.chainvalidator.operation.binary.BaseBinaryOperation;
|
||||
import flintstones.helper.chainvalidator.operation.method.BaseMethodOperation;
|
||||
import flintstones.helper.data.Pair;
|
||||
|
||||
/**
|
||||
* The Class Generator.
|
||||
*/
|
||||
public class Generator {
|
||||
|
||||
/** The statements. */
|
||||
private final ArrayList<Statement> statements = new ArrayList<>();
|
||||
|
||||
/** The operations in text. */
|
||||
private final ArrayList<Pair<Point, BaseOperation>> operationsInText = new ArrayList<>();
|
||||
|
||||
/** The context. */
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/**
|
||||
* Instantiates a new generator.
|
||||
*/
|
||||
public Generator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the statement.
|
||||
*
|
||||
* @param statement the statement
|
||||
*/
|
||||
public void addStatement(Statement statement) {
|
||||
statement = this.cleanStatement(statement);
|
||||
this.statements.add(statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean statement.
|
||||
*
|
||||
* @param statement the statement
|
||||
* @return the statement
|
||||
*/
|
||||
private Statement cleanStatement(Statement statement) {
|
||||
|
||||
Statement clone = statement.copy();
|
||||
|
||||
if (clone.getOperations()
|
||||
.size() == 0)
|
||||
return clone;
|
||||
|
||||
BaseOperation firstOp = clone.getOperations()
|
||||
.get(0);
|
||||
if (firstOp.getClass()
|
||||
.getSimpleName()
|
||||
.equals(And.class.getSimpleName()))
|
||||
clone.getOperations()
|
||||
.remove(firstOp);
|
||||
if (firstOp.getClass()
|
||||
.getSimpleName()
|
||||
.equals(Or.class.getSimpleName()))
|
||||
clone.getOperations()
|
||||
.remove(firstOp);
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the styled pseudo code.
|
||||
*
|
||||
* @param input the input box
|
||||
* @param drawEvaluation the draw evaluation
|
||||
*/
|
||||
public void drawStyledPseudoCode(StyledText input, boolean drawEvaluation) {
|
||||
|
||||
StyleProvider styler = new StyleProvider(input);
|
||||
styler.drawEvaluation(drawEvaluation);
|
||||
|
||||
// Cabecera
|
||||
styler.addBoldText(this.messages.Generator_headerVariables);
|
||||
|
||||
// Variables
|
||||
HashMap<String, String> variables = this.getAllVariables();
|
||||
Map<String, String> variablesSorted = new TreeMap<>(variables); // Variables sorted by key
|
||||
for (Entry<String, String> entry : variablesSorted.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
styler.addNewVariable(key, value);
|
||||
styler.addNL();
|
||||
}
|
||||
|
||||
// Cabecera
|
||||
styler.addNL();
|
||||
styler.addBoldText(this.messages.Generator_headerAlgorith);
|
||||
|
||||
// If Statement
|
||||
for (Statement statement : this.statements) {
|
||||
styler.addIfOpen();
|
||||
|
||||
statement.getOperations()
|
||||
.stream()
|
||||
.forEach(k -> {
|
||||
|
||||
int paddingBegin = styler.getCurrentPadding();
|
||||
|
||||
if (k instanceof BaseBinaryOperation) {
|
||||
styler.setEvaluation(k.evaluate());
|
||||
BaseBinaryOperation binaryOp = (BaseBinaryOperation) k;
|
||||
styler.addVariableKOV(binaryOp.getKey(), binaryOp.getOperator(), binaryOp.getValue());
|
||||
styler.endEvaluation();
|
||||
|
||||
} else if (k instanceof BaseMethodOperation) {
|
||||
styler.setEvaluation(k.evaluate());
|
||||
BaseMethodOperation methodOp = (BaseMethodOperation) k;
|
||||
styler.addMethod(methodOp.getOperationName(), methodOp.getArgsTextual());
|
||||
styler.endEvaluation();
|
||||
} else {
|
||||
styler.addWS();
|
||||
styler.addText(k.getPseudoCode());
|
||||
styler.addWS();
|
||||
}
|
||||
|
||||
int paddingEnd = styler.getCurrentPadding();
|
||||
this.addOperatorPosition(k, paddingBegin, paddingEnd);
|
||||
|
||||
});
|
||||
|
||||
styler.addIfClose();
|
||||
styler.addNL();
|
||||
|
||||
styler.addReturnLabel();
|
||||
styler.setEvaluation(statement.evaluate());
|
||||
styler.addReturnText(statement.getReturnValue());
|
||||
styler.endEvaluation();
|
||||
|
||||
styler.addNL();
|
||||
}
|
||||
|
||||
input.pack();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the operator position.
|
||||
*
|
||||
* @param operation the operation
|
||||
* @param paddingBegin the padding begin
|
||||
* @param paddingEnd the padding end
|
||||
*/
|
||||
private void addOperatorPosition(BaseOperation operation, int paddingBegin, int paddingEnd) {
|
||||
Point desp = new Point(paddingBegin, paddingEnd);
|
||||
Pair<Point, BaseOperation> pair = new Pair<>(desp, operation);
|
||||
this.operationsInText.add(pair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the operator at the given point in the styled text.
|
||||
*
|
||||
* @param p the p
|
||||
* @return the operator
|
||||
*/
|
||||
public BaseOperation getOperator(Point p) {
|
||||
int position = p.x;
|
||||
for (Pair<Point, BaseOperation> pair : this.operationsInText) {
|
||||
int min = pair.getLeft().x;
|
||||
int max = pair.getLeft().y;
|
||||
if (position >= min && position <= max)
|
||||
return pair.getRight();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the all variables.
|
||||
*
|
||||
* @return the all variables
|
||||
*/
|
||||
private HashMap<String, String> getAllVariables() {
|
||||
HashMap<String, String> variables = new HashMap<>();
|
||||
|
||||
for (Statement statement : this.statements)
|
||||
for (BaseOperation operation : statement.getOperations())
|
||||
variables.putAll(operation.getVariables());
|
||||
return variables;
|
||||
}
|
||||
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
package flintstones.helper.chainvalidator.pseudocode;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
/**
|
||||
* The Class PseudoCodeStyler.
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
public class StyleProvider {
|
||||
|
||||
/** The styled text. */
|
||||
private final /** The styled text widget. */
|
||||
StyledText styledText;
|
||||
|
||||
/** The evaluation. */
|
||||
private int evaluation = 0; // -1 incorrecto, 0 nada, 1 correcto
|
||||
|
||||
/** The draw evaluation. */
|
||||
private boolean drawEvaluation = false;
|
||||
|
||||
/** The ui service. */
|
||||
|
||||
/**
|
||||
* Sets the background color of the widget.
|
||||
*
|
||||
* @param c the new background
|
||||
*/
|
||||
private void setBackground(Color c) {
|
||||
this.styledText.setBackground(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new pseudo code styler.
|
||||
*
|
||||
* @param text the text
|
||||
*/
|
||||
public StyleProvider(StyledText text) {
|
||||
super();
|
||||
this.styledText = text;
|
||||
Color blackBackground = UiService.getColor(28, 31, 34);
|
||||
this.setBackground(blackBackground);
|
||||
UiService.setFont(this.styledText, UiService.FONT_CODE);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the evaluation.
|
||||
*
|
||||
* @param status the new evaluation
|
||||
*/
|
||||
public void setEvaluation(boolean status) {
|
||||
if (this.drawEvaluation)
|
||||
this.evaluation = status ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* End evaluation.
|
||||
*/
|
||||
public void endEvaluation() {
|
||||
this.evaluation = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dibujar.
|
||||
*
|
||||
* @param text the text
|
||||
* @param itemType the item type
|
||||
*/
|
||||
private void paint(String text, String itemType) {
|
||||
|
||||
if (this.evaluation == -1)
|
||||
itemType = UiService.CODE_WRONG;
|
||||
else if (this.evaluation == 1)
|
||||
itemType = UiService.CODE_RIGHT;
|
||||
|
||||
Color foregroundColor = UiService.getCodeForeground(itemType, true);
|
||||
int fontStyle = UiService.getCodeStyle(itemType, true);
|
||||
|
||||
int appendSize = text.length();
|
||||
int totalSize = this.styledText.getText()
|
||||
.length() + appendSize;
|
||||
int begin = totalSize - appendSize;
|
||||
|
||||
this.styledText.append(text);
|
||||
this.styledText.setStyleRange(new StyleRange(begin, appendSize, foregroundColor, null, fontStyle));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tabulation.
|
||||
*/
|
||||
public void addTab() {
|
||||
this.styledText.append(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a white space.
|
||||
*/
|
||||
public void addWS() {
|
||||
this.styledText.append(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new line.
|
||||
*/
|
||||
public void addNL() {
|
||||
this.styledText.append("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds text.
|
||||
*
|
||||
* @param text the text
|
||||
*/
|
||||
public void addText(String text) {
|
||||
this.paint(text, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Key Operator Value.
|
||||
*
|
||||
* @param key the key
|
||||
* @param operator the operator
|
||||
* @param value the value
|
||||
*/
|
||||
public void addVariableKOV(String key, String operator, String value) {
|
||||
// addWS();
|
||||
this.addVariableK(key);
|
||||
this.addWS();
|
||||
this.addOperator(operator);
|
||||
this.addWS();
|
||||
this.addVariableV(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the a var Key = Value.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
public void addNewVariable(String key, String value) {
|
||||
this.addText("var");
|
||||
this.addWS();
|
||||
this.addVariableKOV(key, "=", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Key = Value.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
public void addVariableKV(String key, String value) {
|
||||
this.addVariableKOV(key, "=", value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Key.
|
||||
*
|
||||
* @param key the key
|
||||
*/
|
||||
public void addVariableK(String key) {
|
||||
this.paint(key, UiService.CODE_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Value.
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public void addVariableV(String value) {
|
||||
this.paint(value, UiService.CODE_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the operator.
|
||||
*
|
||||
* @param op the op
|
||||
*/
|
||||
public void addOperator(String op) {
|
||||
this.paint(op, UiService.CODE_OPERATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the bold text. AKA important
|
||||
*
|
||||
* @param text the text
|
||||
*/
|
||||
public void addBoldText(String text) {
|
||||
this.paint(text, UiService.CODE_COMMENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the return label.
|
||||
*
|
||||
*/
|
||||
public void addReturnLabel() {
|
||||
this.addTab();
|
||||
this.paint("return", "return");
|
||||
this.addWS();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the return text.
|
||||
*
|
||||
* @param returnText the return text
|
||||
*/
|
||||
public void addReturnText(String returnText) {
|
||||
returnText = MessageFormat.format("\"{0}\"", returnText);
|
||||
this.paint(returnText, UiService.CODE_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the if open.
|
||||
*/
|
||||
public void addIfOpen() {
|
||||
this.addWS();
|
||||
this.paint("if (", UiService.CODE_CONDITION);
|
||||
this.addWS();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the if close.
|
||||
*/
|
||||
public void addIfClose() {
|
||||
this.addWS();
|
||||
this.paint(") then", UiService.CODE_CONDITION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the method.
|
||||
*
|
||||
* @param methodName the method name
|
||||
* @param args the args
|
||||
*/
|
||||
public void addMethod(String methodName, String... args) {
|
||||
this.paint(methodName + "(", UiService.CODE_METHOD);
|
||||
this.addWS();
|
||||
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
this.addVariableK(arg);
|
||||
if (i < args.length - 1)
|
||||
this.addSemicolon();
|
||||
this.addWS();
|
||||
}
|
||||
this.paint(")", UiService.CODE_METHOD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the semicolon.
|
||||
*/
|
||||
public void addSemicolon() {
|
||||
this.paint(",", "semicolon");
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw evaluation.
|
||||
*
|
||||
* @param state the state
|
||||
*/
|
||||
public void drawEvaluation(boolean state) {
|
||||
this.drawEvaluation = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current padding.
|
||||
*
|
||||
* @return the current padding
|
||||
*/
|
||||
public int getCurrentPadding() {
|
||||
return this.styledText.getText()
|
||||
.length();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user