public static String getMacacoCopyrightInformation() {
StringBuilder s = new StringBuilder("");
+ //
s.append(MInformation.getMacacoFullName() + System.getProperty("line.separator"));
s.append("Copyright (c) 2009-2022 by Marco Zanon." + System.getProperty("line.separator"));
- s.append("Released under MIT license (see LICENSE.MIT.sample for details)." + System.getProperty("line.separator"));
+ s.append("Released under MIT license (https://opensource.org/licenses/MIT)." + System.getProperty("line.separator"));
s.append("Small portions inspired by other projects or web pages. See source code for additional information.");
+ //
return s.toString();
}
//
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
+ //
throwable.printStackTrace(pw);
pw.flush();
sw.flush();
c1.setLenient(false);
SimpleDateFormat sdf = new SimpleDateFormat(inputDateFormat, inputLocale);
sdf.setCalendar(c1);
+ //
Date d1 = null;
try {
d1 = sdf.parse(x);
catch (ParseException exception) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat)); // no need to propagate exception
}
+ //
Calendar c2 = Calendar.getInstance(inputTimeZone, inputLocale);
c2.clear();
c2.set(Calendar.YEAR, c1.get(Calendar.YEAR));
c2.set(Calendar.HOUR_OF_DAY, c1.get(Calendar.HOUR_OF_DAY));
c2.set(Calendar.MINUTE, c1.get(Calendar.MINUTE));
c2.set(Calendar.SECOND, c1.get(Calendar.SECOND));
+ //
Date d2 = c2.getTime();
if (!x.equals(sdf.format(d2))) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat));
}
+ //
return d2;
}
//
SimpleDateFormat sdf = new SimpleDateFormat(outputDateFormat, outputLocale);
sdf.setCalendar(Calendar.getInstance(outputTimeZone, outputLocale));
+ //
return sdf.format(date);
}
for (String dateFormat: this.getDateFormats()) {
try {
y = MDateConverter.getDateFromStringByParameters(x, dateFormat, this.getLocale(), this.getTimeZone());
+ //
return y;
}
catch (MInvalidConversionFormatException exception) {
if (null == y) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x': %s.", x));
}
+ //
return y; // necessary to avoid Java compilation errors
}
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
+ //
return calendar.getTime();
}
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
+ //
return calendar.getTime();
}
for (String dateFormat: this.getDateFormats()) {
try {
y = MLocalDateConverter.getDateFromStringByParameters(x, dateFormat, this.getLocale());
+ //
return y;
}
catch (MInvalidConversionFormatException exception) {
if (null == y) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x': %s.", x));
}
+ //
return y; // necessary to avoid Java compilation errors
}
for (String datetimeFormat: this.getDatetimeFormats()) {
try {
y = MLocalDateTimeConverter.getDatetimeFromStringByParameters(x, datetimeFormat, this.getLocale());
+ //
return y;
}
catch (MInvalidConversionFormatException exception) {
if (null == y) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x': %s.", x));
}
+ //
return y; // necessary to avoid Java compilation errors
}
DecimalFormatSymbols dfs = new DecimalFormatSymbols(inputLocale);
DecimalFormat df = new DecimalFormat(inputNumberFormat, dfs);
df.setParseBigDecimal(true);
+ //
ParsePosition validPosition = new ParsePosition(0);
BigDecimal bd = (BigDecimal)df.parse(x, validPosition);
if (validPosition.getIndex() < x.length()) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputNumberFormat));
}
+ //
return bd;
}
DecimalFormatSymbols dfs = new DecimalFormatSymbols(outputLocale);
DecimalFormat df = new DecimalFormat(outputNumberFormat, dfs);
df.setRoundingMode(RoundingMode.HALF_UP);
+ //
return df.format(number);
}
for (String numberFormat: this.getNumberFormats()) {
try {
y = MNumberConverter.getNumberFromStringByParameters(x, numberFormat, this.getLocale());
+ //
return y;
}
catch (MInvalidConversionFormatException exception) {
if (null == y) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x': %s.", x));
}
+ //
return y; // necessary to avoid Java compilation errors
}
this.getConnection().setAutoCommit(true);
this.setTransactionStatus(MDatabaseConnection.TransactionStatus.CLOSED);
this.logStatement("### COMMIT ###");
+ //
return MDatabaseConnection.TransactionStatus.SUCCESSFUL;
}
catch (SQLException exception) {
this.rollBackTransaction();
+ //
return MDatabaseConnection.TransactionStatus.FAILED;
}
case FAILED:
this.rollBackTransaction();
+ //
return MDatabaseConnection.TransactionStatus.FAILED;
default: // instead of "case CLOSED:" (necessary to avoid Java compilation errors)
throw new MSqlTransactionException("Transaction not started.");
}
throw new MSqlStatementException(String.format("Could not execute prepared statement: %s.", preparedStatement), exception);
}
+ //
return results;
}
public synchronized MDatabaseConnection popDatabaseConnection() throws MDatabaseConnectionFailureException {
LinkedList<MDatabaseConnection> databaseConnections = this.getDatabaseConnections();
+ //
MDatabaseConnection databaseConnection = null;
if (0 == databaseConnections.size()) {
databaseConnection = this.getDatabaseConnectionGenerator().getNewDatabaseConnection();
else {
databaseConnection = databaseConnections.removeLast();
}
+ //
if (this.getMinimumSize() > databaseConnections.size()) {
databaseConnections.add(this.getDatabaseConnectionGenerator().getNewDatabaseConnection());
}
+ //
return databaseConnection;
}
}
else {
LinkedList<MDatabaseConnection> databaseConnections = this.getDatabaseConnections();
+ //
if (this.getMaximumSize() >= databaseConnections.size()) {
databaseConnections.add(databaseConnection);
}
}
recordsByField.add(r);
}
+ //
return recordsByField;
}
LinkedList<Object> p = new LinkedList<Object>();
StringBuilder fields = new StringBuilder("");
StringBuilder s = new StringBuilder("");
+ //
for (String field: map.keySet()) {
fields.append("\"" + this.getTable() + "\".\"" + field + "\", ");
s.append("?, ");
//
LinkedList<Object> p = new LinkedList<Object>();
StringBuilder s = new StringBuilder("");
+ //
for (String field: map.keySet()) {
s.append("\"" + this.getTable() + "\".\"" + field + "\" = ?, ");
p.add(map.get(field));
//
String whereClause = null;
LinkedList<Object> p = null;
+ //
if (0 == idSet.size()) {
whereClause = "0";
}
else {
StringJoiner s = new StringJoiner(", ");
p = new LinkedList<Object>();
+ //
for (Object id: idSet) {
s.add("?");
p.add(id);
}
+ //
whereClause = "\"" + this.getTable() + "\".\"" + this.getPrimaryKey() + "\" IN (" + s.toString() + ")";
}
//
@Override
public MJsonArray clone() {
MJsonArray tmpMJsonArray = null;
+ //
try {
tmpMJsonArray = new MJsonArray(this.getJsonValue());
}
catch (MInvalidJsonValueException exception) { // cannot happen
}
+ //
return tmpMJsonArray;
}
if ((2 > x.length()) || ('[' != x.charAt(0))) {
return 0;
}
+ //
int position = x.indexOf("]", 1);
while (-1 < position) {
try {
MJsonArray testValue = new MJsonArray();
testValue.parseString(x.substring(0, position + 1));
+ //
return position + 1;
}
catch (MInvalidJsonValueException exception) {
position = x.indexOf("]", position + 1);
}
}
+ //
return 0;
}
if ((2 > x.length()) || ('[' != x.charAt(0)) || (']' != x.charAt(x.length() - 1))) {
throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: must begin and end with square brackets.", x));
}
+ //
String y = x.substring(1, x.length() - 1);
int parsingPosition = 0;
MJsonArray.ParsingMode parsingMode = MJsonArray.ParsingMode.START;
break;
}
}
+ //
if (MJsonArray.ParsingMode.POST_VALUE_SEPARATOR == parsingMode) {
parsingMode = MJsonArray.ParsingMode.ERROR;
}
@Override
public String getJsonValue() {
StringBuilder s = new StringBuilder("");
+ //
s.append("[");
for (int i = 0; this.getValueCount() > i; i++) {
if (0 < i) {
s.append(this.getValues().get(i).getJsonValue());
}
s.append("]");
+ //
return s.toString();
}
@Override
public MJsonBoolean clone() {
MJsonBoolean tmpMJsonBoolean = null;
+ //
try {
tmpMJsonBoolean = new MJsonBoolean(this.getJsonValue());
}
catch (MInvalidJsonValueException exception) { // cannot happen
}
+ //
return tmpMJsonBoolean;
}
else if (x.startsWith("false")) {
return "false".length();
}
+ //
return 0;
}
if ((!"true".equals(x)) && (!"false".equals(x))) {
throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json boolean.", x));
}
+ //
this.setValue(Boolean.valueOf(x));
}
@Override
public MJsonNull clone() {
MJsonNull tmpMJsonNull = null;
+ //
try {
tmpMJsonNull = new MJsonNull(this.getJsonValue());
}
catch (MInvalidJsonValueException exception) { // cannot happen
}
+ //
return tmpMJsonNull;
}
if (x.startsWith("null")) {
return "null".length();
}
+ //
return 0;
}
@Override
public MJsonNumber clone() {
MJsonNumber tmpMJsonNumber = null;
+ //
try {
tmpMJsonNumber = new MJsonNumber(this.getJsonValue());
}
catch (MInvalidJsonValueException exception) { // cannot happen
}
+ //
return tmpMJsonNumber;
}
if (' ' == x.charAt(0)) {
return 0;
}
+ //
int position = 0;
int validPosition = 0;
BigDecimal y = null;
+ //
while (x.length() > position) {
if (' ' == x.charAt(position)) {
break;
}
}
}
+ //
return validPosition;
}
}
//
BigDecimal y = null;
+ //
try {
y = new BigDecimal(x);
}
catch (NumberFormatException exception) {
throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json number.", x)); // no need to propagate exception
}
+ //
this.setValue(y);
}
@Override
public MJsonObject clone() {
MJsonObject tmpMJsonObject = null;
+ //
try {
tmpMJsonObject = new MJsonObject(this.getJsonValue());
}
catch (MInvalidJsonValueException exception) { // cannot happen
}
+ //
return tmpMJsonObject;
}
if (!this.containsKey(key)) {
throw new IllegalArgumentException(String.format("Invalid 'key': %s: not available.", key));
}
+ //
return this.getValues().get(key).clone();
}
if (!this.containsKey(key)) {
throw new IllegalArgumentException(String.format("Invalid 'key': %s: not available.", key));
}
+ //
this.getValues().remove(key);
}
for (String key: this.getValues().keySet()) {
keys.add(key);
}
+ //
return keys;
}
if ((2 > x.length()) || ('{' != x.charAt(0))) {
return 0;
}
+ //
int position = x.indexOf("}", 1);
while (-1 < position) {
try {
MJsonObject testValue = new MJsonObject();
testValue.parseString(x.substring(0, position + 1));
+ //
return position + 1;
}
catch (MInvalidJsonValueException exception) {
position = x.indexOf("}", position + 1);
}
}
+ //
return 0;
}
if ((2 > x.length()) || ('{' != x.charAt(0)) || ('}' != x.charAt(x.length() - 1))) {
throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: must begin and end with curly brackets.", x));
}
+ //
String y = x.substring(1, x.length() - 1);
int parsingPosition = 0;
MJsonObject.ParsingMode parsingMode = MJsonObject.ParsingMode.START;
break;
}
}
+ //
if ((MJsonObject.ParsingMode.POST_NAME == parsingMode) || (MJsonObject.ParsingMode.POST_NAME_SEPARATOR == parsingMode) || (MJsonObject.ParsingMode.POST_VALUE_SEPARATOR == parsingMode)) {
parsingMode = MJsonObject.ParsingMode.ERROR;
}
@Override
public String getJsonValue() {
StringBuilder s = new StringBuilder("");
+ //
s.append("{");
int k = 0;
for (String key: this.getValues().keySet()) {
k++;
}
s.append("}");
+ //
return s.toString();
}
@Override
public MJsonString clone() {
MJsonString tmpMJsonString = null;
+ //
try {
tmpMJsonString = new MJsonString(this.getJsonValue());
}
catch (MInvalidJsonValueException exception) { // cannot happen
}
+ //
return tmpMJsonString;
}
}
}
}
+ //
return y.toString();
}
y.appendCodePoint(c);
}
}
+ //
return y.toString();
}
if ('"' == x.charAt(1)) {
return 1 + 1;
}
+ //
String y = x.substring(1);
int quotationMarkPosition = 0;
while (-1 < (quotationMarkPosition = y.indexOf("\"", quotationMarkPosition + 1))) {
break;
}
}
+ //
if (-1 == quotationMarkPosition) {
return 0;
}
+ //
return (quotationMarkPosition + 1) + 1;
}
if ((2 > x.length()) || ('"' != x.charAt(0)) || ('"' != x.charAt(x.length() - 1))) {
throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
+ //
String y = x.substring(1, x.length() - 1);
if (-1 < y.replaceAll("\\\\\"", "__").indexOf("\"")) {
throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
+ //
this.setValue(MJsonString.getUnescapedString(y));
}
//
LinkedHashMap<String, Object> p = new LinkedHashMap<String, Object>();
p.put(this.getLogDatabaseField(), timestamp + separator + message);
+ //
(new MSqlTable(databaseConnection, this.getLogDatabaseTable(), this.getLogDatabaseTablePrimaryKey())).setRecord(p, null, false);
//
this.getDatabaseConnectionPool().pushDatabaseConnection(databaseConnection);
if ((null != x) && ("".equals(x))) {
return true;
}
+ //
return false;
}
if ((null == x) || ("".equals(x))) {
return true;
}
+ //
return false;
}
}
//
StringBuilder y = new StringBuilder("");
+ //
for (int i = 0; i < times; i++) {
y = y.append(x);
}
+ //
return y.toString();
}
}
//
StringBuilder y = new StringBuilder("");
+ //
for (int i = 0; i < length; i++) {
char c = (char)(65 + (25 * Math.random()));
y = y.append(c);
}
+ //
return y.toString();
}
catch (IOException exception) {
throw new MTranslationFileParsingException("Could not read file.", exception);
}
+ //
if (null == line) {
break;
}
+ //
line = line.trim();
+ //
if (MText.isEmpty(line)) {
message = null;
continue;
if (this.getMessages().containsKey(message)) {
throw new MTranslationFileParsingException(String.format("Invalid line: %s: duplicated message: %s.", buffer.getLineNumber(), message));
}
+ //
this.getMessages().put(message, new LinkedHashMap<String, String>());
}
else {
if (-1 == a) {
throw new MTranslationFileParsingException(String.format("Invalid line: %s: string malformed: %s.", buffer.getLineNumber(), line));
}
+ //
String localeRepresentation = line.substring(0, a).trim();
String translation = line.substring(a + 1).trim();
if (this.getMessages().get(message).containsKey(localeRepresentation)) {
throw new MTranslationFileParsingException(String.format("Invalid line: %s: duplicated translation for locale: %s.", buffer.getLineNumber(), message));
}
+ //
this.getMessages().get(message).put(localeRepresentation, translation);
}
}
public String getLenientTranslation(String message, Locale locale) {
String translation = null;
+ //
try {
translation = this.getTranslation(message, locale, false);
}
catch (MTranslationValueNotFoundException exception) { // cannot happen
}
+ //
return translation;
}
if (strictMode) {
throw new MTranslationValueNotFoundException(String.format("Invalid 'message': %s: not available.", message));
}
+ //
return message;
}
/*
if (strictMode) {
throw new MTranslationValueNotFoundException(String.format("Invalid 'locale': %s: translation not available for message: %s.", localeRepresentation, message));
}
+ //
String localeFallbackRepresentation = locale.getLanguage();
+ //
if (!messageTranslations.containsKey(localeFallbackRepresentation)) {
return message;
}
+ //
return messageTranslations.get(localeFallbackRepresentation);
}
+ //
return messageTranslations.get(localeRepresentation);
}