diff --git a/src/main/java/info/bukova/isspst/StringUtils.java b/src/main/java/info/bukova/isspst/StringUtils.java
index 5292bb87..cd418556 100644
--- a/src/main/java/info/bukova/isspst/StringUtils.java
+++ b/src/main/java/info/bukova/isspst/StringUtils.java
@@ -2,55 +2,74 @@ package info.bukova.isspst;
import org.zkoss.util.resource.Labels;
-public class StringUtils {
+public class StringUtils
+{
- public static String nullStr(String str) {
+ private static String nullStr(String str)
+ {
return str == null ? "" : str;
}
-
- public static String not0ToStr(long i) {
+
+ private static String not0ToStr(long i)
+ {
return i == 0 ? "" : String.valueOf(i);
}
-
- public static String localizeDbErr(String sqlError) {
+
+ public static String localizeDbErr(String sqlError)
+ {
String splitMessage[] = sqlError.split("'");
String message = "";
-
- for (int i = 0; i < splitMessage.length; i++) {
- if (i % 2 == 0) {
+
+ for (int i = 0; i < splitMessage.length; i++)
+ {
+ if (i % 2 == 0)
+ {
message += getLocalized(splitMessage[i]);
- } else {
+ }
+ else
+ {
message += " '" + splitMessage[i] + "' ";
}
}
-
+
return message;
}
-
- public static String localize(String key) {
+
+ public static String localize(String key)
+ {
return Labels.getLabel(key) == null ? key : Labels.getLabel(key);
}
-
- private static String getLocalized(String str) {
+
+ private static String getLocalized(String str)
+ {
String words[] = str.split(" ");
String key = "";
-
- for (String word: words) {
- if (!word.isEmpty()) {
+
+ for (String word : words)
+ {
+ if (!word.isEmpty())
+ {
key += word.substring(0, 1).toUpperCase() + word.substring(1);
}
}
-
+
return Labels.getLabel("Db" + key);
}
-
+
public static boolean isEqualForFilter(String value, String search)
{
value = StringUtils.nullStr(value).toLowerCase();
search = StringUtils.nullStr(search).toLowerCase();
- return value.contains(search);
+ return value.startsWith(search);
}
-
+
+ public static boolean isIcEqualForFilter(long value, long search)
+ {
+ String compareValue = StringUtils.not0ToStr(value);
+ String searchValue = StringUtils.not0ToStr(search);
+ return compareValue.startsWith(searchValue);
+ }
+
public static String encodeSpecialChars(String value)
{
if (value != null)
@@ -58,7 +77,7 @@ public class StringUtils {
value = value.replace("²", "[up]2[/up]");
value = value.replace("³", "[up]3[/up]");
}
-
+
return value;
}
@@ -69,7 +88,7 @@ public class StringUtils {
value = value.replace("[up]2[/up]", "²");
value = value.replace("[up]3[/up]", "³");
}
-
+
return value;
}
}
diff --git a/src/main/java/info/bukova/isspst/filters/AddressFilter.java b/src/main/java/info/bukova/isspst/filters/AddressFilter.java
index 3d876111..83de2ab7 100644
--- a/src/main/java/info/bukova/isspst/filters/AddressFilter.java
+++ b/src/main/java/info/bukova/isspst/filters/AddressFilter.java
@@ -1,7 +1,6 @@
package info.bukova.isspst.filters;
-import static info.bukova.isspst.StringUtils.not0ToStr;
-import static info.bukova.isspst.StringUtils.nullStr;
+import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.Address;
import org.hamcrest.Description;
@@ -31,13 +30,15 @@ public class AddressFilter implements Filter
{
}
@Override
- public boolean matchesSafely(Address item) {
- return nullStr(item.getCompany()).toLowerCase().contains(nullStr(condAddress.getCompany()).toLowerCase())
- && nullStr(item.getCity()).toLowerCase().contains(nullStr(condAddress.getCity()).toLowerCase())
- && nullStr(item.getContactName()).toLowerCase().contains(nullStr(condAddress.getContactName()).toLowerCase())
- && nullStr(item.getStreet()).toLowerCase().contains(nullStr(condAddress.getStreet()).toLowerCase())
- && not0ToStr(item.getIc()).startsWith(not0ToStr(condAddress.getIc()))
- && nullStr(item.getHouseNumber()).startsWith(nullStr(condAddress.getHouseNumber()));
+ public boolean matchesSafely(Address item)
+ {
+ boolean companyIsEqual = StringUtils.isEqualForFilter(item.getCompany(), condAddress.getCompany());
+ boolean cityIsEqual = StringUtils.isEqualForFilter(item.getCity(), condAddress.getCity());
+ boolean contactNameIsEqual = StringUtils.isEqualForFilter(item.getContactName(), condAddress.getContactName());
+ boolean streetIsEqual = StringUtils.isEqualForFilter(item.getStreet(), condAddress.getStreet());
+ boolean icIsEqual = StringUtils.isIcEqualForFilter(item.getIc(), condAddress.getIc());
+ boolean houseNumberIsEqual = StringUtils.isEqualForFilter(item.getHouseNumber(), condAddress.getHouseNumber());
+ return (companyIsEqual && cityIsEqual && contactNameIsEqual && streetIsEqual && icIsEqual && houseNumberIsEqual);
}
@Factory
diff --git a/src/main/java/info/bukova/isspst/filters/BuildingFilter.java b/src/main/java/info/bukova/isspst/filters/BuildingFilter.java
index 8122546e..cab56a30 100644
--- a/src/main/java/info/bukova/isspst/filters/BuildingFilter.java
+++ b/src/main/java/info/bukova/isspst/filters/BuildingFilter.java
@@ -1,6 +1,6 @@
package info.bukova.isspst.filters;
-import static info.bukova.isspst.StringUtils.nullStr;
+import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.Building;
import org.hamcrest.Description;
@@ -30,10 +30,12 @@ public class BuildingFilter implements Filter {
}
@Override
- public boolean matchesSafely(Building item) {
- return nullStr(item.getCode()).toLowerCase().contains(nullStr(condBuilding.getCode()).toLowerCase())
- && nullStr(item.getName()).toLowerCase().contains(nullStr(condBuilding.getName()).toLowerCase())
- && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condBuilding.getDescription()).toLowerCase());
+ public boolean matchesSafely(Building item)
+ {
+ boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condBuilding.getCode());
+ boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condBuilding.getName());
+ boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condBuilding.getDescription());
+ return (codeIsEqual && nameIsEqual && descriptionIsEqual);
}
@Factory
diff --git a/src/main/java/info/bukova/isspst/filters/ServiceItemFilter.java b/src/main/java/info/bukova/isspst/filters/ServiceItemFilter.java
index d12dc3b2..f0e36c5a 100644
--- a/src/main/java/info/bukova/isspst/filters/ServiceItemFilter.java
+++ b/src/main/java/info/bukova/isspst/filters/ServiceItemFilter.java
@@ -1,6 +1,6 @@
package info.bukova.isspst.filters;
-import static info.bukova.isspst.StringUtils.nullStr;
+import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.ServiceItem;
import org.hamcrest.Description;
@@ -30,10 +30,12 @@ public class ServiceItemFilter implements Filter {
}
@Override
- public boolean matchesSafely(ServiceItem item) {
- return nullStr(item.getCode()).toLowerCase().contains(nullStr(condServiceItem.getCode()).toLowerCase())
- && nullStr(item.getName()).toLowerCase().contains(nullStr(condServiceItem.getName()).toLowerCase())
- && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condServiceItem.getDescription()).toLowerCase());
+ public boolean matchesSafely(ServiceItem item)
+ {
+ boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condServiceItem.getCode());
+ boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condServiceItem.getName());
+ boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condServiceItem.getDescription());
+ return (codeIsEqual && nameIsEqual && descriptionIsEqual);
}
@Factory
diff --git a/src/main/java/info/bukova/isspst/filters/UserFilter.java b/src/main/java/info/bukova/isspst/filters/UserFilter.java
index c613510c..881d66be 100644
--- a/src/main/java/info/bukova/isspst/filters/UserFilter.java
+++ b/src/main/java/info/bukova/isspst/filters/UserFilter.java
@@ -1,13 +1,12 @@
package info.bukova.isspst.filters;
+import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.User;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;
-import static info.bukova.isspst.StringUtils.nullStr;
-
public class UserFilter implements Filter {
private User condUser;
@@ -30,11 +29,13 @@ public class UserFilter implements Filter {
}
@Override
- public boolean matchesSafely(User item) {
- return nullStr(item.getUsername()).toLowerCase().contains(nullStr(condUser.getUsername()).toLowerCase())
- && nullStr(item.getFirstName()).toLowerCase().contains(nullStr(condUser.getFirstName()).toLowerCase())
- && nullStr(item.getLastName()).toLowerCase().contains(nullStr(condUser.getLastName()).toLowerCase())
- && nullStr(item.getPersonalNumber()).toLowerCase().contains(nullStr(condUser.getPersonalNumber()).toLowerCase());
+ public boolean matchesSafely(User item)
+ {
+ boolean userNameIsEqual = StringUtils.isEqualForFilter(item.getUsername(), condUser.getUsername());
+ boolean firstNameIsEqual = StringUtils.isEqualForFilter(item.getFirstName(), condUser.getFirstName());
+ boolean lastNameIsEqual = StringUtils.isEqualForFilter(item.getLastName(), condUser.getLastName());
+ boolean personalNumberIsEqual = StringUtils.isEqualForFilter(item.getPersonalNumber(), condUser.getPersonalNumber());
+ return (userNameIsEqual && firstNameIsEqual && lastNameIsEqual && personalNumberIsEqual);
}
@Factory
diff --git a/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java b/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java
index ec8571d3..dce74d3e 100644
--- a/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java
+++ b/src/main/java/info/bukova/isspst/filters/WorkgroupFilter.java
@@ -1,6 +1,6 @@
package info.bukova.isspst.filters;
-import static info.bukova.isspst.StringUtils.nullStr;
+import info.bukova.isspst.StringUtils;
import info.bukova.isspst.data.Workgroup;
import org.hamcrest.Description;
@@ -30,10 +30,12 @@ public class WorkgroupFilter implements Filter {
}
@Override
- public boolean matchesSafely(Workgroup item) {
- return nullStr(item.getCode()).toLowerCase().contains(nullStr(condWorkgroup.getCode()).toLowerCase())
- && nullStr(item.getName()).toLowerCase().contains(nullStr(condWorkgroup.getName()).toLowerCase())
- && item.isCentre() == condWorkgroup.isCentre();
+ public boolean matchesSafely(Workgroup item)
+ {
+ boolean codeIsEqual = StringUtils.isEqualForFilter(item.getCode(), condWorkgroup.getCode());
+ boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condWorkgroup.getName());
+ boolean centerIsEqual = (item.isCentre() == condWorkgroup.isCentre());
+ return (codeIsEqual && nameIsEqual && centerIsEqual);
}
@Factory