From d048a41b883ba0766cfff94db2e5c7dd30ed4ee0 Mon Sep 17 00:00:00 2001 From: Neale Upstone Date: Thu, 28 Dec 2023 20:20:38 +0000 Subject: [PATCH] Perf: Replace StringBuffer with StringBuilder --- .../cosmo/calendar/data/OutputFilter.java | 10 ++-- .../query/StandardItemFilterProcessor.java | 48 +++++++++---------- .../osaf/cosmo/BaseMockServletTestCase.java | 2 +- .../data/ExpandRecurringEventsTest.java | 6 +-- .../calendar/data/LimitRecurrenceSetTest.java | 6 +-- .../osaf/cosmo/dao/mock/MockDaoStorage.java | 2 +- .../org/osaf/cosmo/model/mock/MockQName.java | 2 +- .../org/osaf/cosmo/util/UriTemplateTest.java | 20 ++++---- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/core/src/main/java/org/osaf/cosmo/calendar/data/OutputFilter.java b/core/src/main/java/org/osaf/cosmo/calendar/data/OutputFilter.java index fd2aca5..1100071 100644 --- a/core/src/main/java/org/osaf/cosmo/calendar/data/OutputFilter.java +++ b/core/src/main/java/org/osaf/cosmo/calendar/data/OutputFilter.java @@ -54,7 +54,7 @@ public OutputFilter(String name) { } public void filter(Calendar calendar, - StringBuffer buffer) { + StringBuilder buffer) { // If expansion of recurrence is required what we have to do // is create a whole new calendar object with the new expanded // components in it and then write that one out. @@ -276,7 +276,7 @@ else if (comp instanceof VToDo) } private void filterProperties(PropertyList properties, - StringBuffer buffer) { + StringBuilder buffer) { if (isAllProperties()) { buffer.append(properties.toString()); return; @@ -297,7 +297,7 @@ private void filterProperties(PropertyList properties, } private void chompPropertyValue(Property property, - StringBuffer buffer) { + StringBuilder buffer) { buffer.append(property.getName()). append(property.getParameters()). append(':'). @@ -305,7 +305,7 @@ private void chompPropertyValue(Property property, } private void filterSubComponents(ComponentList subComponents, - StringBuffer buffer) { + StringBuilder buffer) { if (isAllSubComponents() && getLimit() != null) { buffer.append(subComponents.toString()); return; @@ -386,7 +386,7 @@ private boolean includeOverride(VEvent event) { } private void filterSubComponent(Component subComponent, - StringBuffer buffer) { + StringBuilder buffer) { buffer.append(Component.BEGIN). append(':'). append(subComponent.getName()). diff --git a/core/src/main/java/org/osaf/cosmo/dao/hibernate/query/StandardItemFilterProcessor.java b/core/src/main/java/org/osaf/cosmo/dao/hibernate/query/StandardItemFilterProcessor.java index 1d06180..e34b79a 100644 --- a/core/src/main/java/org/osaf/cosmo/dao/hibernate/query/StandardItemFilterProcessor.java +++ b/core/src/main/java/org/osaf/cosmo/dao/hibernate/query/StandardItemFilterProcessor.java @@ -87,9 +87,9 @@ public Set processFilter(Session session, ItemFilter filter) { * @return hibernate query built using HQL */ public Query buildQuery(Session session, ItemFilter filter) { - StringBuffer selectBuf = new StringBuffer(); - StringBuffer whereBuf = new StringBuffer(); - StringBuffer orderBuf = new StringBuffer(); + StringBuilder selectBuf = new StringBuilder(); + StringBuilder whereBuf = new StringBuilder(); + StringBuilder orderBuf = new StringBuilder(); HashMap params = new HashMap(); @@ -131,8 +131,8 @@ else if(filter instanceof ContentItemFilter) return hqlQuery; } - private void handleItemFilter(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleItemFilter(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, ItemFilter filter) { if(selectBuf.toString() != null && selectBuf.toString().isEmpty()) @@ -159,8 +159,8 @@ private void handleItemFilter(StringBuffer selectBuf, } - private void handleAttributeFilters(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleAttributeFilters(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, ItemFilter filter) { for(AttributeFilter attrFilter: filter.getAttributeFilters()) { if(attrFilter instanceof TextAttributeFilter) @@ -170,8 +170,8 @@ private void handleAttributeFilters(StringBuffer selectBuf, } } - private void handleTextAttributeFilter(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleTextAttributeFilter(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, TextAttributeFilter filter) { String alias = "ta" + params.size(); @@ -181,8 +181,8 @@ private void handleTextAttributeFilter(StringBuffer selectBuf, formatExpression(whereBuf, params, alias + ".value", filter.getValue()); } - private void handleStampFilters(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleStampFilters(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, ItemFilter filter) { for(StampFilter stampFilter: filter.getStampFilters()) { if(stampFilter instanceof EventStampFilter) @@ -192,8 +192,8 @@ private void handleStampFilters(StringBuffer selectBuf, } } - private void handleStampFilter(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleStampFilter(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, StampFilter filter) { String toAppend = ""; @@ -204,8 +204,8 @@ private void handleStampFilter(StringBuffer selectBuf, appendWhere(whereBuf, toAppend); } - private void handleAttributeFilter(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleAttributeFilter(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, AttributeFilter filter) { String param = "param" + params.size(); @@ -219,8 +219,8 @@ private void handleAttributeFilter(StringBuffer selectBuf, params.put(param, filter.getQname()); } - private void handleEventStampFilter(StringBuffer selectBuf, - StringBuffer whereBuf, HashMap params, + private void handleEventStampFilter(StringBuilder selectBuf, + StringBuilder whereBuf, HashMap params, EventStampFilter filter) { selectBuf.append(", HibBaseEventStamp es"); @@ -250,8 +250,8 @@ private void handleEventStampFilter(StringBuffer selectBuf, } } - private void handleNoteItemFilter(StringBuffer selectBuf, - StringBuffer whereBuf, StringBuffer orderBuf, HashMap params, + private void handleNoteItemFilter(StringBuilder selectBuf, + StringBuilder whereBuf, StringBuilder orderBuf, HashMap params, NoteItemFilter filter) { selectBuf.append("select i from HibNoteItem i"); handleItemFilter(selectBuf, whereBuf, params, filter); @@ -301,8 +301,8 @@ private void handleNoteItemFilter(StringBuffer selectBuf, } } - private void handleContentItemFilter(StringBuffer selectBuf, - StringBuffer whereBuf, StringBuffer orderBuf, HashMap params, + private void handleContentItemFilter(StringBuilder selectBuf, + StringBuilder whereBuf, StringBuilder orderBuf, HashMap params, ContentItemFilter filter) { if(selectBuf.toString() != null && selectBuf.toString().isEmpty()) { @@ -312,14 +312,14 @@ private void handleContentItemFilter(StringBuffer selectBuf, } - private void appendWhere(StringBuffer whereBuf, String toAppend) { + private void appendWhere(StringBuilder whereBuf, String toAppend) { if(whereBuf.toString() != null && whereBuf.toString().isEmpty()) whereBuf.append(" where ").append(toAppend); else whereBuf.append(" and ").append(toAppend); } - private void appendOrder(StringBuffer orderBuf, String toAppend) { + private void appendOrder(StringBuilder orderBuf, String toAppend) { if(orderBuf.toString() != null && orderBuf.toString().isEmpty()) orderBuf.append(" order by ").append(toAppend); else @@ -438,7 +438,7 @@ private Collection processMasterNote(NoteItem note, return results; } - private void formatExpression(StringBuffer whereBuf, + private void formatExpression(StringBuilder whereBuf, HashMap params, String propName, FilterCriteria fc) { diff --git a/core/src/test/java/org/osaf/cosmo/BaseMockServletTestCase.java b/core/src/test/java/org/osaf/cosmo/BaseMockServletTestCase.java index d42f39c..1dacb72 100644 --- a/core/src/test/java/org/osaf/cosmo/BaseMockServletTestCase.java +++ b/core/src/test/java/org/osaf/cosmo/BaseMockServletTestCase.java @@ -115,7 +115,7 @@ protected Document readXmlResponse(MockHttpServletResponse response) /** */ protected String toAbsoluteUrl(MockHttpServletRequest request, String path) { - StringBuffer url = new StringBuffer(request.getScheme()); + StringBuilder url = new StringBuilder(request.getScheme()); url.append("://").append(request.getServerName()); if ((request.isSecure() && request.getServerPort() != 443) || (request.getServerPort() != 80)) { diff --git a/core/src/test/java/org/osaf/cosmo/calendar/data/ExpandRecurringEventsTest.java b/core/src/test/java/org/osaf/cosmo/calendar/data/ExpandRecurringEventsTest.java index f464c9b..897ed3f 100644 --- a/core/src/test/java/org/osaf/cosmo/calendar/data/ExpandRecurringEventsTest.java +++ b/core/src/test/java/org/osaf/cosmo/calendar/data/ExpandRecurringEventsTest.java @@ -53,7 +53,7 @@ public void testExpandEvent() throws Exception { filter.setAllSubComponents(); filter.setAllProperties(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); @@ -106,7 +106,7 @@ public void testExpandEventWithOverrides() throws Exception { filter.setAllSubComponents(); filter.setAllProperties(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); @@ -157,7 +157,7 @@ public void REMOVEDtestExpandNonRecurringEvent() throws Exception { filter.setAllSubComponents(); filter.setAllProperties(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); diff --git a/core/src/test/java/org/osaf/cosmo/calendar/data/LimitRecurrenceSetTest.java b/core/src/test/java/org/osaf/cosmo/calendar/data/LimitRecurrenceSetTest.java index d63d497..767f32f 100644 --- a/core/src/test/java/org/osaf/cosmo/calendar/data/LimitRecurrenceSetTest.java +++ b/core/src/test/java/org/osaf/cosmo/calendar/data/LimitRecurrenceSetTest.java @@ -53,7 +53,7 @@ public void testLimitRecurrenceSet() throws Exception { filter.setAllSubComponents(); filter.setAllProperties(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); @@ -90,7 +90,7 @@ public void testLimitFloatingRecurrenceSet() throws Exception { filter.setAllSubComponents(); filter.setAllProperties(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); @@ -123,7 +123,7 @@ public void testLimitRecurrenceSetThisAndFuture() throws Exception { filter.setAllSubComponents(); filter.setAllProperties(); - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); diff --git a/core/src/test/java/org/osaf/cosmo/dao/mock/MockDaoStorage.java b/core/src/test/java/org/osaf/cosmo/dao/mock/MockDaoStorage.java index 964905d..fe484ac 100755 --- a/core/src/test/java/org/osaf/cosmo/dao/mock/MockDaoStorage.java +++ b/core/src/test/java/org/osaf/cosmo/dao/mock/MockDaoStorage.java @@ -212,7 +212,7 @@ public Set findItemChildren(Item item) { /** */ public String getItemPath(Item item) { - StringBuffer path = new StringBuffer(); + StringBuilder path = new StringBuilder(); LinkedList hierarchy = new LinkedList<>(); hierarchy.addFirst(item.getName()); diff --git a/core/src/test/java/org/osaf/cosmo/model/mock/MockQName.java b/core/src/test/java/org/osaf/cosmo/model/mock/MockQName.java index 6d766de..3ab5345 100644 --- a/core/src/test/java/org/osaf/cosmo/model/mock/MockQName.java +++ b/core/src/test/java/org/osaf/cosmo/model/mock/MockQName.java @@ -121,7 +121,7 @@ public boolean equals(Object o) { /** */ public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append("{"). append(namespace). append("}"). diff --git a/core/src/test/java/org/osaf/cosmo/util/UriTemplateTest.java b/core/src/test/java/org/osaf/cosmo/util/UriTemplateTest.java index 76912f0..bdcda3e 100644 --- a/core/src/test/java/org/osaf/cosmo/util/UriTemplateTest.java +++ b/core/src/test/java/org/osaf/cosmo/util/UriTemplateTest.java @@ -1,12 +1,12 @@ /* * Copyright 2008 Open Source Applications Foundation - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,19 +24,19 @@ public class UriTemplateTest extends TestCase { private final static int MIN_CHARCODE = 0x21; //ASCII range private final static int MAX_CHARCODE = 0x7e; //ASCII range private Random rnd = new Random(); - + public void testUnescapeSpaces() throws Exception { Assert.assertEquals("test test", UriTemplate.unescapeSegment("test+test")); } - + private String getPlaceHolder(int length) { return getPlaceHolder(length, "/{}"); } - + private String getPlaceHolder(int length, String delims) { if (length <= 0) length = 1; - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); while (result.length() < length) { char ch = (char)(rnd.nextInt(MAX_CHARCODE - MIN_CHARCODE) + MIN_CHARCODE); if (delims.indexOf(ch) < 0 && Character.isJavaIdentifierPart(ch)) @@ -44,10 +44,10 @@ private String getPlaceHolder(int length, String delims) { } return result.toString(); } - + public void testBindAbsolute() throws Exception { String username = getPlaceHolder(10); Assert.assertEquals("Error binding template: ", "/" + username + "/Inbox", new UriTemplate("/{username}/Inbox").bindAbsolute(false, "", username)); } - -} + +}