You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2011/09/15 08:04:29 UTC
svn commit: r1170961 - in /ofbiz/trunk:
applications/accounting/src/org/ofbiz/accounting/payment/
applications/content/src/org/ofbiz/content/
applications/marketing/src/org/ofbiz/sfa/vcard/
applications/product/src/org/ofbiz/product/category/ framework...
Author: sascharodekamp
Date: Thu Sep 15 06:04:29 2011
New Revision: 1170961
URL: http://svn.apache.org/viewvc?rev=1170961&view=rev
Log:
IMPROVEMENT: Replace String concatenation in a loop (https://issues.apache.org/jira/browse/OFBIZ-4418) A patch from Dimitri Unruh.
Modified:
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java
ofbiz/trunk/applications/content/src/org/ofbiz/content/ContentManagementWorker.java
ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java?rev=1170961&r1=1170960&r2=1170961&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/GiftCertificateServices.java Thu Sep 15 06:04:29 2011
@@ -1455,28 +1455,27 @@ public class GiftCertificateServices {
Random rand = new Random();
boolean isValid = false;
- String number = null;
+ StringBuilder number = null;
while (!isValid) {
- number = "";
+ number = new StringBuilder("");
for (int i = 0; i < length; i++) {
int randInt = rand.nextInt(9);
- number = number + randInt;
+ number.append(randInt);
}
if (isId) {
- int check = UtilValidate.getLuhnCheckDigit(number);
- number = number + check;
+ number.append(UtilValidate.getLuhnCheckDigit(number.toString()));
// validate the number
- if (checkCardNumber(number)) {
+ if (checkCardNumber(number.toString())) {
// make sure this number doens't already exist
- isValid = checkNumberInDatabase(delegator, number);
+ isValid = checkNumberInDatabase(delegator, number.toString());
}
} else {
isValid = true;
}
}
- return number;
+ return number.toString();
}
private static boolean checkNumberInDatabase(Delegator delegator, String number) throws GenericEntityException {
Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java?rev=1170961&r1=1170960&r2=1170961&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentMethodServices.java Thu Sep 15 06:04:29 2011
@@ -586,19 +586,19 @@ public class PaymentMethodServices {
if (cardNumber.startsWith("*")) {
// get the masked card number from the db
String origCardNumber = giftCard.getString("cardNumber");
- String origMaskedNumber = "";
+ StringBuilder origMaskedNumber = new StringBuilder("");
int cardLength = origCardNumber.length() - 4;
if (cardLength > 0) {
for (int i = 0; i < cardLength; i++) {
- origMaskedNumber = origMaskedNumber + "*";
+ origMaskedNumber.append("*");
}
- origMaskedNumber = origMaskedNumber + origCardNumber.substring(cardLength);
+ origMaskedNumber.append(origCardNumber.substring(cardLength));
} else {
- origMaskedNumber = origCardNumber;
+ origMaskedNumber.append(origCardNumber);
}
// compare the two masked numbers
- if (cardNumber.equals(origMaskedNumber)) {
+ if (cardNumber.equals(origMaskedNumber.toString())) {
cardNumber = origCardNumber;
}
}
Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/ContentManagementWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/ContentManagementWorker.java?rev=1170961&r1=1170960&r2=1170961&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/ContentManagementWorker.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/ContentManagementWorker.java Thu Sep 15 06:04:29 2011
@@ -126,7 +126,7 @@ public class ContentManagementWorker {
* @param suffix a string that can be used to distinguish the signature (probably not used).
*/
public static String buildPKSig(GenericEntity pk, String suffix) {
- String sig = "";
+ StringBuilder sig = new StringBuilder("");
Collection<String> keyColl = pk.getPrimaryKey().getAllKeys();
List<String> keyList = UtilMisc.makeListWritable(keyColl);
Collections.sort(keyList);
@@ -135,15 +135,15 @@ public class ContentManagementWorker {
String ky = it.next();
String val = (String)pk.get(ky);
if (UtilValidate.isNotEmpty(val)) {
- if (sig.length() > 0) sig += "_";
- sig += val;
+ if (sig.length() > 0) sig.append("_");
+ sig.append(val);
}
}
if (UtilValidate.isNotEmpty(suffix)) {
- if (sig.length() > 0) sig += "_";
- sig += suffix;
+ if (sig.length() > 0) sig.append("_");
+ sig.append(suffix);
}
- return sig;
+ return sig.toString();
}
public static void setCurrentEntityMap(HttpServletRequest request, GenericEntity ent) {
Modified: ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java?rev=1170961&r1=1170960&r2=1170961&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java (original)
+++ ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Thu Sep 15 06:04:29 2011
@@ -167,10 +167,10 @@ public class VCard {
}
if (UtilValidate.isNotEmpty(phone)) {
String[] numberParts = phone.split("\\D");
- String telNumber = "";
+ StringBuilder telNumber = new StringBuilder("");
for (String number: numberParts) {
if (number != "") {
- telNumber = telNumber + number;
+ telNumber.append(number);
}
}
serviceCtx.put("areaCode", telNumber.substring(0, 3));
Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java?rev=1170961&r1=1170960&r2=1170961&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java Thu Sep 15 06:04:29 2011
@@ -506,12 +506,14 @@ public class CategoryServices {
@SuppressWarnings("unchecked")
public static void toJsonObjectList(List attrList, HttpServletResponse response){
- String jsonStr = "[";
+ StringBuilder jsonBuilder = new StringBuilder("[");
for (Object attrMap : attrList) {
JSONObject json = JSONObject.fromObject(attrMap);
- jsonStr = jsonStr + json.toString() + ',';
+ jsonBuilder.append(json.toString());
+ jsonBuilder.append(',');
}
- jsonStr = jsonStr + "{ } ]";
+ jsonBuilder.append("{ } ]");
+ String jsonStr = jsonBuilder.toString();
if (UtilValidate.isEmpty(jsonStr)) {
Debug.logError("JSON Object was empty; fatal error!",module);
}
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java?rev=1170961&r1=1170960&r2=1170961&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelRelation.java Thu Sep 15 06:04:29 2011
@@ -196,7 +196,7 @@ public class ModelRelation extends Model
}
public String keyMapString(String separator, String afterLast) {
- String returnString = "";
+ StringBuilder stringBuilder = new StringBuilder("");
if (keyMaps.size() < 1) {
return "";
@@ -205,10 +205,12 @@ public class ModelRelation extends Model
int i = 0;
for (; i < keyMaps.size() - 1; i++) {
- returnString = returnString + keyMaps.get(i).fieldName + separator;
+ stringBuilder.append(keyMaps.get(i).fieldName);
+ stringBuilder.append(separator);
}
- returnString = returnString + keyMaps.get(i).fieldName + afterLast;
- return returnString;
+ stringBuilder.append(keyMaps.get(i).fieldName);
+ stringBuilder.append(afterLast);
+ return stringBuilder.toString();
}
public String keyMapUpperString(String separator, String afterLast) {