All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sta.mutils.CmpUtils Maven / Gradle / Ivy

There is a newer version: 1.11
Show newest version

package com.sta.mutils;

/**
 * 

Name: CmpUtils

*

Description: Hilfsklasse zum Vergleichen von Objekten. * In dieser Klasse wurde eine Sammlung von Vergleichsmethoden zusammengestellt. *

*

Comment: ... *

*

Copyright: Copyright (c) 2020

*

Company: >StA-Soft<

* @author StA * @version 1.0 */ public class CmpUtils { /** * Die Instanz. */ private static CmpUtils myInstance = null; //=========================================================================== /** * Statische Methode, die die CmpUtils-Instanz ermittelt. Ist noch keine vorhanden, wird eine neue CmpUtils-Instanz erzeugt. * Umsetzung des Singleton-Musters. Wird f?r Beanshell ben?tigt. * @return die CmpUtils-Instanz */ public static CmpUtils getInstance() { if (myInstance == null) { myInstance = new CmpUtils(); } return myInstance; } //=========================================================================== /** * Hilfsmethode f?r diverse Stellen, an denen Objekte vergleichen werden sollen. * Ziel: Diverse compareTo-Methoden sollen (von der Zeilenanzahl her) m?glichst klein werden. * @param value1 Wert aus dem aktuellen TO (my*) * @param value2 Wert aus dem TO, was mit dem aktuellen verglichen werden * soll * @param ignorecase true: ignore case, if type is string * @return ein Wert kleiner 0 falls kleiner, gleich 0 falls gleich und gr??er * 0 falls gr??er */ public static int compare(Object value1, Object value2, boolean ignorecase) { // Elementare Vergleiche if (value1 == value2) { return 0; } if (value1 == null) // dann ist value2 != null { return -1; } if (value2 == null) // dann ist value1 != null { return 1; } // Integer-Long-Anomalie if ((value1 instanceof Long) && (value2 instanceof Integer)) { value2 = ((Integer) value2).longValue(); } else if ((value2 instanceof Long) && (value1 instanceof Integer)) { value1 = ((Integer) value1).longValue(); } // Boolean- und String-Sonderf?lle // Hinweise: // * wenn (value1 instanceof Boolean) ist, dann gilt genau genommen auch (value2 instanceof Boolean) // * wenn (value1 instanceof String) ist, dann gilt genau genommen auch (value2 instanceof String) if ((value1 instanceof Boolean) && (value2 instanceof Boolean)) { // Boolean implementiert Comparable, sodass man hier auch auf den else-Zweig zur?ckfallen k?nnte... if (!((Boolean) value1) && ((Boolean) value2)) { return -1; } if (((Boolean) value1) && !((Boolean) value2)) { return 1; } } else if ((value1 instanceof String) && (value2 instanceof String)) { // int res = Collator.getInstance().compare((String) value1, (String) value2); return ignorecase ? ((String) value1).compareToIgnoreCase((String) value2) : ((String) value1).compareTo((String) value2); } else { return ((Comparable) value1).compareTo(value2); } return 0; } /** * Hilfsmethode f?r compareTo(Object), Ziel: compareTo-Methoden der TCi sollen * (von der Zeilenanzahl her) m?glichst klein werden. * @param value1 Wert 1 * @param value2 Wert 2 * @return kleiner 0 falls value1 < value2, gleich 0 falls value1 = value2 * oder gr??er 0 falls value1 > value2 */ public static int compare(Object value1, Object value2) { return compare(value1, value2, false); } /** * Test auf Gleichheit. * @param value1 Wert 1 * @param value2 Wert 2 * @return true: value1 = value2, false: value1 != value2 */ public static boolean equals(Object value1, Object value2) { return compare(value1, value2) == 0; } /** * Test auf "kleiner". * @param value1 Wert 1 * @param value2 Wert 2 * @return true: value1 < value2, false: value1 >= value2 */ public static boolean less(Object value1, Object value2) { return compare(value1, value2) < 0; } /** * Test auf "gr??er". * @param value1 Wert 1 * @param value2 Wert 2 * @return true: value1 > value2, false: value1 <= value2 */ public static boolean greater(Object value1, Object value2) { return compare(value1, value2) > 0; } /** * in-Operator (pr?fen ob Wert in Wertemenge). * @param value0 zu pr?fender Wert * @param values Menge von Werten * @return true: ja, false: nein */ public static boolean in(Object value0, Object... values) { for (int i = 0; i < values.length; i++) { if (compare(value0, values[i]) == 0) { return true; } } return false; } //--------------------------------------------------------------------------- // Problem: Die Beanshell bekommt das in(...) scheinbar nicht in die Reihe // Daher wurden hier eine Reihe von in-Methoden mit verschieden vielen Parametern definiert. /** * in-Methode. * @param value0 Object * @param value1 Object1 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1) { return in(value0, new Object[] { value1 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2) { return in(value0, new Object[] { value1, value2 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3) { return in(value0, new Object[] { value1, value2, value3 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4) { return in(value0, new Object[] { value1, value2, value3, value4 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5) { return in(value0, new Object[] { value1, value2, value3, value4, value5 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @param value14 Object14 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13, Object value14) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @param value14 Object14 * @param value15 Object15 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13, Object value14, Object value15) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @param value14 Object14 * @param value15 Object15 * @param value16 Object16 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13, Object value14, Object value15, Object value16) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @param value14 Object14 * @param value15 Object15 * @param value16 Object16 * @param value17 Object17 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13, Object value14, Object value15, Object value16, Object value17) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16, value17 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @param value14 Object14 * @param value15 Object15 * @param value16 Object16 * @param value17 Object17 * @param value18 Object18 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13, Object value14, Object value15, Object value16, Object value17, Object value18) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16, value17, value18 }); } /** * in-Methode. * @param value0 Object * @param value1 Object1 * @param value2 Object2 * @param value3 Object3 * @param value4 Object4 * @param value5 Object5 * @param value6 Object6 * @param value7 Object7 * @param value8 Object8 * @param value9 Object9 * @param value10 Object10 * @param value11 Object11 * @param value12 Object12 * @param value13 Object13 * @param value14 Object14 * @param value15 Object15 * @param value16 Object16 * @param value17 Object17 * @param value18 Object18 * @param value19 Object19 * @return true, falls Object in Object-Menge (Object1...) */ public static boolean in(Object value0, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8, Object value9, Object value10, Object value11, Object value12, Object value13, Object value14, Object value15, Object value16, Object value17, Object value18, Object value19) { return in(value0, new Object[] { value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16, value17, value18, value19 }); } //=========================================================================== /** * Dummy-Constructor. */ protected CmpUtils() { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy