ips1ap101.lib.base.util.ObjUtils.java Source code

Java tutorial

Introduction

Here is the source code for ips1ap101.lib.base.util.ObjUtils.java

Source

/*
 * Este programa es software libre; usted puede redistribuirlo y/o modificarlo bajo los trminos
 * de la licencia "GNU General Public License" publicada por la Fundacin "Free Software Foundation".
 * Este programa se distribuye con la esperanza de que pueda ser til, pero SIN NINGUNA GARANTIA;
 * vea la licencia "GNU General Public License" para obtener mas informacin.
 */
package ips1ap101.lib.base.util;

import com.sun.webui.jsf.component.Calendar;
import com.sun.webui.jsf.component.Checkbox;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.PasswordField;
import com.sun.webui.jsf.component.TextField;
import com.sun.webui.jsf.component.Upload;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import ips1ap101.lib.base.interfaces.Recurso;
import ips1ap101.lib.base.interfaces.RecursoCodificable;
import ips1ap101.lib.base.interfaces.RecursoEnumerable;
import ips1ap101.lib.base.interfaces.RecursoIdentificable;
import ips1ap101.lib.base.interfaces.RecursoNombrable;
import ips1ap101.lib.core.jsf.component.CampoArchivo;
import ips1ap101.lib.core.jsf.component.CampoArchivoMultiPart;
import org.apache.commons.lang.StringUtils;

/**
 * @author Jorge Campins
 */
public class ObjUtils {

    // <editor-fold defaultstate="collapsed" desc="conversion methods">
    public static Boolean toBoolean(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof Checkbox) {
            return toBoolean(((Checkbox) o).getSelected());
        } else if (o instanceof DropDown) {
            return toBoolean(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toBoolean(((TextField) o).getText());
        }
        return BitUtils.newBoolean(o);
    }

    public static Character toCharacter(Object o) {
        String string = toString(o);
        return string == null ? null : string.isEmpty() ? null : string.charAt(0);
    }

    public static String toString(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof Checkbox) {
            return trimToNull(((Checkbox) o).getSelected());
        } else if (o instanceof DropDown) {
            return trimToNull(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return trimToNull(((TextField) o).getText());
        } else if (o instanceof PasswordField) {
            return trimToNull(((PasswordField) o).getPassword());
        } else if (o instanceof CampoArchivo) {
            return StringUtils.trimToNull(((CampoArchivo) o).getServerFileName());
        } else if (o instanceof CampoArchivoMultiPart) {
            return StringUtils.trimToNull(((CampoArchivoMultiPart) o).getServerFileName());
        } else if (o instanceof RecursoCodificable) {
            return StringUtils.trimToNull(((RecursoCodificable) o).getCodigoRecurso());
        } else if (o instanceof RecursoNombrable) {
            return StringUtils.trimToNull(((RecursoNombrable) o).getNombreRecurso());
        } else if (o instanceof RecursoIdentificable) {
            Long id = ((RecursoIdentificable) o).getIdentificacionRecurso();
            return id == null ? null : id.toString();
        } else if (o instanceof RecursoEnumerable) {
            Integer numero = ((RecursoEnumerable) o).getNumeroRecurso();
            return numero == null ? null : numero.toString();
        }
        return o.toString();
    }

    private static String trimToNull(Object o) {
        return StringUtils.trimToNull(toString(o));
    }

    public static Byte toByte(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toByte(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toByte(((TextField) o).getText());
        }
        try {
            return NumUtils.newByte(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Short toShort(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toShort(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toShort(((TextField) o).getText());
        }
        try {
            return NumUtils.newShort(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Integer toInteger(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toInteger(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toInteger(((TextField) o).getText());
        } else if (o instanceof RecursoIdentificable) {
            return toInteger(((RecursoIdentificable) o).getIdentificacionRecurso());
        } else if (o instanceof RecursoEnumerable) {
            return ((RecursoEnumerable) o).getNumeroRecurso();
        }
        try {
            return NumUtils.newInteger(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Long toLong(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toLong(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toLong(((TextField) o).getText());
        } else if (o instanceof RecursoIdentificable) {
            return ((RecursoIdentificable) o).getIdentificacionRecurso();
        } else if (o instanceof RecursoEnumerable) {
            return toLong(((RecursoEnumerable) o).getNumeroRecurso());
        }
        try {
            return NumUtils.newLong(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Float toFloat(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toFloat(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toFloat(((TextField) o).getText());
        }
        try {
            return NumUtils.newFloat(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Double toDouble(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toDouble(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toDouble(((TextField) o).getText());
        }
        try {
            return NumUtils.newDouble(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static BigInteger toBigInteger(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toBigInteger(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toBigInteger(((TextField) o).getText());
        }
        try {
            return NumUtils.newBigInteger(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static BigDecimal toBigDecimal(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof DropDown) {
            return toBigDecimal(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toBigDecimal(((TextField) o).getText());
        }
        try {
            return NumUtils.newBigDecimal(o);
        } catch (NumberFormatException e) {
            return null;
        }
    }

    public static Date toDate(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof Calendar) {
            return toDate(((Calendar) o).getSelectedDate());
        } else if (o instanceof DropDown) {
            return toDate(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toDate(((TextField) o).getText());
        }
        try {
            return TimeUtils.newDate(o);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    public static Time toTime(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof Calendar) {
            return toTime(((Calendar) o).getSelectedDate());
        } else if (o instanceof DropDown) {
            return toTime(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toTime(((TextField) o).getText());
        }
        try {
            return TimeUtils.newTime(o);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    public static Timestamp toTimestamp(Object o) {
        if (o == null) {
            return null;
        } else if (invalidUIInput(o)) {
            return null;
        } else if (o instanceof Calendar) {
            return toTimestamp(((Calendar) o).getSelectedDate());
        } else if (o instanceof DropDown) {
            return toTimestamp(((DropDown) o).getSelected());
        } else if (o instanceof TextField) {
            return toTimestamp(((TextField) o).getText());
        }
        try {
            return TimeUtils.newTimestamp(o);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    /**
     * Casts object as Recurso.
     *
     * @param o the object to be casted.
     * @return null if the object cannot be casted; same object otherwise.
     */
    public static Recurso toRecurso(Object o) {
        return o instanceof Recurso ? (Recurso) o : null;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="comparison expression methods">
    public static Boolean isNull(Object o) {
        return o == null;
    }

    public static Boolean isNotNull(Object o) {
        return o != null;
    }

    public static Boolean isTrue(Object o) {
        return o != null && toBoolean(o);
    }

    public static Boolean isFalse(Object o) {
        return o != null && !toBoolean(o);
    }

    public static Boolean eq(Object x, Object y) {
        Integer i = compare(x, y);
        return (i != null) ? i == 0 : x != null && y != null && x.equals(y);
    }

    public static Boolean neq(Object x, Object y) {
        Integer i = compare(x, y);
        return (i != null) ? i != 0 : x != null && y != null && !x.equals(y);
    }

    public static Boolean gt(Object x, Object y) {
        Integer i = compare(x, y);
        return (i != null && i > 0);
    }

    public static Boolean gteq(Object x, Object y) {
        Integer i = compare(x, y);
        return (i != null && i >= 0);
    }

    public static Boolean lt(Object x, Object y) {
        Integer i = compare(x, y);
        return (i != null && i < 0);
    }

    public static Boolean lteq(Object x, Object y) {
        Integer i = compare(x, y);
        return (i != null && i <= 0);
    }

    public static Integer compare(Object x, Object y) {
        if (x == null || y == null) {
            return null;
        }
        if (x instanceof Boolean && y instanceof Boolean) {
            Boolean bx = (Boolean) x;
            Boolean by = (Boolean) y;
            return bx.compareTo(by);
        }
        if (x instanceof String && y instanceof String) {
            String sx = (String) x;
            String sy = (String) y;
            return sx.compareTo(sy);
        }
        if (x instanceof Number && y instanceof Number) {
            BigDecimal nx = NumUtils.numberToBigDecimal(x);
            BigDecimal ny = NumUtils.numberToBigDecimal(y);
            return nx.compareTo(ny);
        }
        if (x instanceof java.util.Date && y instanceof java.util.Date) {
            java.util.Date dx = (java.util.Date) x;
            java.util.Date dy = (java.util.Date) y;
            return dx.compareTo(dy);
        }
        if (x instanceof String || y instanceof String) {
            String sx = toString(x);
            String sy = toString(y);
            if (sx != null && sy != null) {
                return sx.compareTo(sy);
            }
        }
        return null;
    }

    public static Boolean startsWith(Object x, Object y) {
        if (x == null || y == null) {
            return false;
        } else if (x instanceof String) {
            return y instanceof String ? StringUtils.startsWithIgnoreCase(((String) x), ((String) y))
                    : StringUtils.startsWithIgnoreCase(((String) x), toString(y));
        }
        return startsWith(toString(x), y);
    }

    public static Boolean notStartsWith(Object x, Object y) {
        return x != null && y != null && !startsWith(x, y);
    }

    public static Boolean contains(Object x, Object y) {
        if (x == null || y == null) {
            return false;
        } else if (x instanceof String) {
            return y instanceof String ? StringUtils.containsIgnoreCase(((String) x), ((String) y))
                    : StringUtils.containsIgnoreCase(((String) x), toString(y));
        }
        return contains(toString(x), y);
    }

    public static Boolean notContains(Object x, Object y) {
        return x != null && y != null && !contains(x, y);
    }

    public static Boolean endsWith(Object x, Object y) {
        if (x == null || y == null) {
            return false;
        } else if (x instanceof String) {
            return y instanceof String ? StringUtils.endsWithIgnoreCase(((String) x), ((String) y))
                    : StringUtils.endsWithIgnoreCase(((String) x), toString(y));
        }
        return endsWith(toString(x), y);
    }

    public static Boolean notEndsWith(Object x, Object y) {
        return x != null && y != null && !endsWith(x, y);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="comparison expression methods (is null or)">
    public static Boolean isNullOrTrue(Object o) {
        return o == null || isTrue(o);
    }

    public static Boolean isNullOrFalse(Object o) {
        return o == null || isFalse(o);
    }

    public static Boolean isNullOrEq(Object x, Object y) {
        return x == null || eq(x, y);
    }

    public static Boolean isNullOrNeq(Object x, Object y) {
        return x == null || neq(x, y);
    }

    public static Boolean isNullOrGt(Object x, Object y) {
        return x == null || gt(x, y);
    }

    public static Boolean isNullOrGteq(Object x, Object y) {
        return x == null || gteq(x, y);
    }

    public static Boolean isNullOrLt(Object x, Object y) {
        return x == null || lt(x, y);
    }

    public static Boolean isNullOrLteq(Object x, Object y) {
        return x == null || lteq(x, y);
    }

    public static Boolean isNullOrStartsWith(Object x, Object y) {
        return x == null || startsWith(x, y);
    }

    public static Boolean isNullOrNotStartsWith(Object x, Object y) {
        return x == null || notStartsWith(x, y);
    }

    public static Boolean isNullOrContains(Object x, Object y) {
        return x == null || contains(x, y);
    }

    public static Boolean isNullOrNotContains(Object x, Object y) {
        return x == null || notContains(x, y);
    }

    public static Boolean isNullOrEndsWith(Object x, Object y) {
        return x == null || endsWith(x, y);
    }

    public static Boolean isNullOrNotEndsWith(Object x, Object y) {
        return x == null || notEndsWith(x, y);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="data aggregate expression methods">
    public static Object coalesce(Object... objects) {
        for (Object obj : objects) {
            if (obj != null) {
                return obj;
            }
        }
        return null;
    }

    public static Long count(Object... objects) {
        long i = 0;
        for (Object obj : objects) {
            if (obj != null) {
                i++;
            }
        }
        return i;
    }

    public static Object maximum(Object... objects) {
        Object max = null;
        for (Object obj : objects) {
            if (obj != null) {
                max = max == null ? obj : gt(obj, max) ? obj : max;
            }
        }
        return max;
    }

    public static Object minimum(Object... objects) {
        Object min = null;
        for (Object obj : objects) {
            if (obj != null) {
                min = min == null ? obj : lt(obj, min) ? obj : min;
            }
        }
        return min;
    }

    public static Boolean and(Object... objects) {
        for (Object obj : objects) {
            if (isTrue(obj)) {
                continue;
            }
            return false;
        }
        return true;
    }

    public static Boolean nand(Object... objects) {
        return !and(objects);
    }

    public static Boolean or(Object... objects) {
        for (Object obj : objects) {
            if (isTrue(obj)) {
                return true;
            }
        }
        return false;
    }

    public static Boolean nor(Object... objects) {
        return !or(objects);
    }

    public static Boolean naxor(Object... objects) {
        boolean b = false;
        for (Object obj : objects) {
            if (isTrue(obj)) {
                if (b) {
                    return false;
                }
                b = true;
            }
        }
        return b;
    }

    public static Boolean naxnor(Object... objects) {
        return !naxor(objects);
    }

    public static Boolean norOrNaxor(Object... objects) {
        return nor(objects) || naxor(objects);
    }

    public static String concat(Object... objects) {
        String string = "";
        for (Object obj : objects) {
            if (obj instanceof String) {
                string += obj;
            }
            return null;
        }
        return string;
    }

    public static BigDecimal sum(Object... objects) {
        BigDecimal result = BigDecimal.ZERO;
        BigDecimal augend;
        for (Object obj : objects) {
            augend = NumUtils.numberToBigDecimal(obj);
            if (augend == null) {
                return null;
            }
            result.add(augend);
        }
        return result;
    }

    public static BigDecimal product(Object... objects) {
        BigDecimal result = BigDecimal.ONE;
        BigDecimal multiplicand;
        int i = 0;
        for (Object obj : objects) {
            multiplicand = NumUtils.numberToBigDecimal(obj);
            if (multiplicand == null) {
                return null;
            }
            i++;
            result.multiply(multiplicand);
        }
        return i > 1 ? result : null;
    }

    public static BigDecimal average(Object... objects) {
        long count = count(objects);
        BigDecimal divisor = count == 0 ? null : BigDecimal.valueOf(count);
        BigDecimal dividend = divisor == null ? null : sum(objects);
        BigDecimal result = dividend == null ? null : dividend.divide(divisor);
        return result;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="ordered-pair expression methods">
    public static Object nullif(Object x, Object y) {
        return eq(x, y) ? null : x;
    }

    public static Boolean xor(Object x, Object y) {
        return !isTrue(x) && isTrue(y) || isTrue(x) && !isTrue(y);
    }

    public static Boolean xnor(Object x, Object y) {
        return !xor(x, y);
    }

    public static Boolean xImpliesY(Object x, Object y) {
        return !isTrue(x) || isTrue(y);
    }

    public static BigDecimal xPlusY(Object x, Object y) {
        BigDecimal bx = NumUtils.numberToBigDecimal(x);
        BigDecimal by = bx == null ? null : NumUtils.numberToBigDecimal(y);
        return bx == null || by == null ? null : bx.add(by);
    }

    public static BigDecimal xMinusY(Object x, Object y) {
        BigDecimal bx = NumUtils.numberToBigDecimal(x);
        BigDecimal by = bx == null ? null : NumUtils.numberToBigDecimal(y);
        return bx == null || by == null ? null : bx.subtract(by);
    }

    public static BigDecimal xMultipliedByY(Object x, Object y) {
        BigDecimal bx = NumUtils.numberToBigDecimal(x);
        BigDecimal by = bx == null ? null : NumUtils.numberToBigDecimal(y);
        return bx == null || by == null ? null : bx.multiply(by);
    }

    public static BigDecimal xDividedIntoY(Object x, Object y) {
        BigDecimal bx = NumUtils.numberToBigDecimal(x);
        BigDecimal by = bx == null ? null : NumUtils.numberToBigDecimal(y);
        return bx == null || by == null ? null : bx.divide(by);
    }

    public static BigDecimal xRaisedToTheY(Object x, Object y) {
        BigDecimal bx = NumUtils.numberToBigDecimal(x);
        Integer iy = bx == null ? null : NumUtils.numberToInteger(y);
        return bx == null || iy == null ? null : bx.pow(iy);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="scalar expression methods">
    public static Boolean not(Object o) {
        return o != null && !toBoolean(o);
    }

    public static String lower(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : string.toLowerCase();
    }

    public static String upper(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : string.toUpperCase();
    }

    public static String capitalize(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : StringUtils.capitalize(string);
    }

    public static String uncapitalize(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : StringUtils.uncapitalize(string);
    }

    public static String trim(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : string.trim();
    }

    public static String ltrim(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : StrUtils.ltrim(string);
    }

    public static String rtrim(Object o) {
        String string = o instanceof String ? ((String) o) : null;
        return string == null ? null : StrUtils.rtrim(string);
    }

    public static Number modulus(Object o) {
        if (o == null) {
            return null;
        } else if (o instanceof Byte) {
            Byte pdq = (Byte) o;
            return NumUtils.newByte(Math.abs(pdq));
        } else if (o instanceof Short) {
            Short pdq = (Short) o;
            return NumUtils.newShort(Math.abs(pdq));
        } else if (o instanceof Integer) {
            Integer pdq = (Integer) o;
            return Math.abs(pdq);
        } else if (o instanceof Long) {
            Long pdq = (Long) o;
            return Math.abs(pdq);
        } else if (o instanceof Float) {
            Float pdq = (Float) o;
            return Math.abs(pdq);
        } else if (o instanceof Double) {
            Double pdq = (Double) o;
            return Math.abs(pdq);
        } else if (o instanceof BigInteger) {
            BigInteger pdq = (BigInteger) o;
            return pdq.abs();
        } else if (o instanceof BigDecimal) {
            BigDecimal pdq = (BigDecimal) o;
            return pdq.abs();
        }
        return null;
    }

    public static Number opposite(Object o) {
        if (o == null) {
            return null;
        } else if (o instanceof Byte) {
            Byte pdq = (Byte) o;
            return NumUtils.newByte(0 - pdq);
        } else if (o instanceof Short) {
            Short pdq = (Short) o;
            return NumUtils.newShort(0 - pdq);
        } else if (o instanceof Integer) {
            Integer pdq = (Integer) o;
            return 0 - pdq;
        } else if (o instanceof Long) {
            Long pdq = (Long) o;
            return 0L - pdq;
        } else if (o instanceof Float) {
            Float pdq = (Float) o;
            return 0.0F - pdq;
        } else if (o instanceof Double) {
            Double pdq = (Double) o;
            return 0.0D - pdq;
        } else if (o instanceof BigInteger) {
            BigInteger pdq = (BigInteger) o;
            return BigInteger.ZERO.subtract(pdq);
        } else if (o instanceof BigDecimal) {
            BigDecimal pdq = (BigDecimal) o;
            return BigDecimal.ZERO.subtract(pdq);
        }
        return null;
    }

    public static BigDecimal reciprocal(Object o) {
        BigDecimal pdq = NumUtils.numberToBigDecimal(o);
        return pdq == null || pdq.equals(BigDecimal.ZERO) ? null : BigDecimal.ONE.divide(pdq);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="generic methods">
    public static <X> X coalesceX(X... objects) {
        return (X) coalesce(objects);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="web components">
    public static void setComponentValue(UIComponent component, Object value) {
        if (component == null) {
        } else if (component instanceof TextField) {
            Object valor = value instanceof Recurso ? stringOf(value) : value;
            ((TextField) component).setText(valor);
        } else if (component instanceof DropDown) {
            Object valor = value instanceof Recurso ? numberOf(value) : value;
            ((DropDown) component).setSelected(valor);
        } else if (component instanceof Checkbox) {
            Boolean valor = BitUtils.newBoolean(value);
            ((Checkbox) component).setSelected(valor);
        } else if (component instanceof Calendar) {
            ((Calendar) component).setText(value);
        } else if (component instanceof Upload) {
            ((Upload) component).setText(value);
        } else if (component instanceof PasswordField) {
            ((PasswordField) component).setPassword(value);
        }
    }

    private static String stringOf(Object o) {
        if (o instanceof String) {
            return (String) o;
        } else if (o instanceof RecursoCodificable) {
            return StringUtils.trimToNull(((RecursoCodificable) o).getCodigoRecurso());
        } else if (o instanceof RecursoNombrable) {
            return StringUtils.trimToNull(((RecursoNombrable) o).getNombreRecurso());
        } else {
            return null;
        }
    }

    private static Number numberOf(Object o) {
        if (o instanceof Number) {
            return (Number) o;
        } else if (o instanceof RecursoIdentificable) {
            return ((RecursoIdentificable) o).getIdentificacionRecurso();
        } else if (o instanceof RecursoEnumerable) {
            return ((RecursoEnumerable) o).getNumeroRecurso();
        } else {
            return null;
        }
    }

    private static boolean invalidUIInput(Object o) {
        return o instanceof UIInput && !((UIInput) o).isValid();
    }
    // </editor-fold>

}