public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -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.validator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Validator</name>
</project>
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.helper.validator</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>1779484362615</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,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Validator
Bundle-SymbolicName: flintstones.helper.validator
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: flintstones.helper.validator
Automatic-Module-Name: flintstones.helper.validator
Require-Bundle: org.eclipse.e4.core.services;visibility:=reexport,
javax.inject
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,509 @@
package flintstones.helper.validator;
import javax.inject.Inject;
import org.eclipse.e4.core.services.nls.Translation;
import flintstones.helper.validator.messages.Messages;
@SuppressWarnings("javadoc")
public class Validator {
@Inject
@Translation
private Messages messages;
/**
* Cadena para mostrar si no se aceptan valores nulos.
*/
private final static String NOT_NULL = Messages.Cannot_pass_null_value;
/**
* Cadena para mostrar si no se aceptan cadenas vacías.
*/
private final static String NOT_EMPTY_STRING = Messages.Cannot_pass_empty_string;
/**
* Cadena para mostrar si no se aceptan arrays vacíos.
*/
private final static String NOT_EMPTY_ARRAY = Messages.ParameterValidator_Cannot_pass_empty_array;
/**
* Cadena para mostrar si el tamaño es inválido.
*/
private final static String INVALID_SIZE = Messages.ParameterValidator_Invalid_size;
/**
* Cadena para mostrar si el rango es inválido.
*/
private final static String INVALID_RANGE = Messages.ParameterValidator_Invalid_range;
/**
* Cadena para mostrar que no se permiten valores negativos.
*/
private final static String NOT_NEGATIVE = Messages.ParameterValidator_Cannot_pass_negative_value;
/**
* Cadena para mostrar que no se permiten valores negativos.
*/
private final static String NOT_DISORDER = Messages.ParameterValidator_Cannot_pass_disorder_values;
/**
* Cadena para mostrar que no se permiten tipos ilegales.
*/
private final static String NOT_ILLEGAL_TYPE = Messages.ParameterValidator_Cannot_pass_illegal_objects;
private final static String NOT_SAME_ELEMENT = Messages.ParameterValidator_Cannot_pass_same_element;
/**
* Comprueba que un valor esté en el rango especificado.
*
* @param value
* Valor a comprobar.
* @param min
* Límite inferior del rango.
* @param max
* Límite superior del rango.
* @return True si el valor está dentro del rango establecido, False en caso
* contrario.
* @throws IllegalArgumentException
* Si el rango no es válido.
*/
public static boolean inRange(int value, int min, int max) {
if (min > max)
throw new IllegalArgumentException(Validator.INVALID_RANGE);
return ((min <= value) && (value <= max));
}
/**
* Comprueba que un valor esté en el rango especificado.
*
* @param value
* Valor a comprobar.
* @param min
* Límite inferior del rango.
* @param max
* Límite superior del rango.
* @return True si el valor está dentro del rango establecido, False en caso
* contrario.
* @throws IllegalArgumentException
* Si el rango no es válido.
*/
public static boolean inRange(double value, double min, double max) {
if (min > max)
throw new IllegalArgumentException(Validator.INVALID_RANGE);
return ((min <= value) && (value <= max));
}
/**
* Comprueba que un valor esté en el rango especificado.
*
* @param value
* Valor a comprobar.
* @param min
* Límite inferior del rango.
* @param max
* Límite superior del rango.
* @param includeStartpoint
* Considerar el valor inicial dentro del rango.
*
* @return True si el valor está dentro del rango establecido, False en caso
* contrario.
* @throws IllegalArgumentException
* Si el rango no es válido.
*/
public static boolean inRange(int value, int min, int max, boolean includeStartpoint, boolean includeEndpoint) {
if (min > max)
throw new IllegalArgumentException(Validator.INVALID_RANGE);
if (includeStartpoint) {
if (includeEndpoint)
return ((min <= value) && (value <= max));
else
return ((min <= value) && (value < max));
} else if (includeEndpoint)
return ((min < value) && (value <= max));
else
return ((min < value) && (value < max));
}
/**
* Comprueba que un valor esté en el rango especificado.
*
* @param value
* Valor a comprobar.
* @param min
* Límite inferior del rango.
* @param max
* Límite superior del rango.
* @param includeStartpoint
* Considerar el valor inicial dentro del rango.
*
* @return True si el valor está dentro del rango establecido, False en caso
* contrario.
* @throws IllegalArgumentException
* Si el rango no es válido.
*/
public static boolean inRange(double value, double min, double max, boolean includeStartpoint, boolean includeEndpoint) {
if (min > max)
throw new IllegalArgumentException(Validator.INVALID_RANGE);
if (includeStartpoint) {
if (includeEndpoint)
return ((min <= value) && (value <= max));
return ((min <= value) && (value < max));
} else if (includeEndpoint)
return ((min < value) && (value <= max));
else
return ((min < value) && (value < max));
}
/**
* Comprueba si una parámetro es nulo.
*
* @param parameter
* Parámetro a comprobar.
* @return True si es nulo, False en caso contrario.
*/
public static boolean isNull(Object parameter) {
return (parameter == null);
}
/**
* Comprueba si una cadena está vacía.
*
* @param parameter
* Parámetro a comprobar.
* @return True si es la cadena vacía, False en caso contrario.
* @throws IllegalArgumentException
* Si el parámetro es nulo.
*/
public static boolean isEmpty(String parameter) {
Validator.notNull(parameter);
return (parameter.trim()
.isEmpty());
}
/**
* Comprueba si un array está vacío.
*
* @param parameter
* Parámetro a comprobar.
* @return True si el array está vacío, False en caso contrario.
*
* @throws IllegalArgumentException
* Si el parámetro es nulo.
*/
public static boolean isEmpty(Object[] parameter) {
Validator.notNull(parameter);
return (parameter.length == 0);
}
/**
* Comprueba si un valor es negativo.
*
* @param value
* Valor a comprobar.
*
* @return True si el valor es negativo, False en caso contrario.
*/
public static boolean isNegative(double value) {
return (value < 0);
}
/**
* Comprueba que un conjunto de valores esté desordenado
*
* @param values
* Valores a comprobar.
*
* @return True si los valores están en orden, False en caso contrario.
*
* @throws IllegalArgumentException
* Si los valores son nulos.
*/
public static boolean isOrdered(double[] values) {
int length;
Validator.notNull(values);
length = values.length;
if (length < 2)
return true;
for (int i = 0; i < length; i++) {
for (int j = 0; j < i; j++)
if (values[j] > values[i])
return false;
for (int j = i + 1; j < length; j++)
if (values[j] < values[i])
return false;
}
return true;
}
/**
* Comprueba que un conjunto de valores esté ordenado de forma estricta.
*
* @param values
* Valores a comprobar.
* @return True si los valores están en orden extricto, False en caso contrario.
* @throws IllegalArgumentException
* Si los valores son nulos.
*/
public static boolean isStrictlyOrdered(double[] values) {
int length;
Validator.notNull(values);
length = values.length;
if (length < 2)
return true;
for (int i = 0; i < length; i++) {
for (int j = 0; j < i; j++)
if (values[j] >= values[i])
return false;
for (int j = i + 1; j < length; j++)
if (values[j] <= values[i])
return false;
}
return true;
}
/**
* Comprueba que un elemento sea de alguno de los tipos indicados.
*
* @param object
* Objeto que debe ser del tipo indicado.
* @param types
* Tipos permitidos.
* @return True si el elemento es de alguno de los tipos indicados, False en
* caso contrario.
* @throw IllegalArgumentException Si object es null o,
* <p>
* si types está vacío o
* <p>
* si types es null.
*/
public static boolean validElementType(Object object, String[] types) {
Validator.notEmpty(types);
Validator.notNull(object);
String objectClass = object.getClass()
.toString();
for (String type : types)
if (objectClass.equals(type))
return true;
return false;
}
/**
* Comprueba si una cadena es nula o está vacía.
*
* @param parameter
* Parámetro a comprobar.
* @return True si es la cadena es nula o está vacía, False en caso contrario.
*/
public static boolean isNullOrEmpty(String parameter) {
return (parameter == null) ? true
: parameter.trim()
.isEmpty();
}
public static boolean isSameElement(Object element, Object other) {
return (element == other);
}
/**
* Comprueba que un parametro no sea nulo.
*
* @param parameter
* Parametro a comprobar.
*
* @throws IllegalArgumentException
* Si el parámetro es nulo.
*/
public static void notNull(Object parameter) {
if (Validator.isNull(parameter))
throw new IllegalArgumentException(Validator.NOT_NULL);
}
/**
* Comprueba que una cadena no sea vacía.
*
* @param parameter
* Parametro a comprobar.
* @throws IllegalArgumentException
* Si la cadena está vacía o es nula.
*/
public static void notEmpty(String parameter) {
if (Validator.isEmpty(parameter))
throw new IllegalArgumentException(Validator.NOT_EMPTY_STRING);
}
/**
* Comprueba que un array no esté vacío
*
* @param parameter
* Array a comprobar.
* @throws IllegalArgumentException
* Si el array está vacía o es nulo.
*/
public static void notEmpty(Object[] parameter) {
if (Validator.isEmpty(parameter))
throw new IllegalArgumentException(Validator.NOT_EMPTY_ARRAY);
}
/**
* Comprueba que el tamaño de un elemento esté dentro de los valores permitidos.
*
* @param size
* Tamaño del elemento.
* @param minValidSize
* Tamaño mínimo permitido.
* @param maxValidSize
* Tamaño máximo permitido.
* @throws IllegalArgumentException
* Si el tamaño no está dentro del rango permitido o si el rango es
* inválido.
*/
public static void notInvalidSize(int size, int minValidSize, int maxValidSize) {
if (!Validator.inRange(size, minValidSize, maxValidSize))
throw new IllegalArgumentException(Validator.INVALID_SIZE + Messages.ParameterValidator_Value_must_be_in_range_1 + size + ", " //$NON-NLS-1$
+ minValidSize + ", " //$NON-NLS-1$
+ maxValidSize + "]."); //$NON-NLS-1$
}
/**
* Comprueba que el tamaño de un elemento esté dentro de los valores permitidos.
*
* @param size
* Tamaño del elemento.
* @param minValidSize
* Tamaño mínimo permitido.
* @param maxValidSize
* Tamaño máximo permitido.
* @throws IllegalArgumentException
* Si el tamaño no está dentro del rango permitido o si el rango es
* inválido.
*/
public static void notInvalidSize(double size, double minValidSize, double maxValidSize, String parameterName) {
if (!Validator.inRange(size, minValidSize, maxValidSize))
throw new IllegalArgumentException(Validator.INVALID_SIZE + "" + size + ", " //$NON-NLS-1$//$NON-NLS-2$
+ minValidSize + ", " //$NON-NLS-1$
+ maxValidSize + "]."); //$NON-NLS-1$
}
/**
* Comprueba que el tamaño de un elemento esté dentro de los valores permitidos.
*
* @param size
* Tamaño del elemento.
* @param minValidSize
* Tamaño mínimo permitido.
* @param maxValidSize
* Tamaño máximo permitido.
* @param includeStartpoint
* Incluir el valor inicial dentro del rango.
* @throws IllegalArgumentException
* Si el tamaño no está dentro del rango permitido o si el rango es
* inválido.
*/
public static void notInvalidSize(int size, int minValidSize, int maxValidSize, boolean includeStartpoint, boolean includeEndpoint, String parameterName) {
if (!Validator.inRange(size, minValidSize, maxValidSize, includeStartpoint, includeEndpoint)) {
String open = (includeEndpoint) ? "[" : "("; //$NON-NLS-1$ //$NON-NLS-2$
String close = (includeEndpoint) ? "]" : ")"; //$NON-NLS-1$ //$NON-NLS-2$
throw new IllegalArgumentException(Validator.INVALID_SIZE + Messages.ParameterValidator_Value_must_be_in_range_2 + open + minValidSize + ", " //$NON-NLS-1$
+ maxValidSize + close + "."); //$NON-NLS-1$
}
}
/**
* Comprueba que el tamaño de un elemento esté dentro de los valores permitidos.
*
* @param size
* Tamaño del elemento.
* @param minValidSize
* Tamaño mínimo permitido.
* @param maxValidSize
* Tamaño máximo permitido.
* @param includeStartpoint
* Incluir el valor inicial dentro del rango.
* @throws IllegalArgumentException
* Si el tamaño no está dentro del rango permitido o si el rango es
* inválido.
*/
public static void notInvalidSize(double size, double minValidSize, double maxValidSize, boolean includeStartpoint, boolean includeEndpoint) {
if (!Validator.inRange(size, minValidSize, maxValidSize, includeStartpoint, includeEndpoint)) {
String open = (includeEndpoint) ? "[" : "("; //$NON-NLS-1$ //$NON-NLS-2$
String close = (includeEndpoint) ? "]" : ")"; //$NON-NLS-1$ //$NON-NLS-2$
throw new IllegalArgumentException(Validator.INVALID_SIZE + "" + open + minValidSize + ", " //$NON-NLS-1$//$NON-NLS-2$
+ maxValidSize + close + "."); //$NON-NLS-1$
}
}
/**
* Comprueba que un valor no sea negativo.
*
* @param value
* Valor a comprobar.
* @throw IllegalArgumentException Si el parámetro es negativo.
*/
public static void notNegative(double value) {
if (Validator.isNegative(value))
throw new IllegalArgumentException(Validator.NOT_NEGATIVE);
}
/**
* Comprueba que un conjunto de valores no estén desordenados.
*
* @param values
* Valores a comprobar.
* @param strictlyOrder
* Orden estricto.
* @throw IllegalArgumentException Si los valores son nulos o están
* desordenados.
*/
public static void notDisorder(double[] values, boolean strictlyOrder) {
boolean disorder;
if (strictlyOrder)
disorder = !Validator.isStrictlyOrdered(values);
else
disorder = !Validator.isOrdered(values);
if (disorder)
throw new IllegalArgumentException(Validator.NOT_DISORDER);
}
/**
* Comprueba que un elemento sea de alguno de los tipos indicados.
*
* @param object
* Objeto que debe ser del tipo indicado.
* @param types
* Tipos permitidos.
* @throw IllegalArgumentException Si el objeto no es de alguno de los tipos
* indicados o,
* <p>
* si object es null o,
* <p>
* si types está vacío o
* <p>
* si types es null.
*/
public static void notIllegalElementType(Object object, String[] types) {
if (!Validator.validElementType(object, types))
throw new IllegalArgumentException(Validator.NOT_ILLEGAL_TYPE);
}
public static void notSameElement(Object element, Object other) {
if (Validator.isSameElement(element, other))
throw new IllegalArgumentException(Validator.NOT_SAME_ELEMENT);
}
}
@@ -0,0 +1,22 @@
// This file has been auto-generated
package flintstones.helper.validator.messages;
import org.eclipse.e4.core.services.nls.Message;
@Message
@SuppressWarnings("javadoc")
public class Messages {
public static String Cannot_pass_null_value;
public static String Cannot_pass_empty_string;
public static String ParameterValidator_Cannot_pass_empty_array;
public static String ParameterValidator_Invalid_size;
public static String ParameterValidator_Invalid_range;
public static String ParameterValidator_Cannot_pass_negative_value;
public static String ParameterValidator_Cannot_pass_disorder_values;
public static String ParameterValidator_Cannot_pass_illegal_objects;
public static String ParameterValidator_Cannot_pass_same_element;
public static String ParameterValidator_Value_must_be_in_range_1;
public static String ParameterValidator_Value_must_be_in_range_2;
}
@@ -0,0 +1,11 @@
Cannot_pass_empty_string=Cannot pass empty string
Cannot_pass_null_value=Cannot pass null value
ParameterValidator_Cannot_pass_disorder_values=Cannot pass disorder values
ParameterValidator_Cannot_pass_empty_array=Cannot pass empty array
ParameterValidator_Cannot_pass_illegal_objects=Cannot pass illegal objects
ParameterValidator_Cannot_pass_negative_value=Cannot pass negative value
ParameterValidator_Cannot_pass_same_element=Cannot pass same element
ParameterValidator_Invalid_range=Invalid range
ParameterValidator_Invalid_size=Invalid size
ParameterValidator_Value_must_be_in_range_1=\ Value must be in range [
ParameterValidator_Value_must_be_in_range_2=\ Value must be in range
@@ -0,0 +1,9 @@
ParameterValidator_Cannot_pass_disorder_values=No se pueden pasar valores desordenados
ParameterValidator_Cannot_pass_empty_array=No se puede pasar un array vacío
ParameterValidator_Cannot_pass_illegal_objects=No se puede pasar objetos inválidos
ParameterValidator_Cannot_pass_negative_value=No se puede pasar valores negativos
ParameterValidator_Cannot_pass_same_element=No se puede pasar elementos iguales
ParameterValidator_Invalid_range=Rango inválidos
ParameterValidator_Invalid_size=Tamaño inválido
ParameterValidator_Value_must_be_in_range_1=\\ El valor debe de estar en el rango [
ParameterValidator_Value_must_be_in_range_2=\\ El valor debe de estar en el rango