Author: doogie
Date: Thu Aug 14 08:13:53 2008 New Revision: 685938 URL: http://svn.apache.org/viewvc?rev=685938&view=rev Log: Generics, StringBuilder, for-loop, Number.valueOf. Modified: ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Modified: ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java?rev=685938&r1=685937&r2=685938&view=diff ============================================================================== --- ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java (original) +++ ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/marketing/MarketingServices.java Thu Aug 14 08:13:53 2008 @@ -43,7 +43,7 @@ public static final String resourceMarketing = "MarketingUiLabels"; public static final String resourceOrder = "OrderUiLabels"; - public static Map signUpForContactList(DispatchContext dctx, Map context) { + public static Map<String, Object> signUpForContactList(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); @@ -59,7 +59,7 @@ try { // locate the contact list - Map input = UtilMisc.toMap("contactListId", contactListId); + Map<String, Object> input = UtilMisc.<String, Object>toMap("contactListId", contactListId); GenericValue contactList = delegator.findByPrimaryKey("ContactList", input); if (contactList == null) { String error = UtilProperties.getMessage(resourceMarketing, "ContactListNotFound", input, locale); @@ -71,7 +71,7 @@ // associate the email with anonymous user TODO: do we need a custom contact mech purpose type, say MARKETING_EMAIL? input = UtilMisc.toMap("userLogin", userLogin, "emailAddress", email, "partyId", "_NA_", "fromDate", fromDate, "contactMechPurposeTypeId", "OTHER_EMAIL"); - Map serviceResults = dispatcher.runSync("createPartyEmailAddress", input); + Map<String, Object> serviceResults = dispatcher.runSync("createPartyEmailAddress", input); if (ServiceUtil.isError(serviceResults)) { throw new GenericServiceException(ServiceUtil.getErrorMessage(serviceResults)); } Modified: ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java?rev=685938&r1=685937&r2=685938&view=diff ============================================================================== --- ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java (original) +++ ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/report/ReportHelper.java Thu Aug 14 08:13:53 2008 @@ -22,6 +22,8 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.util.EntityUtil; import java.util.*; +import javolution.util.FastList; +import javolution.util.FastMap; /** * Marketing Report Helper @@ -39,41 +41,40 @@ * @return a List of Maps with keys (${keyFieldName}, visits - # visits, orders - # orders, orderAmount - total amount of orders, * conversionRate - # orders/# visits */ - public static List calcConversionRates(List visits, List orders, String keyFieldName) { - List conversionRates = new ArrayList(); + public static List<Map<String, Object>> calcConversionRates(List<GenericValue> visits, List<GenericValue> orders, String keyFieldName) { + List<Map<String, Object>> conversionRates = FastList.newInstance(); // loop through all the visits - for (Iterator vit = visits.iterator(); vit.hasNext(); ) { - GenericValue visit = (GenericValue) vit.next(); - Map reportValue = new HashMap(); + for (GenericValue visit: visits) { + Map<String, Object> reportValue = FastMap.newInstance(); reportValue.put(keyFieldName, visit.getString(keyFieldName)); reportValue.put("visits", visit.getLong("visitId")); // actually # of visits // find the matching entry in orders for the given key field - List ordersForThisKey = EntityUtil.filterByAnd(orders, UtilMisc.toMap(keyFieldName, visit.getString(keyFieldName))); + List<GenericValue> ordersForThisKey = EntityUtil.filterByAnd(orders, UtilMisc.toMap(keyFieldName, visit.getString(keyFieldName))); // if there are matching orders, then calculate orders, order amount, and conversion rate if ((ordersForThisKey != null) && (ordersForThisKey.size() > 0)) { // note: there should be only one line of order stats per key, so .get(0) should work - GenericValue orderValue = (GenericValue) ordersForThisKey.get(0); + GenericValue orderValue = ordersForThisKey.get(0); reportValue.put("orders", orderValue.getLong("orderId")); // # of orders if (orderValue.getDouble("grandTotal") == null) { - reportValue.put("orderAmount", new Double(0)); + reportValue.put("orderAmount", Double.valueOf(0)); } else { reportValue.put("orderAmount", orderValue.getDouble("grandTotal")); } if ((orderValue.getLong("orderId") == null) || (visit.getLong("visitId") == null) || (visit.getLong("visitId").intValue() == 0)) { - reportValue.put("conversionRate", new Double(0)); + reportValue.put("conversionRate", Double.valueOf(0)); } else { - reportValue.put("conversionRate", new Double(orderValue.getLong("orderId").doubleValue() / visit.getLong("visitId").doubleValue())); + reportValue.put("conversionRate", Double.valueOf(orderValue.getLong("orderId").doubleValue() / visit.getLong("visitId").doubleValue())); } } else { // no matching orders - all those values are zeroes - reportValue.put("orders", new Long(0)); - reportValue.put("orderAmount", new Double(0)); - reportValue.put("conversionRate", new Double(0)); + reportValue.put("orders", Long.valueOf(0)); + reportValue.put("orderAmount", Double.valueOf(0)); + reportValue.put("conversionRate", Double.valueOf(0)); } conversionRates.add(reportValue); Modified: ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java?rev=685938&r1=685937&r2=685938&view=diff ============================================================================== --- ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java (original) +++ ofbiz/trunk/applications/marketing/src/org/ofbiz/marketing/tracking/TrackingCodeEvents.java Thu Aug 14 08:13:53 2008 @@ -147,9 +147,9 @@ trackingCode.set("lastModifiedDate", UtilDateTime.nowTimestamp()); //use nearly unlimited trackable lifetime: 10 billion seconds, 310 years - trackingCode.set("trackableLifetime", new Long(10000000000L)); + trackingCode.set("trackableLifetime", Long.valueOf(10000000000L)); //use 2592000 seconds as billable lifetime: equals 1 month - trackingCode.set("billableLifetime", new Long(2592000)); + trackingCode.set("billableLifetime", Long.valueOf(2592000)); trackingCode.set("comments", "This TrackingCode has default values because no default TrackingCode could be found."); 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=685938&r1=685937&r2=685938&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 Aug 14 08:13:53 2008 @@ -68,10 +68,10 @@ public class VCard { public static final String module = VCard.class.getName(); - public static Map importVCard(DispatchContext dctx, Map context) { + public static Map<String, Object> importVCard(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = (LocalDispatcher) dctx.getDispatcher(); GenericDelegator delegator = (GenericDelegator) dctx.getDelegator(); - Map result = ServiceUtil.returnSuccess(); + Map<String, Object> result = ServiceUtil.returnSuccess(); Address workAddress = null; String email = null; String phone = null; @@ -81,15 +81,15 @@ try { ContactIOFactory ciof = Pim.getContactIOFactory(); ContactUnmarshaller unmarshaller = ciof.createContactUnmarshaller(); - Contact[] contact = unmarshaller.unmarshallContacts(in); + Contact[] contacts = unmarshaller.unmarshallContacts(in); - for (int i = 0; i < contact.length; i++) { - PersonalIdentity pid = contact[i].getPersonalIdentity(); - Map serviceCtx = UtilMisc.toMap("firstName", pid.getFirstname(), "lastName", pid.getLastname()); + for (Contact contact: contacts) { + PersonalIdentity pid = contact.getPersonalIdentity(); + Map<String, Object> serviceCtx = UtilMisc.<String, Object>toMap("firstName", pid.getFirstname(), "lastName", pid.getLastname()); - for (Iterator iter = contact[i].getAddresses(); iter.hasNext();) { + for (Iterator iter = contact.getAddresses(); iter.hasNext();) { Address address = (AddressImpl) iter.next(); - if (contact[i].isPreferredAddress(address)) { + if (contact.isPreferredAddress(address)) { workAddress = address; break; } else if (address.isWork()) { @@ -114,7 +114,7 @@ GenericValue stateGeo = EntityUtil.getFirst(delegator.findList("Geo", condition, null, null, null, true)); serviceCtx.put("stateProvinceGeoId", stateGeo.get("geoId")); - Communications communications = contact[i].getCommunications(); + Communications communications = contact.getCommunications(); for (Iterator iter = communications.getEmailAddresses(); iter.hasNext();) { EmailAddress emailAddress = (EmailAddressImpl) iter.next(); if (communications.isPreferredEmailAddress(emailAddress)) { @@ -139,11 +139,11 @@ continue; } } - String[] number = phone.split("\\D"); + String[] numberParts = phone.split("\\D"); String telNumber = ""; - for (int j = 0; j < number.length; j++) { - if (number[j] != "") { - telNumber = telNumber + number[j]; + for (String number: numberParts) { + if (number != "") { + telNumber = telNumber + number; } } serviceCtx.put("areaCode", telNumber.substring(0, 3)); @@ -152,7 +152,7 @@ GenericValue userLogin = (GenericValue) context.get("userLogin"); serviceCtx.put("userLogin", userLogin); String serviceName = (String) context.get("serviceName"); - Map resp = dispatcher.runSync(serviceName, serviceCtx); + Map<String, Object> resp = dispatcher.runSync(serviceName, serviceCtx); result.put("partyId", resp.get("partyId")); } } catch (GenericEntityException e) { @@ -165,7 +165,7 @@ return result; } - public static Map exportVCard(DispatchContext dctx, Map context) { + public static Map<String, Object> exportVCard(DispatchContext dctx, Map<String, ? extends Object> context) { GenericDelegator delegator = (GenericDelegator) dctx.getDelegator(); String partyId = (String) context.get("partyId"); File file = null; |
Free forum by Nabble | Edit this page |