From: Roland Haeder Date: Mon, 17 Aug 2015 07:19:37 +0000 (+0200) Subject: Replace multiple-added strings/objects into MessageFormat.format() call to reduce... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8ae1f7e2ca6d24ff562846e3147e0a57a047b4ff;p=jcore.git Replace multiple-added strings/objects into MessageFormat.format() call to reduce string objects in string pool + ignored them for internationalization Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jcore/BaseFrameworkSystem.java b/src/org/mxchange/jcore/BaseFrameworkSystem.java index db3b9ed..4b6d025 100644 --- a/src/org/mxchange/jcore/BaseFrameworkSystem.java +++ b/src/org/mxchange/jcore/BaseFrameworkSystem.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; import java.util.StringTokenizer; -import java.util.logging.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.mxchange.jcore.application.Application; @@ -593,7 +592,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { Boolean value = (Boolean) method.invoke(instance); // Trace message - this.getLogger().trace("value=" + value + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N // Return value return value; @@ -625,7 +624,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { method.invoke(instance, value); // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -656,13 +655,13 @@ public class BaseFrameworkSystem implements FrameworkInterface { Method method = this.getMethodFromName(instance, targetClass, methodName); // Debug message - this.getLogger().debug("method=" + method + ",instance=" + instance); + this.getLogger().debug(MessageFormat.format("method={0},instance={1}", method, instance)); //NOI18N // Get value from field Object value = method.invoke(instance); // Trace messahe - this.getLogger().trace("value=" + value + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N // Return value return value; @@ -688,7 +687,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { Class type = this.getType(instance, targetClass, columnName); // Debug message - this.getLogger().debug("type=" + type); + this.getLogger().debug(MessageFormat.format("type={0}", type)); //NOI18N // Init object Object object = value; @@ -696,39 +695,39 @@ public class BaseFrameworkSystem implements FrameworkInterface { // Hard-coded "cast" again ... :-( // @TODO Can't we get rid of this??? switch (type.getSimpleName()) { - case "Long": // Long object + case "Long": // Long object //NOI18N object = Long.parseLong((String) value); break; - case "Float": // Float object + case "Float": // Float object //NOI18N object = Float.parseFloat((String) value); break; - case "Boolean": // Boolean object + case "Boolean": // Boolean object //NOI18N object = Boolean.parseBoolean((String) value); break; - case "String": // String object + case "String": // String object //NOI18N break; default: // Unsupported type - throw new IllegalArgumentException("value " + value + " has unsupported type " + type.getSimpleName()); + throw new IllegalArgumentException(MessageFormat.format("value {0} has unsupported type {1}", value, type.getSimpleName())); //NOI18N } // Debug message - this.getLogger().debug("object[" + object.getClass().getSimpleName() + "]=" + object); + this.getLogger().debug(MessageFormat.format("object[{0}]={1}", object.getClass().getSimpleName(), object)); //NOI18N // Get method to call Method method = this.getMethodFromName(instance, targetClass, methodName, type); // Debug message - this.getLogger().debug("method=" + method + ",instance=" + instance + ",value[" + value.getClass().getSimpleName() + "]=" + value); + this.getLogger().debug(MessageFormat.format("method={0},instance={1},value[{2}]={3}", method, instance, value.getClass().getSimpleName(), value)); //NOI18N // Get value from field method.invoke(instance, object); // Trace messahe - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -889,7 +888,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ protected void initBundle () { // Trace message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // Is the bundle set? if (bundle instanceof ResourceBundle) { @@ -901,7 +900,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { bundle = ResourceBundle.getBundle(FrameworkInterface.I18N_BUNDLE_FILE); // NOI18N // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -998,10 +997,10 @@ public class BaseFrameworkSystem implements FrameworkInterface { // Both should not be null if (key == null) { // key is null - throw new NullPointerException("key is null"); + throw new NullPointerException("key is null"); //NOI18N } else if (value == null) { // value is null - throw new NullPointerException("value is null"); + throw new NullPointerException("value is null"); //NOI18N } // Set it @@ -1044,18 +1043,18 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ protected void setValueInStoreableFromColumn (final Storeable instance, final String targetClass, final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace("instance=" + instance + ",targetClass=" + targetClass + ",columnName=" + columnName + ",value=" + value + " - CALLED!"); + this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2},value={3} - CALLED!", instance, targetClass, columnName, value)); //NOI18N // A '$' means not our field - if (columnName.startsWith("$")) { + if (columnName.startsWith("$")) { //NOI18N // Don't handle these - throw new IllegalArgumentException("columnsName contains $"); + throw new IllegalArgumentException("columnsName contains $"); //NOI18N } // Determine if the given column is boolean if (this.isBooleanField(instance, targetClass, columnName)) { // Debug message - this.getLogger().debug("Column " + columnName + " represents a boolean field."); + this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N // Yes, then call other method this.setBooleanField(instance, targetClass, this.convertColumnNameToSetterMethod(columnName), columnName, (Boolean) value); @@ -1065,13 +1064,13 @@ public class BaseFrameworkSystem implements FrameworkInterface { String methodName = this.convertColumnNameToSetterMethod(columnName); // Debug message - this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); + this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); //NOI18N // Get field this.setField(instance, targetClass, methodName, columnName, value); // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -1087,18 +1086,18 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ protected Object getValueInStoreableFromColumn (final Storeable instance, final String targetClass, final String columnName) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); + this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N // A '$' means not our field - if (columnName.startsWith("$")) { + if (columnName.startsWith("$")) { //NOI18N // Don't handle these - throw new IllegalArgumentException("columnsName contains $"); + throw new IllegalArgumentException("columnsName contains $"); //NOI18N } // Determine if the given column is boolean if (this.isBooleanField(instance, targetClass, columnName)) { // Debug message - this.getLogger().debug("Column " + columnName + " represents a boolean field."); + this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N // Yes, then call other method return this.getBooleanField(instance, targetClass, this.convertColumnNameToGetterMethod(columnName, true)); @@ -1108,13 +1107,13 @@ public class BaseFrameworkSystem implements FrameworkInterface { String methodName = this.convertColumnNameToGetterMethod(columnName, false); // Debug message - this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); + this.getLogger().debug(MessageFormat.format("methodName={0}", methodName)); //NOI18N // Get field Object value = this.getField(instance, targetClass, methodName); // Trace message - this.getLogger().trace("value=" + value + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N // Return value return value; @@ -1130,7 +1129,7 @@ public class BaseFrameworkSystem implements FrameworkInterface { */ private Class getType (final FrameworkInterface instance, final String targetClass, final String columnName) { // Trace message - this.getLogger().trace("instance=" + instance + ",targetClass=" + targetClass + ",columnName=" + columnName + " - CALLED!"); + this.getLogger().trace(MessageFormat.format("instance={0},targetClass={1},columnName={2} - CALLED!", instance, targetClass, columnName)); //NOI18N // Init field tye Class type = null; @@ -1139,12 +1138,12 @@ public class BaseFrameworkSystem implements FrameworkInterface { Field[] fields = this.getClassFromTarget(instance, targetClass).getDeclaredFields(); // Debug message - this.getLogger().debug("fields()=" + fields.length); + this.getLogger().debug("fields()=" + fields.length); //NOI18N // Search for proper field instance for (final Field field : fields) { // Debug message - this.getLogger().debug("field=" + field); + this.getLogger().debug("field=" + field); //NOI18N // Does it match? if (field.getName().equals(columnName)) { @@ -1157,11 +1156,11 @@ public class BaseFrameworkSystem implements FrameworkInterface { // type should not be null if (type == null) { // No null allowed - throw new NullPointerException("type is null"); + throw new NullPointerException("type is null"); //NOI18N } // Trace message - this.getLogger().debug("type=" + type + " - EXIT!"); + this.getLogger().debug(MessageFormat.format("type={0} - EXIT!", type)); //NOI18N // Return it return type; diff --git a/src/org/mxchange/jcore/contact/BaseContact.java b/src/org/mxchange/jcore/contact/BaseContact.java index 71a7d30..19ff281 100644 --- a/src/org/mxchange/jcore/contact/BaseContact.java +++ b/src/org/mxchange/jcore/contact/BaseContact.java @@ -305,7 +305,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { */ @Override public final void setFamilyName (final String familyName) { - /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); + /* NOISY-DEBUG: */ this.getLogger().trace(MessageFormat.format("familyName={0} - CALLED!", familyName)); //NOI18N this.familyName = familyName; } @@ -453,34 +453,34 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { @Override public Object getValueFromColumn (final String columnName) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); + this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N // A '$' means not our field - if (columnName.startsWith("$")) { + if (columnName.startsWith("$")) { //NOI18N // Don't handle these - throw new IllegalArgumentException("columnsName contains $"); + throw new IllegalArgumentException("columnsName contains $"); //NOI18N } // Determine if the given column is boolean - if (this.isBooleanField(this, "BaseContact", columnName)) { + if (this.isBooleanField(this, "BaseContact", columnName)) { //NOI18N // Debug message - this.getLogger().debug("Column " + columnName + " represents a boolean field."); + this.getLogger().debug(MessageFormat.format("Column {0} represents a boolean field.", columnName)); //NOI18N // Yes, then call other method - return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true)); + return this.getBooleanField(this, "BaseContact", this.convertColumnNameToGetterMethod(columnName, true)); //NOI18N } // Convert column name to field name String methodName = this.convertColumnNameToGetterMethod(columnName, false); // Debug message - this.getLogger().debug(MessageFormat.format("field={0}", methodName)); + this.getLogger().debug(MessageFormat.format("field={0}", methodName)); //NOI18N // Get field - Object value = this.getField(this, "BaseContact", methodName); + Object value = this.getField(this, "BaseContact", methodName); //NOI18N // Trace message - this.getLogger().trace("value=" + value + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N // Return it return value; @@ -509,7 +509,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { @Override public int hashCode () { // Validate gender instance - assert (this.getGender() instanceof Gender) : "gender is not set."; + assert (this.getGender() instanceof Gender) : "gender is not set."; //NOI18N int hash = 7; hash = 79 * hash + Objects.hashCode(this.getFamilyName()); @@ -538,25 +538,25 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { @Override public boolean isFieldValueEqual (final String columnName, final boolean bool) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool)); + this.getLogger().trace(MessageFormat.format("columnName={0},bool={1} - CALLED!", columnName, bool)); //NOI18N // Convert column name to field name String methodName = this.convertColumnNameToGetterMethod(columnName, true); // Debug message - this.getLogger().debug(MessageFormat.format("field={0}", methodName)); + this.getLogger().debug(MessageFormat.format("field={0}", methodName)); //NOI18N // Init class instance - boolean value = this.getBooleanField(this, "BaseContact", methodName); + boolean value = this.getBooleanField(this, "BaseContact", methodName); //NOI18N // Debug message - this.getLogger().debug(MessageFormat.format("value={0}", value)); + this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N // Compare it boolean isFound = (bool == value); // Trace message - this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); + this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N // Return result return isFound; @@ -568,7 +568,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { */ @Override public Iterator> iterator () throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - return this.fieldIterator(this, "BaseContact"); + return this.fieldIterator(this, "BaseContact"); //NOI18N } /** @@ -584,7 +584,7 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { // The client must be set if (client == null) { // Not set - throw new NullPointerException("client is null"); + throw new NullPointerException("client is null"); //NOI18N } // Display name "box" @@ -608,12 +608,12 @@ public class BaseContact extends BaseFrameworkSystem implements Contact { @Override public void setValueFromColumn (final String columnName, final Object value) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value)); + this.getLogger().trace(MessageFormat.format("columnName={0},value={1} - CALLED!", columnName, value)); //NOI18N // Call super method - this.setValueInStoreableFromColumn(this, "BaseContact", columnName, value); + this.setValueInStoreableFromColumn(this, "BaseContact", columnName, value); //NOI18N // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } } diff --git a/src/org/mxchange/jcore/criteria/BaseCriteria.java b/src/org/mxchange/jcore/criteria/BaseCriteria.java index 0846504..469404b 100644 --- a/src/org/mxchange/jcore/criteria/BaseCriteria.java +++ b/src/org/mxchange/jcore/criteria/BaseCriteria.java @@ -58,11 +58,25 @@ public class BaseCriteria extends BaseFrameworkSystem implements Criteria { this.criteria.put(key, value); } + @Override + public void addCriteria (final String key, final Number value) { + this.criteria.put(key, value); + } + @Override public Set> entrySet () { return this.criteria.entrySet(); } + /** + * Setter for Logical instance + * + * @param logcial the Logical instance to set + */ + public final void setLogcial (final Logical logcial) { + this.logcial = logcial; + } + @Override public Iterable values () { // Call map's method @@ -78,18 +92,4 @@ public class BaseCriteria extends BaseFrameworkSystem implements Criteria { protected final Logical getLogical () { return this.logcial; } - - /** - * Setter for Logical instance - * - * @param logcial the Logical instance to set - */ - public final void setLogcial (final Logical logcial) { - this.logcial = logcial; - } - - @Override - public void addCriteria (final String key, final Number value) { - this.criteria.put(key, value); - } } diff --git a/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java b/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java index e217f09..d8f0bf6 100644 --- a/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java +++ b/src/org/mxchange/jcore/criteria/searchable/SearchCriteria.java @@ -16,7 +16,6 @@ */ package org.mxchange.jcore.criteria.searchable; -import org.mxchange.jcore.criteria.logical.Logical; import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.HashMap; @@ -69,21 +68,21 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { @Override public boolean matches (final Storeable storeable) throws IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("storeable={0} - CALLED!", storeable)); + this.getLogger().trace(MessageFormat.format("storeable={0} - CALLED!", storeable)); //NOI18N // Must not be null if (storeable == null) { // Abort here - throw new NullPointerException("storeable is null"); + throw new NullPointerException("storeable is null"); //NOI18N } // Debug message - this.getLogger().debug("this.entrySet().size()=" + this.entrySet().size()); + this.getLogger().debug("this.entrySet().size()=" + this.entrySet().size()); //NOI18N //NOI18N // No matches found? if (this.entrySet().isEmpty()) { // Debug message - this.getLogger().debug("No criteria set, returning true ..."); + this.getLogger().debug("No criteria set, returning true ..."); //NOI18N // Then there is nothing to match! return true; @@ -95,18 +94,18 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { // Check all conditions for (final Map.Entry criteria : this.entrySet()) { // Debug message - this.getLogger().debug(MessageFormat.format("criteria: key={0},value[{1}]={2}", criteria.getKey(), criteria.getValue().getClass().getSimpleName(), criteria.getValue())); + this.getLogger().debug(MessageFormat.format("criteria: key={0},value[{1}]={2}", criteria.getKey(), criteria.getValue().getClass().getSimpleName(), criteria.getValue())); //NOI18N // Get value from column name Object value = storeable.getValueFromColumn(criteria.getKey()); // Debug message - this.getLogger().debug("value[" + value.getClass().getSimpleName() + "]=" + value); + this.getLogger().debug(MessageFormat.format("value[{0}]={1}", value.getClass().getSimpleName(), value)); //NOI18N // Is both same? if (value.equals(criteria.getValue())) { // Debug message - this.getLogger().debug("value=" + value + " - MATCHES!"); + this.getLogger().debug(MessageFormat.format("value={0} - MATCHES!", value)); //NOI18N // Matching criteria found criteraMatches.put(criteria.getKey(), true); @@ -122,14 +121,14 @@ public class SearchCriteria extends BaseCriteria implements SearchableCriteria { matches = (criteraMatches.size() == 1); } else if (this.getLogical() == null) { // Logical instance is null - throw new NullPointerException("logical is not set, but more than one column shall be matched."); + throw new NullPointerException("logical is not set, but more than one column shall be matched."); //NOI18N } else { // Now for the final test matches = this.getLogical().matches(this.entrySet(), criteraMatches); } // Trace message - this.getLogger().trace(MessageFormat.format("matches={0} - EXIT!", matches)); + this.getLogger().trace(MessageFormat.format("matches={0} - EXIT!", matches)); //NOI18N // Return result return matches; diff --git a/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java index 04b9b0c..3295325 100644 --- a/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/base64/Base64CsvDatabaseBackend.java @@ -107,19 +107,19 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat @Override public Result doInsertDataSet (final Map dataset) throws IOException { // Trace message - this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); + this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); //NOI18N // dataset should not be null and not empty if (dataset == null) { // It is null, so abort here - throw new NullPointerException("dataset is null"); + throw new NullPointerException("dataset is null"); //NOI18N } else if (dataset.isEmpty()) { // It is empty, also abort here - throw new IllegalArgumentException("dataset is empty"); + throw new IllegalArgumentException("dataset is empty"); //NOI18N } // Debug message - this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size())); + this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size())); //NOI18N // Get iterator from it Iterator> iterator = dataset.entrySet().iterator(); @@ -128,7 +128,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat StringBuilder output = new StringBuilder(dataset.size() * 20); // Add index column - output.append(String.format("key=%s,value=\"%s\";", this.getFrontend().getIdName(), this.getTotalRows() + 1)); + output.append(String.format("key=%s,value=\"%s\";", this.getFrontend().getIdName(), this.getTotalRows() + 1)); //NOI18N // "Walk" over all entries while (iterator.hasNext()) { @@ -144,17 +144,17 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat String str = (String) value; // Does it contain a " ? - if (str.contains("\"")) { + if (str.contains("\"")) { //NOI18N // Don't accept here - throw new IllegalArgumentException("value " + value + " with double-quote not supported yet."); + throw new IllegalArgumentException(MessageFormat.format("value {0} with double-quote not supported yet.", value)); //NOI18N } } // Generate key=value pair - String pair = String.format("key=%s,value=\"%s\";", entry.getKey(), String.valueOf(value)); + String pair = String.format("key=%s,value=\"%s\";", entry.getKey(), String.valueOf(value)); //NOI18N // Debug message - this.getLogger().debug("pair=" + pair); + this.getLogger().debug(MessageFormat.format("pair={0}", pair)); //NOI18N // Append to output output.append(pair); @@ -167,7 +167,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat Result result = new DatabaseResult(); // Trace message - this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); + this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N // Return it return result; @@ -176,7 +176,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat @Override public Result doSelectByCriteria (final SearchableCriteria critera) throws IOException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { // Trace message - this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); + this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); //NOI18N // Init result instance Result result = new DatabaseResult(); @@ -190,7 +190,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat String line = this.readLine(); // Debug message - this.getLogger().debug(MessageFormat.format("line={0}", line)); + this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N // Parse it to a Map Map map = this.getMapFromLine(line); @@ -199,7 +199,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat Storeable storeable = this.getFrontend().toStoreable(map); // Debug message - this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); + this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); //NOI18N // Now matches the found instance if (critera.matches(storeable)) { @@ -333,28 +333,28 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat */ private void writeData (final StringBuilder output) throws IOException { // Trace message - this.getLogger().trace("output=" + output + " - CALLED!"); + this.getLogger().trace(MessageFormat.format("output={0} - CALLED!", output)); //NOI18N // No null or empty strings if (output == null) { // Is null - throw new NullPointerException("output is null"); + throw new NullPointerException("output is null"); //NOI18N } else if (output.length() == 0) { // Is empty - throw new IllegalArgumentException("output is empty"); + throw new IllegalArgumentException("output is empty"); //NOI18N } // Encode it to BASE64 String rawOutput = Base64.encodeBase64String(output.toString().getBytes()); // Debug message - this.getLogger().debug("rawOutput=" + rawOutput); + this.getLogger().debug(MessageFormat.format("rawOutput={0}", rawOutput)); //NOI18N // Write each line separately - this.getStorageFile().writeBytes(rawOutput + "\n"); + this.getStorageFile().writeBytes(String.format("%s\n", rawOutput)); //NOI18N // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -367,42 +367,42 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat */ private Map getMapFromLine (final String line) throws CorruptedDatabaseFileException, BadTokenException { // Trace message - this.getLogger().debug("line=" + line + " - CALLED!"); + this.getLogger().debug(MessageFormat.format("line={0} - CALLED!", line)); //NOI18N // "line" must not be null or empty if (line == null) { // Is null - throw new NullPointerException("line is null"); + throw new NullPointerException("line is null"); //NOI18N } else if (line.isEmpty()) { // Is empty - throw new IllegalArgumentException("line is empty, maybe isEndOfFile() was not called?"); - } else if (!line.endsWith(";")) { + throw new IllegalArgumentException("line is empty, maybe isEndOfFile() was not called?"); //NOI18N + } else if (!line.endsWith(";")) { //NOI18N // Bad line found - throw new CorruptedDatabaseFileException(this.fileName, "No semicolon at end of line"); - } else if (!line.contains("key=")) { + throw new CorruptedDatabaseFileException(this.fileName, "No semicolon at end of line"); //NOI18N + } else if (!line.contains("key=")) { //NOI18N // Bad line found - throw new CorruptedDatabaseFileException(this.fileName, "No \"key=bla\" found."); - } else if (!line.contains("value=")) { + throw new CorruptedDatabaseFileException(this.fileName, "No \"key=bla\" found."); //NOI18N + } else if (!line.contains("value=")) { //NOI18N // Bad line found - throw new CorruptedDatabaseFileException(this.fileName, "No \"value=bla\" found."); + throw new CorruptedDatabaseFileException(this.fileName, "No \"value=bla\" found."); //NOI18N } - Pattern pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";){1,}"); + Pattern pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";){1,}"); //NOI18N Matcher matcher = pattern.matcher(line); // Debug message - this.getLogger().debug("matches=" + matcher.matches()); + this.getLogger().debug(MessageFormat.format("matches={0}", matcher.matches())); //NOI18N // Matches? if (!matcher.matches()) { // Corrupted file found - throw new CorruptedDatabaseFileException(this.fileName, "line " + line + " doesn't match regular expression."); + throw new CorruptedDatabaseFileException(this.fileName, MessageFormat.format("line {0} doesn't match regular expression.", line)); //NOI18N } // Instance map Map map = new HashMap<>(line.length() / 40); - pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";)"); + pattern = Pattern.compile("(key=([a-z0-9_]{1,}),value=\"([^\"]*)\";)"); //NOI18N matcher = pattern.matcher(line); // Init group count @@ -416,14 +416,14 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat String value = matcher.group(3); // key must noch be empty - assert((key != null) && (!key.isEmpty())) : "key=" + key + " is not valid"; + assert((key != null) && (!key.isEmpty())) : MessageFormat.format("key={0} is not valid", key); //NOI18N // Get start and end int start = matcher.start(); int end = matcher.end(); // Debug message - this.getLogger().debug("init=" + init + ",start=" + start + ",end=" + end + ",match=" + match + ",key=" + key + ",value=" + value); + this.getLogger().debug(MessageFormat.format("init={0},start={1},end={2},match={3},key={4},value={5}", init, start, end, match, key, value)); //NOI18N // Add key/value to map map.put(key, value); @@ -433,7 +433,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat } // Trace message - this.getLogger().trace("map()=" + map.size() + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("map()={0} - EXIT!", map.size())); //NOI18N // Return finished map return map; @@ -442,7 +442,7 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat @Override public final Long getTotalRows () throws IOException { // Trace message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // Init count Long count = 0L; @@ -455,12 +455,15 @@ public class Base64CsvDatabaseBackend extends BaseDatabaseBackend implements Dat // Get next line String line = this.readLine(); + // Debug message + this.getLogger().debug(MessageFormat.format("line={0}", line)); //NOI18N + // Count one up count++; } // Trace message - this.getLogger().trace("count=" + count + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("count={0} - EXIT!", count)); //NOI18N // Return it return count; diff --git a/src/org/mxchange/jcore/database/backend/file/DatabaseFile.java b/src/org/mxchange/jcore/database/backend/file/DatabaseFile.java index 1623d3f..40b4434 100644 --- a/src/org/mxchange/jcore/database/backend/file/DatabaseFile.java +++ b/src/org/mxchange/jcore/database/backend/file/DatabaseFile.java @@ -40,7 +40,7 @@ public class DatabaseFile extends BaseFrameworkSystem implements Synchronizeable */ public DatabaseFile (final String fqfn) throws FileNotFoundException { // Init it here - this.file = new RandomAccessFile(fqfn, "rw"); + this.file = new RandomAccessFile(fqfn, "rw"); //NOI18N } @Override diff --git a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java index 7cf84b2..b081ca8 100644 --- a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java @@ -118,7 +118,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas this.getLogger().debug("Connection is up, preparing some statements ..."); //NOI18N // Set prepared statement - this.totalRows = connection.prepareStatement(String.format("SELECT COUNT(`%s`) AS `cnt` FROM `%s` LIMIT 1", this.getFrontend().getIdName(), this.getTableName())); + this.totalRows = connection.prepareStatement(String.format("SELECT COUNT(`%s`) AS `cnt` FROM `%s` LIMIT 1", this.getFrontend().getIdName(), this.getTableName())); //NOI18N // Trace message this.getLogger().trace("EXIT!"); //NOI18N @@ -136,26 +136,26 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas @Override public Result doInsertDataSet (final Map dataset) throws SQLException { // Trace message - this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); + this.getLogger().trace(MessageFormat.format("dataset={0} - CALLED!", dataset)); //NOI18N // dataset should not be null and not empty if (dataset == null) { // It is null, so abort here - throw new NullPointerException("dataset is null"); + throw new NullPointerException("dataset is null"); //NOI18N } else if (dataset.isEmpty()) { // It is empty, also abort here - throw new IllegalArgumentException("dataset is empty"); + throw new IllegalArgumentException("dataset is empty"); //NOI18N } // Debug message - this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size())); + this.getLogger().debug(MessageFormat.format("Need to parse {0} values ...", dataset.size())); //NOI18N // Init values Set values = new LinkedHashSet<>(dataset.size()); // Start with INSERT INTO - StringBuilder query = new StringBuilder(String.format("INSERT INTO `%s` (", this.getTableName())); - StringBuilder valueQuery = new StringBuilder("("); + StringBuilder query = new StringBuilder(String.format("INSERT INTO `%s` (", this.getTableName())); //NOI18N + StringBuilder valueQuery = new StringBuilder("("); //NOI18N // Get iterator from it Iterator> iterator = dataset.entrySet().iterator(); @@ -166,38 +166,38 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas Map.Entry entry = iterator.next(); // Add key as database column to query - query.append(String.format("`%s`,", entry.getKey())); + query.append(String.format("`%s`,", entry.getKey())); //NOI18N // Get value Object value = entry.getValue(); // Debug message - this.getLogger().debug(MessageFormat.format("value={0} - BEFORE!", value)); + this.getLogger().debug(MessageFormat.format("value={0} - BEFORE!", value)); //NOI18N // Handle possible empty->null convertion value = this.getFrontend().emptyStringToNull(entry.getKey(), value); // Debug message - this.getLogger().debug(MessageFormat.format("value={0} - AFTER!", value)); + this.getLogger().debug(MessageFormat.format("value={0} - AFTER!", value)); //NOI18N // Is the value null? if (value == null) { // Add null - valueQuery.append("NULL,"); + valueQuery.append("NULL,"); //NOI18N } else { // Add value - valueQuery.append("?,"); + valueQuery.append("?,"); //NOI18N values.add(value); } } // Now put all together - query.replace(query.length() - 1, query.length(), ") VALUES "); + query.replace(query.length() - 1, query.length(), ") VALUES "); //NOI18N query.append(valueQuery.substring(0, valueQuery.length() - 1)); - query.append(")"); + query.append(")"); //NOI18N // Full statement is complete here, better log it - this.getLogger().debug(MessageFormat.format("query={0} is complete.", query)); + this.getLogger().debug(MessageFormat.format("query={0} is complete.", query)); //NOI18N // Prepare statement instance PreparedStatement statement = this.getPreparedStatement(query, values); @@ -206,13 +206,13 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas int status = statement.executeUpdate(); // Debug message - this.getLogger().debug(MessageFormat.format("status={0}", status)); + this.getLogger().debug(MessageFormat.format("status={0}", status)); //NOI18N // The result set needs to be transformed into Result, so initialize a result instance here Result result = new DatabaseResult(status, statement); // Trace message - this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); + this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N // Return it return result; @@ -221,16 +221,16 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas @Override public Result doSelectByCriteria (final SearchableCriteria critera) throws SQLException { // Trace message - this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); + this.getLogger().trace(MessageFormat.format("criteria={0} - CALLED!", critera)); //NOI18N // Start SELECT query - StringBuilder query = new StringBuilder(String.format("SELECT * FROM `%s`", this.getTableName())); + StringBuilder query = new StringBuilder(String.format("SELECT * FROM `%s`", this.getTableName())); //NOI18N // Get entry set Set> set = critera.entrySet(); // Debug message - this.getLogger().debug(MessageFormat.format("set.isEmpty()={0}", set.isEmpty())); + this.getLogger().debug(MessageFormat.format("set.isEmpty()={0}", set.isEmpty())); //NOI18N // Init values Set values = new LinkedHashSet<>(set.size()); @@ -238,12 +238,12 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas // Are there conditions? if (!set.isEmpty()) { // Continue with WHERE - query.append(" WHERE "); + query.append(" WHERE "); //NOI18N // No more than 1 value currently if (set.size() > 1) { // Not supported yet - throw new IllegalArgumentException("More than one criteria is not supported yet."); + throw new IllegalArgumentException("More than one criteria is not supported yet."); //NOI18N } // Get iterator @@ -255,16 +255,16 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas Map.Entry entry = iterator.next(); // Add key as column name - query.append(String.format("`%s`", entry.getKey())); + query.append(String.format("`%s`", entry.getKey())); //NOI18N // Get value Object value = entry.getValue(); // Debug message - this.getLogger().debug(MessageFormat.format("value={0}", value)); + this.getLogger().debug(MessageFormat.format("value={0}", value)); //NOI18N // Add value - query.append("=?"); + query.append("=?"); //NOI18N values.add(value); } } @@ -274,15 +274,15 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas // Is skip set? if (critera.getSkip() > 0) { // Limit with skip - query.append(String.format(" LIMIT %d,%d", critera.getSkip(), critera.getLimit())); + query.append(String.format(" LIMIT %d,%d", critera.getSkip(), critera.getLimit())); //NOI18N } else { // Only limit - query.append(String.format(" LIMIT %d", critera.getLimit())); + query.append(String.format(" LIMIT %d", critera.getLimit())); //NOI18N } } // Full statement is complete here, better log it - this.getLogger().debug(MessageFormat.format("query={0} is complete.", query)); + this.getLogger().debug(MessageFormat.format("query={0} is complete.", query)); //NOI18N // Get a prepared instance PreparedStatement statement = this.getPreparedStatement(query, values); @@ -294,7 +294,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas Result result = this.getFrontend().getResultFromSet(resultSet); // Trace message - this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); + this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N // Return it return result; @@ -318,7 +318,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas @Override public Long getTotalRows () throws IOException, SQLException { // Trace message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // Execute query ResultSet set = this.totalRows.executeQuery(); @@ -327,10 +327,10 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas set.beforeFirst(); // Get long - Long count = set.getLong("cnt"); + Long count = set.getLong("cnt"); //NOI18N // Trace message - this.getLogger().trace("count=" + count + " - EXIT!"); + this.getLogger().trace(MessageFormat.format("count={0} - EXIT!", count)); //NOI18N // Return it return count; @@ -345,13 +345,13 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas */ private PreparedStatement getPreparedStatement (final StringBuilder query, final Set values) throws SQLException { // Trace message - this.getLogger().trace("query=" + query + ",values=" + values + " - CALLED!"); + this.getLogger().trace(MessageFormat.format("query={0},values={1} - CALLED!", query, values)); //NOI18N // Init prepared statement PreparedStatement statement = connection.prepareStatement(query.toString()); // Debug message - this.getLogger().debug(MessageFormat.format("statement={0}", statement)); + this.getLogger().debug(MessageFormat.format("statement={0}", statement)); //NOI18N // Get iterator on values Iterator valueIterator = values.iterator(); @@ -365,45 +365,45 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas Object value = valueIterator.next(); //Debug message - this.getLogger().debug(MessageFormat.format("index={1} has value={0}", value, index)); + this.getLogger().debug(MessageFormat.format("index={1} has value={0}", value, index)); //NOI18N // Detect type again if (value instanceof Boolean) { // Debug log - this.getLogger().debug(MessageFormat.format("Setting boolean value={0} for index={1}", value, index)); + this.getLogger().debug(MessageFormat.format("Setting boolean value={0} for index={1}", value, index)); //NOI18N // Found boolean statement.setBoolean(index, (boolean) value); } else if (value instanceof String) { // Debug message - this.getLogger().debug(MessageFormat.format("Setting string value={0} for index={1}", value, index)); + this.getLogger().debug(MessageFormat.format("Setting string value={0} for index={1}", value, index)); //NOI18N // Found string statement.setString(index, (String) value); } else if (value instanceof Integer) { // Debug message - this.getLogger().debug(MessageFormat.format("Setting integer value={0} for index={1}", value, index)); + this.getLogger().debug(MessageFormat.format("Setting integer value={0} for index={1}", value, index)); //NOI18N // Found ineteger statement.setInt(index, (int) value); } else if (value instanceof Long) { // Debug message - this.getLogger().debug(MessageFormat.format("Setting long value={0} for index={1}", value, index)); + this.getLogger().debug(MessageFormat.format("Setting long value={0} for index={1}", value, index)); //NOI18N // Found ineteger statement.setLong(index, (long) value); } else if (value instanceof Float) { // Debug message - this.getLogger().debug(MessageFormat.format("Setting float value={0} for index={1}", value, index)); + this.getLogger().debug(MessageFormat.format("Setting float value={0} for index={1}", value, index)); //NOI18N // Found ineteger statement.setFloat(index, (float) value); } else if (value == null) { // Debug message - this.getLogger().warn(MessageFormat.format("Null value in index={0} is not supported (yet)", index)); + this.getLogger().warn(MessageFormat.format("Null value in index={0} is not supported (yet)", index)); //NOI18N } else { // Not parseable type - throw new SQLException(MessageFormat.format("Cannot handle value({0})={1} for index={2} in table {3}", value.getClass().getSimpleName(), value, index, this.getTableName())); + throw new SQLException(MessageFormat.format("Cannot handle value({0})={1} for index={2} in table {3}", value.getClass().getSimpleName(), value, index, this.getTableName())); //NOI18N } // Increment index @@ -411,7 +411,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas } // Trace message - this.getLogger().trace(MessageFormat.format("statement={0} - EXIT!", statement)); + this.getLogger().trace(MessageFormat.format("statement={0} - EXIT!", statement)); //NOI18N // Return it return statement; diff --git a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java index c5f3424..95ce0b6 100644 --- a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java +++ b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java @@ -78,19 +78,19 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement */ protected void addToDataSet (final String key, final String value) { // Trace message - this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); + this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N // Is key null? if (key == null) { // Key is null - throw new NullPointerException("key is null"); + throw new NullPointerException("key is null"); //NOI18N } // Add it to map this.dataset.put(key, value); // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -101,22 +101,22 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement */ protected void addToDataSet (final String key, final Number value) { // Trace message - this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); + this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N // Is key/value null? if (key == null) { // Key is null - throw new NullPointerException("key is null"); + throw new NullPointerException("key is null"); //NOI18N } else if (value == null) { // Key is null - throw new NullPointerException("value is null"); + throw new NullPointerException("value is null"); //NOI18N } // Add it to map this.dataset.put(key, value); // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -127,22 +127,22 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement */ protected void addToDataSet (final String key, final Boolean value) { // Trace message - this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); + this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N // Is key/value null? if (key == null) { // Key is null - throw new NullPointerException("key is null"); + throw new NullPointerException("key is null"); //NOI18N } else if (value == null) { // Key is null - throw new NullPointerException("value is null"); + throw new NullPointerException("value is null"); //NOI18N } // Add it to map this.dataset.put(key, value); // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -151,13 +151,13 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement */ protected void clearDataSet () { // Trace message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // Clear dataset this.dataset.clear(); // Trace message - this.getLogger().trace("EXIT!"); + this.getLogger().trace("EXIT!"); //NOI18N } /** @@ -171,19 +171,19 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement */ protected Result doInsertDataSet () throws SQLException, IOException { // Trace message - this.getLogger().trace("CALLED!"); + this.getLogger().trace("CALLED!"); //NOI18N // Is the dataset instance empty? if (this.dataset.isEmpty()) { // Cannot insert an empty dataset - throw new IllegalStateException("The dataset instance is empty."); + throw new IllegalStateException("The dataset instance is empty."); //NOI18N } // Call backend method Result result = this.getBackend().doInsertDataSet(this.dataset); // Trace message - this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); + this.getLogger().trace(MessageFormat.format("result={0} - EXIT!", result)); //NOI18N // Return it return result; diff --git a/src/org/mxchange/jcore/database/result/DatabaseResult.java b/src/org/mxchange/jcore/database/result/DatabaseResult.java index 038ac42..e541bfa 100644 --- a/src/org/mxchange/jcore/database/result/DatabaseResult.java +++ b/src/org/mxchange/jcore/database/result/DatabaseResult.java @@ -51,7 +51,7 @@ public class DatabaseResult extends BaseFrameworkSystem implements Result(); @@ -70,7 +70,7 @@ public class DatabaseResult extends BaseFrameworkSystem implements Result