From 97beae66777e0912db6d21f927032cbaee985fa6 Mon Sep 17 00:00:00 2001 From: Marco Zanon Date: Wed, 28 Oct 2015 14:18:44 +0000 Subject: [PATCH] Unified all the getObjectReference() and getObject() methods to only return references (not clones) to objects. --- .../macaco/conversion/MDateConverter.java | 25 +++------ .../macaco/conversion/MNumberConverter.java | 15 ++---- .../marcozanon/macaco/json/MJsonArray.java | 16 +++--- .../marcozanon/macaco/json/MJsonObject.java | 20 +++---- .../macaco/logging/MLogDatabaseTable.java | 12 ++--- .../marcozanon/macaco/logging/MLogFilter.java | 6 +-- .../macaco/logging/MLogPlainTextFile.java | 12 ++--- .../marcozanon/macaco/sql/MSqlConnection.java | 22 ++++---- .../macaco/sql/MSqlStatementResults.java | 53 ++++++------------- .../com/marcozanon/macaco/sql/MSqlTable.java | 38 ++++++------- .../marcozanon/macaco/text/MTranslator.java | 20 +++---- 11 files changed, 98 insertions(+), 141 deletions(-) diff --git a/src/java/com/marcozanon/macaco/conversion/MDateConverter.java b/src/java/com/marcozanon/macaco/conversion/MDateConverter.java index 4a53334..e9282f7 100644 --- a/src/java/com/marcozanon/macaco/conversion/MDateConverter.java +++ b/src/java/com/marcozanon/macaco/conversion/MDateConverter.java @@ -76,21 +76,12 @@ public class MDateConverter extends MObject { } } - protected LinkedHashSet getDateFormatsReference() { - return this.dateFormats; - } - public LinkedHashSet getDateFormats() { - LinkedHashSet tmpDateFormats = new LinkedHashSet(); - Iterator i = this.getDateFormatsReference().iterator(); - while (i.hasNext()) { - tmpDateFormats.add((String)i.next()); - } - return tmpDateFormats; + return this.dateFormats; } public String getDefaultDateFormat() { - return this.getDateFormatsReference().iterator().next(); + return this.getDateFormats().iterator().next(); } /* Locale. */ @@ -117,12 +108,8 @@ public class MDateConverter extends MObject { this.timeZone = timeZone; } - protected TimeZone getTimeZoneReference() { - return this.timeZone; - } - public TimeZone getTimeZone() { - return (TimeZone)this.getTimeZoneReference().clone(); + return this.timeZone; } /* Conversions. */ @@ -198,9 +185,9 @@ public class MDateConverter extends MObject { public Date getDateFromString(String x) throws MInvalidConversionFormatException { Date y = null; - for (String dateFormat: this.getDateFormatsReference()) { + for (String dateFormat: this.getDateFormats()) { try { - y = this.getDateFromStringByParameters(x, dateFormat, this.getLocale(), this.getTimeZoneReference()); + y = this.getDateFromStringByParameters(x, dateFormat, this.getLocale(), this.getTimeZone()); return y; } catch (MInvalidConversionFormatException exception) { @@ -213,7 +200,7 @@ public class MDateConverter extends MObject { } public String getStringFromDate(Date x) { - return this.getStringFromDateByParameters(x, this.getDefaultDateFormat(), this.getLocale(), this.getTimeZoneReference()); + return this.getStringFromDateByParameters(x, this.getDefaultDateFormat(), this.getLocale(), this.getTimeZone()); } /* Helpers. */ diff --git a/src/java/com/marcozanon/macaco/conversion/MNumberConverter.java b/src/java/com/marcozanon/macaco/conversion/MNumberConverter.java index 2b69a63..a266afa 100644 --- a/src/java/com/marcozanon/macaco/conversion/MNumberConverter.java +++ b/src/java/com/marcozanon/macaco/conversion/MNumberConverter.java @@ -67,21 +67,12 @@ public class MNumberConverter extends MObject { } } - protected LinkedHashSet getNumberFormatsReference() { - return this.numberFormats; - } - public LinkedHashSet getNumberFormats() { - LinkedHashSet tmpNumberFormats = new LinkedHashSet(); - Iterator i = this.getNumberFormatsReference().iterator(); - while (i.hasNext()) { - tmpNumberFormats.add((String)i.next()); - } - return tmpNumberFormats; + return this.numberFormats; } public String getDefaultNumberFormat() { - return this.getNumberFormatsReference().iterator().next(); + return this.getNumberFormats().iterator().next(); } /* Locale. */ @@ -149,7 +140,7 @@ public class MNumberConverter extends MObject { public BigDecimal getNumberFromString(String x) throws MInvalidConversionFormatException { BigDecimal y = null; - for (String numberFormat: this.getNumberFormatsReference()) { + for (String numberFormat: this.getNumberFormats()) { try { y = this.getNumberFromStringByParameters(x, numberFormat, this.getLocale()); return y; diff --git a/src/java/com/marcozanon/macaco/json/MJsonArray.java b/src/java/com/marcozanon/macaco/json/MJsonArray.java index 1b170bc..202b795 100644 --- a/src/java/com/marcozanon/macaco/json/MJsonArray.java +++ b/src/java/com/marcozanon/macaco/json/MJsonArray.java @@ -49,7 +49,7 @@ public class MJsonArray extends MJsonValue { throw new IllegalArgumentException("Invalid 'x': null."); } // - this.getValuesReference().add(x); + this.getValues().add(x); } public void setValue(int index, MJsonValue x) { @@ -60,10 +60,10 @@ public class MJsonArray extends MJsonValue { throw new IllegalArgumentException("Invalid 'x': null."); } // - this.getValuesReference().set(index, x); + this.getValues().set(index, x); } - protected LinkedList getValuesReference() { + protected LinkedList getValues() { return this.values; } @@ -72,11 +72,11 @@ public class MJsonArray extends MJsonValue { throw new IllegalArgumentException(String.format("Invalid 'index': %s: out of range.", index)); } // - return this.getValuesReference().get(index).clone(); + return this.getValues().get(index).clone(); } public int getValueCount() { - return this.getValuesReference().size(); + return this.getValues().size(); } public void removeValue(int index) { @@ -84,11 +84,11 @@ public class MJsonArray extends MJsonValue { throw new IllegalArgumentException(String.format("Invalid 'index': %s: out of range.", index)); } // - this.getValuesReference().remove(index); + this.getValues().remove(index); } public void clearValues() { - this.getValuesReference().clear(); + this.getValues().clear(); } /* Parsers. */ @@ -199,7 +199,7 @@ public class MJsonArray extends MJsonValue { if (0 < i) { s.append(", "); } - s.append(this.getValuesReference().get(i).getJsonValue()); + s.append(this.getValues().get(i).getJsonValue()); } s.append("]"); return s.toString(); diff --git a/src/java/com/marcozanon/macaco/json/MJsonObject.java b/src/java/com/marcozanon/macaco/json/MJsonObject.java index 6c5060a..8b168b1 100644 --- a/src/java/com/marcozanon/macaco/json/MJsonObject.java +++ b/src/java/com/marcozanon/macaco/json/MJsonObject.java @@ -55,10 +55,10 @@ public class MJsonObject extends MJsonValue { throw new IllegalArgumentException("Invalid 'x': null."); } // - this.getValuesReference().put(key, x); + this.getValues().put(key, x); } - protected LinkedHashMap getValuesReference() { + protected LinkedHashMap getValues() { return this.values; } @@ -70,11 +70,11 @@ public class MJsonObject extends MJsonValue { if (!this.containsKey(key)) { throw new IllegalArgumentException(String.format("Invalid 'key': %s: not available.", key)); } - return this.getValuesReference().get(key).clone(); + return this.getValues().get(key).clone(); } public int getValueCount() { - return this.getValuesReference().size(); + return this.getValues().size(); } public void removeValue(String key) { @@ -85,11 +85,11 @@ public class MJsonObject extends MJsonValue { if (!this.containsKey(key)) { throw new IllegalArgumentException(String.format("Invalid 'key': %s: not available.", key)); } - this.getValuesReference().remove(key); + this.getValues().remove(key); } public void clearValues() { - this.getValuesReference().clear(); + this.getValues().clear(); } public boolean containsKey(String key) { @@ -97,12 +97,12 @@ public class MJsonObject extends MJsonValue { throw new IllegalArgumentException("Invalid 'key': null or empty."); } // - return this.getValuesReference().containsKey(key); + return this.getValues().containsKey(key); } public LinkedHashSet getKeys() { LinkedHashSet keys = new LinkedHashSet(); - for (String key: this.getValuesReference().keySet()) { + for (String key: this.getValues().keySet()) { keys.add(key); } return keys; @@ -246,13 +246,13 @@ public class MJsonObject extends MJsonValue { StringBuilder s = new StringBuilder(""); s.append("{"); int k = 0; - for (String key: this.getValuesReference().keySet()) { + for (String key: this.getValues().keySet()) { if (0 < k) { s.append(", "); } s.append("\"" + MJsonString.getEscapedString(key, false) + "\""); s.append(": "); - s.append(this.getValuesReference().get(key).getJsonValue()); + s.append(this.getValues().get(key).getJsonValue()); k++; } s.append("}"); diff --git a/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java b/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java index 71d9f34..575eed7 100644 --- a/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java +++ b/src/java/com/marcozanon/macaco/logging/MLogDatabaseTable.java @@ -52,7 +52,7 @@ public class MLogDatabaseTable extends MLogTarget { public void close() throws MLoggingException { try { - this.getSqlConnectionReference().close(); + this.getSqlConnection().close(); } catch (MSqlConnectionFailureException exception) { throw new MLoggingException("Could not close Sql connection.", exception); @@ -61,7 +61,7 @@ public class MLogDatabaseTable extends MLogTarget { /* Sql connection generator. */ - protected MSqlConnectionGenerator getSqlConnectionGeneratorReference() { + protected MSqlConnectionGenerator getSqlConnectionGenerator() { return this.sqlConnectionGenerator; } @@ -81,7 +81,7 @@ public class MLogDatabaseTable extends MLogTarget { /* Sql connection. */ - protected MSqlConnection getSqlConnectionReference() { + protected MSqlConnection getSqlConnection() { return this.sqlConnection; } @@ -107,13 +107,13 @@ public class MLogDatabaseTable extends MLogTarget { separator.append(" "); } // - if (null == this.getSqlConnectionReference()) { - this.sqlConnection = this.getSqlConnectionGeneratorReference().getNewConnection(); + if (null == this.getSqlConnection()) { + this.sqlConnection = this.getSqlConnectionGenerator().getNewConnection(); } // LinkedHashMap p = new LinkedHashMap(); p.put(this.getLogDatabaseField(), timestamp + separator + message); - (new MSqlTable(this.getSqlConnectionReference(), this.getLogDatabaseTable(), this.getLogDatabaseTablePrimaryKey())).setRecord(p, null); + (new MSqlTable(this.getSqlConnection(), this.getLogDatabaseTable(), this.getLogDatabaseTablePrimaryKey())).setRecord(p, null); } catch (MSqlConnectionFailureException exception) { throw new MLoggingException("Could not write to database table.", exception); diff --git a/src/java/com/marcozanon/macaco/logging/MLogFilter.java b/src/java/com/marcozanon/macaco/logging/MLogFilter.java index 4669c92..cb7cc8d 100644 --- a/src/java/com/marcozanon/macaco/logging/MLogFilter.java +++ b/src/java/com/marcozanon/macaco/logging/MLogFilter.java @@ -33,7 +33,7 @@ public class MLogFilter extends MObject { } public void close() throws MLoggingException { - for (MLogTarget t: this.getLogTargetsReference()) { + for (MLogTarget t: this.getLogTargets()) { t.close(); } } @@ -72,7 +72,7 @@ public class MLogFilter extends MObject { } } - protected LinkedList getLogTargetsReference() { + protected LinkedList getLogTargets() { return this.logTargets; } @@ -116,7 +116,7 @@ public class MLogFilter extends MObject { String message = logMessage.getMessage(); int indentation = logMessage.getIndentation(); // - for (MLogTarget logTarget: this.getLogTargetsReference()) { + for (MLogTarget logTarget: this.getLogTargets()) { logTarget.appendMessage(message, indentation); } } diff --git a/src/java/com/marcozanon/macaco/logging/MLogPlainTextFile.java b/src/java/com/marcozanon/macaco/logging/MLogPlainTextFile.java index 0f225d5..49b4a78 100644 --- a/src/java/com/marcozanon/macaco/logging/MLogPlainTextFile.java +++ b/src/java/com/marcozanon/macaco/logging/MLogPlainTextFile.java @@ -45,7 +45,7 @@ public class MLogPlainTextFile extends MLogTarget { public void close() throws MLoggingException { try { - this.getBufferReference().close(); + this.getBuffer().close(); } catch (IOException exception) { throw new MLoggingException("Could not close file.", exception); @@ -60,7 +60,7 @@ public class MLogPlainTextFile extends MLogTarget { /* Buffer. */ - protected BufferedWriter getBufferReference() { + protected BufferedWriter getBuffer() { return this.buffer; } @@ -86,10 +86,10 @@ public class MLogPlainTextFile extends MLogTarget { separator.append(" "); } // - synchronized (this.getBufferReference()) { - this.getBufferReference().write(timestamp + separator + message); - this.getBufferReference().newLine(); - this.getBufferReference().flush(); + synchronized (this.getBuffer()) { + this.getBuffer().write(timestamp + separator + message); + this.getBuffer().newLine(); + this.getBuffer().flush(); } } catch (IOException exception) { diff --git a/src/java/com/marcozanon/macaco/sql/MSqlConnection.java b/src/java/com/marcozanon/macaco/sql/MSqlConnection.java index dc8c5ea..12ab736 100644 --- a/src/java/com/marcozanon/macaco/sql/MSqlConnection.java +++ b/src/java/com/marcozanon/macaco/sql/MSqlConnection.java @@ -75,7 +75,7 @@ public class MSqlConnection extends MObject { } // Set SQL mode to standard ANSI. try { - this.getConnectionReference().createStatement().executeUpdate("SET SQL_MODE='ANSI'"); + this.getConnection().createStatement().executeUpdate("SET SQL_MODE='ANSI'"); } catch (SQLException exception) { throw new MSqlConnectionFailureException("Could not set SQL mode to ANSI.", exception); @@ -84,7 +84,7 @@ public class MSqlConnection extends MObject { public void close() throws MSqlConnectionFailureException { try { - this.getConnectionReference().close(); + this.getConnection().close(); } catch (SQLException exception) { throw new MSqlConnectionFailureException("Could not close connection.", exception); @@ -93,7 +93,7 @@ public class MSqlConnection extends MObject { public boolean isClosed() throws MSqlConnectionFailureException { try { - return this.getConnectionReference().isClosed(); + return this.getConnection().isClosed(); } catch (SQLException exception) { throw new MSqlConnectionFailureException("Could not determine the state.", exception); @@ -134,7 +134,7 @@ public class MSqlConnection extends MObject { /* Connection. */ - protected Connection getConnectionReference() { + protected Connection getConnection() { return this.connection; } @@ -157,8 +157,8 @@ public class MSqlConnection extends MObject { throw new MSqlTransactionException("Nested transactions not allowed."); } try { - this.getConnectionReference().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); - this.getConnectionReference().setAutoCommit(false); + this.getConnection().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); + this.getConnection().setAutoCommit(false); this.setTransactionStatus(MSqlConnection.TransactionStatus.SUCCESSFUL); } catch (SQLException exception) { @@ -171,8 +171,8 @@ public class MSqlConnection extends MObject { throw new MSqlTransactionException("Transaction not started."); } try { - this.getConnectionReference().rollback(); - this.getConnectionReference().setAutoCommit(true); + this.getConnection().rollback(); + this.getConnection().setAutoCommit(true); this.setTransactionStatus(MSqlConnection.TransactionStatus.CLOSED); } catch (SQLException exception) { @@ -185,8 +185,8 @@ public class MSqlConnection extends MObject { switch (this.getTransactionStatus()) { case SUCCESSFUL: try { - this.getConnectionReference().commit(); - this.getConnectionReference().setAutoCommit(true); + this.getConnection().commit(); + this.getConnection().setAutoCommit(true); this.setTransactionStatus(MSqlConnection.TransactionStatus.CLOSED); return MSqlConnection.TransactionStatus.SUCCESSFUL; } @@ -220,7 +220,7 @@ public class MSqlConnection extends MObject { PreparedStatement preparedStatement = null; try { // Prepare the statement. - preparedStatement = this.getConnectionReference().prepareStatement(statement, PreparedStatement.RETURN_GENERATED_KEYS); + preparedStatement = this.getConnection().prepareStatement(statement, PreparedStatement.RETURN_GENERATED_KEYS); for (int p = 0; parameters.size() > p; p++) { preparedStatement.setObject(p + 1, parameters.get(p)); } diff --git a/src/java/com/marcozanon/macaco/sql/MSqlStatementResults.java b/src/java/com/marcozanon/macaco/sql/MSqlStatementResults.java index 459d228..7d3210a 100644 --- a/src/java/com/marcozanon/macaco/sql/MSqlStatementResults.java +++ b/src/java/com/marcozanon/macaco/sql/MSqlStatementResults.java @@ -38,16 +38,16 @@ public class MSqlStatementResults extends MObject { this.preparedStatement = preparedStatement; // try { - this.resultSet = this.getPreparedStatementReference().getResultSet(); - if (null != this.getResultSetReference()) { - while (this.getResultSetReference().next()) { - ResultSetMetaData resultSetMetaData = this.getResultSetReference().getMetaData(); + this.resultSet = this.getPreparedStatement().getResultSet(); + if (null != this.getResultSet()) { + while (this.getResultSet().next()) { + ResultSetMetaData resultSetMetaData = this.getResultSet().getMetaData(); LinkedHashMap record = new LinkedHashMap(); for (int f = 0; resultSetMetaData.getColumnCount() > f; f++) { String field = resultSetMetaData.getColumnLabel(f + 1); - record.put(field, this.getResultSetReference().getObject(field)); + record.put(field, this.getResultSet().getObject(field)); } - this.getRecordsReference().add(record); + this.getRecords().add(record); } } } @@ -56,9 +56,9 @@ public class MSqlStatementResults extends MObject { } // try { - ResultSet generatedKeysResultSet = this.getPreparedStatementReference().getGeneratedKeys(); + ResultSet generatedKeysResultSet = this.getPreparedStatement().getGeneratedKeys(); while (generatedKeysResultSet.next()) { - this.getGeneratedKeysReference().add(generatedKeysResultSet.getObject(1)); + this.getGeneratedKeys().add(generatedKeysResultSet.getObject(1)); } generatedKeysResultSet.close(); } @@ -69,10 +69,10 @@ public class MSqlStatementResults extends MObject { public void close() throws MSqlConnectionFailureException { try { - if (null != this.getResultSetReference()) { - this.getResultSetReference().close(); + if (null != this.getResultSet()) { + this.getResultSet().close(); } - this.getPreparedStatementReference().close(); + this.getPreparedStatement().close(); } catch (SQLException exception) { throw new MSqlConnectionFailureException("Could not close statement and/or result set references.", exception); @@ -89,30 +89,18 @@ public class MSqlStatementResults extends MObject { /* References. */ - protected PreparedStatement getPreparedStatementReference() { + protected PreparedStatement getPreparedStatement() { return this.preparedStatement; } - public ResultSet getResultSetReference() { + public ResultSet getResultSet() { return this.resultSet; } /* Records. */ - protected LinkedList> getRecordsReference() { - return this.records; - } - public LinkedList> getRecords() { - LinkedList> tmpRecords = new LinkedList>(); - for (LinkedHashMap record: this.getRecordsReference()) { - LinkedHashMap tmpRecord = new LinkedHashMap(); - for (String key: record.keySet()) { - tmpRecord.put(key, record.get(key)); - } - tmpRecords.add(tmpRecord); - } - return tmpRecords; + return this.records; } public LinkedList getRecordsByField(String field) { @@ -121,7 +109,7 @@ public class MSqlStatementResults extends MObject { } // LinkedList recordsByField = new LinkedList(); - for (LinkedHashMap record: this.getRecordsReference()) { + for (LinkedHashMap record: this.getRecords()) { Object r = record.get(field); if (null == r) { throw new IllegalArgumentException(String.format("Invalid 'field': %s.", field)); @@ -133,17 +121,8 @@ public class MSqlStatementResults extends MObject { /* Generated keys. */ - protected LinkedHashSet getGeneratedKeysReference() { - return this.generatedKeys; - } - public LinkedHashSet getGeneratedKeys() { - LinkedHashSet tmpGeneratedKeys = new LinkedHashSet(); - Iterator i = this.getGeneratedKeysReference().iterator(); - while (i.hasNext()) { - tmpGeneratedKeys.add(i.next()); - } - return tmpGeneratedKeys; + return this.generatedKeys; } } diff --git a/src/java/com/marcozanon/macaco/sql/MSqlTable.java b/src/java/com/marcozanon/macaco/sql/MSqlTable.java index e172e77..1c7cca4 100644 --- a/src/java/com/marcozanon/macaco/sql/MSqlTable.java +++ b/src/java/com/marcozanon/macaco/sql/MSqlTable.java @@ -40,7 +40,7 @@ public class MSqlTable extends MObject { /* Connection. */ - protected MSqlConnection getConnectionReference() { + protected MSqlConnection getConnection() { return this.connection; } @@ -73,10 +73,10 @@ public class MSqlTable extends MObject { } fields.delete(fields.length() - 2, fields.length()); s.delete(s.length() - 2, s.length()); - return this.getConnectionReference().executePreparedStatement(" INSERT INTO \"" + this.getTable() + "\"" - + " (" + fields + ")" - + " VALUES (" + s + ")", - p); + return this.getConnection().executePreparedStatement(" INSERT INTO \"" + this.getTable() + "\"" + + " (" + fields + ")" + + " VALUES (" + s + ")", + p); } protected MSqlStatementResults updateRecord(LinkedHashMap map, Object id) throws MSqlStatementException { @@ -95,10 +95,10 @@ public class MSqlTable extends MObject { } s.delete(s.length() - 2, s.length()); p.add(id); - return this.getConnectionReference().executePreparedStatement(" UPDATE \"" + this.getTable() + "\"" - + " SET " + s - + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", - p); + return this.getConnection().executePreparedStatement(" UPDATE \"" + this.getTable() + "\"" + + " SET " + s + + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", + p); } public MSqlStatementResults setRecord(LinkedHashMap map, Object id) throws MSqlStatementException { @@ -117,10 +117,10 @@ public class MSqlTable extends MObject { // LinkedList p = new LinkedList(); p.add(id); - return this.getConnectionReference().executePreparedStatement(" SELECT *" - + " FROM \"" + this.getTable() + "\"" - + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", - p); + return this.getConnection().executePreparedStatement(" SELECT *" + + " FROM \"" + this.getTable() + "\"" + + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", + p); } public MSqlStatementResults deleteRecord(Object id) throws MSqlStatementException { @@ -130,9 +130,9 @@ public class MSqlTable extends MObject { // LinkedList p = new LinkedList(); p.add(id); - return this.getConnectionReference().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" - + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", - p); + return this.getConnection().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" + + " WHERE (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)", + p); } public MSqlStatementResults deleteRecords(LinkedHashSet idSet) throws MSqlStatementException { @@ -146,9 +146,9 @@ public class MSqlTable extends MObject { whereClause.append(" OR (\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" = ?)"); p.add(id); } - return this.getConnectionReference().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" - + " WHERE (" + whereClause + ")", - p); + return this.getConnection().executePreparedStatement(" DELETE FROM \"" + this.getTable() + "\"" + + " WHERE (" + whereClause + ")", + p); } } diff --git a/src/java/com/marcozanon/macaco/text/MTranslator.java b/src/java/com/marcozanon/macaco/text/MTranslator.java index 9e2a3b5..dcbf4d8 100644 --- a/src/java/com/marcozanon/macaco/text/MTranslator.java +++ b/src/java/com/marcozanon/macaco/text/MTranslator.java @@ -63,7 +63,7 @@ public class MTranslator extends MObject { /* String management. */ - protected LinkedHashMap> getMessagesReference() { + protected LinkedHashMap> getMessages() { return this.messages; } @@ -83,7 +83,7 @@ public class MTranslator extends MObject { } String message = null; String line = null; - synchronized (this.getMessagesReference()) { + synchronized (this.getMessages()) { while (true) { try { line = buffer.readLine(); @@ -104,10 +104,10 @@ public class MTranslator extends MObject { } else if (null == message) { message = line; - if (this.getMessagesReference().containsKey(message)) { + if (this.getMessages().containsKey(message)) { throw new MTranslationFileParsingException(String.format("Invalid line: %s: duplicated message: %s.", buffer.getLineNumber(), message)); } - this.getMessagesReference().put(message, new LinkedHashMap()); + this.getMessages().put(message, new LinkedHashMap()); } else { int a = line.indexOf("="); @@ -116,10 +116,10 @@ public class MTranslator extends MObject { } String localeRepresentation = line.substring(0, a).trim(); String translation = line.substring(a + 1).trim(); - if (this.getMessagesReference().get(message).containsKey(localeRepresentation)) { + if (this.getMessages().get(message).containsKey(localeRepresentation)) { throw new MTranslationFileParsingException(String.format("Invalid line: %s: duplicated translation for locale: %s.", buffer.getLineNumber(), message)); } - this.getMessagesReference().get(message).put(localeRepresentation, translation); + this.getMessages().get(message).put(localeRepresentation, translation); } } } @@ -132,8 +132,8 @@ public class MTranslator extends MObject { } public void clear() { - synchronized (this.getMessagesReference()) { - this.getMessagesReference().clear(); + synchronized (this.getMessages()) { + this.getMessages().clear(); } } @@ -163,7 +163,7 @@ public class MTranslator extends MObject { throw new IllegalArgumentException("Invalid 'locale': null."); } // - if (!this.getMessagesReference().containsKey(message)) { + if (!this.getMessages().containsKey(message)) { if (strictMode) { throw new MTranslationValueNotFoundException(String.format("Invalid 'message': %s: not available.", message)); } @@ -172,7 +172,7 @@ public class MTranslator extends MObject { if (this.getBasicLocale().equals(locale)) { return message; } - LinkedHashMap messageTranslations = this.getMessagesReference().get(message); + LinkedHashMap messageTranslations = this.getMessages().get(message); String localeRepresentation = locale.toString(); if (!messageTranslations.containsKey(localeRepresentation)) { if (strictMode) { -- 2.30.2