Skip to content

Commit

Permalink
chore: replace LinkedList with ArrayList
Browse files Browse the repository at this point in the history
supposedly improving performance
  • Loading branch information
CarstenWickner committed Sep 17, 2021
1 parent 1969990 commit decca29
Show file tree
Hide file tree
Showing 34 changed files with 107 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -126,7 +127,7 @@ public synchronized void setInterviewText(final Interview interview, final Strin
* @return tokenized text
*/
private List<TextToken> determineTokensFromText(final String text) {
final List<TextToken> paragraphs = new LinkedList<>();
final List<TextToken> paragraphs = new ArrayList<>();
// split text into paragraphs at line separators
for (final String singleParagraph : text.split(ModelHandlerImpl.REGEX_PARAGRAPH_SEPARATOR)) {
// separate paragraph into tokens (ideally words) at whitespaces
Expand Down Expand Up @@ -401,10 +402,10 @@ private void resolveIntersectedCategoryAssignments(final List<List<TextToken>> p
* even part (second, fourth, ...)
*/
private List<List<TextToken>> collectInterruptedSelectionParts(final List<TextToken> selectedTokens) {
final List<List<TextToken>> parts = new LinkedList<>();
final List<List<TextToken>> parts = new ArrayList<>();
// determine the first token out of the targeted range to end the following loop on
final TextToken firstTokenAfterSelection = selectedTokens.get(selectedTokens.size() - 1).getFollowingToken();
List<TextToken> currentPart = new LinkedList<>();
List<TextToken> currentPart = new ArrayList<>();
// alternate between selected and unselected sections (i.e. token ranges)
boolean currentPartSelected = true;
TextToken currentToken = selectedTokens.get(0);
Expand All @@ -415,7 +416,7 @@ private List<List<TextToken>> collectInterruptedSelectionParts(final List<TextTo
// add current part to result list
parts.add(currentPart);
// create a new part list
currentPart = new LinkedList<>();
currentPart = new ArrayList<>();
}
currentPart.add(currentToken);
currentToken = currentToken.getFollowingToken();
Expand Down Expand Up @@ -734,7 +735,7 @@ public Map<Interview, Map<List<DetailCategory>, AtomicLong>> extractDetailPatter
// iterate over all given interviews
for (final Interview singleInterview : interviews) {
final Map<List<DetailCategory>, AtomicLong> patternOccurences = new HashMap<>();
final List<List<DetailCategory>> currentPattern = new LinkedList<>();
final List<List<DetailCategory>> currentPattern = new ArrayList<>();
// iterate over the whole detail category sequence
for (final DetailCategory singleDetail : this.extractDetailSequence(singleInterview)) {
currentPattern.add(new ArrayList<>(maxLength));
Expand Down Expand Up @@ -766,7 +767,7 @@ public Map<Interview, Map<List<DetailCategory>, AtomicLong>> extractDetailPatter

@Override
public List<DetailCategory> extractDetailSequence(final Interview interview) {
final List<DetailCategory> sequence = new LinkedList<>();
final List<DetailCategory> sequence = new ArrayList<>();
// iterate over all paragraphs
for (final TextToken singleParagraph : interview.getText()) {
// iterate over all tokens of the current paragraph
Expand Down Expand Up @@ -904,7 +905,7 @@ private void appendCategoryStringForToken(final StringBuilder builder, final Tex
private static class CategoryConflictHandler {

/** Registered unresolved detail category changes, i.e. started but not ended and/or ended but not started. */
final LinkedList<Boolean> categoryChanges = new LinkedList<>();
final Deque<Boolean> categoryChanges = new LinkedList<>();

/**
* Add another start or end of a detail category to this conflict handler.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -188,7 +188,7 @@ public Entry<AisProject, List<?>> parseModelFromXml(final Document doc, final Fi
// retrieve interviews from document
final Element interviewRoot = DomUtil.getChildElement(doc.getDocumentElement(), ModelParseServiceImpl.TAG_INTERVIEW_ROOT);
if (interviewRoot != null) {
final List<Interview> containedInterviews = new LinkedList<>();
final List<Interview> containedInterviews = new ArrayList<>();
for (final Element singleInterview : DomUtil.getChildElements(interviewRoot, ModelParseServiceImpl.TAG_INTERVIEW)) {
containedInterviews.add(this.parseInterviewFromXml(singleInterview, categories));
}
Expand Down Expand Up @@ -287,7 +287,7 @@ MutableDetailCategoryModel parseDetailCategoriesFromXml(final Document doc) thro
*/
private List<DetailCategory> parseDetailCategoriesFromXmlRecursively(final List<Element> categories, final DetailCategory parentCategory)
throws HmxException {
final List<DetailCategory> result = new LinkedList<>();
final List<DetailCategory> result = new ArrayList<>();
for (final Element singleCategoryElement : categories) {
// parse mandatory category attributes
final String code = singleCategoryElement.getAttribute(ModelParseServiceImpl.ATTR_CATEGORY_CODE);
Expand Down Expand Up @@ -458,7 +458,7 @@ private Interview parseInterviewFromXml(final Element interviewElement, final Mu
throw new HmxException(Message.ERROR_FILE_INVALID, new IllegalArgumentException("invalid " + ModelParseServiceImpl.TAG_INTERVIEW
+ " definition"));
}
final List<TextToken> text = new LinkedList<>();
final List<TextToken> text = new ArrayList<>();
for (final Element singleParagraph : DomUtil.getChildElements(interviewElement, ModelParseServiceImpl.TAG_INTERVIEW_PARAGRAPH)) {
text.add(this.parseTextParagraphFromXml(singleParagraph, categories));
}
Expand Down Expand Up @@ -556,7 +556,7 @@ private Element parseXmlFromOpenViewElements(final Document doc, final List<?> o
* @return successfully parsed list of model elements that were open in the view, when the document was created
*/
private List<Object> parseOpenViewElementsFromXml(final Document doc, final AisProject parsedProject) {
final List<Object> openViewElements = new LinkedList<>();
final List<Object> openViewElements = new ArrayList<>();
final Element viewsRoot = DomUtil.getChildElement(doc.getDocumentElement(), ModelParseServiceImpl.TAG_VIEWS);
if (viewsRoot != null) {
for (final Element singleView : DomUtil.getChildElements(viewsRoot)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

Expand Down Expand Up @@ -67,7 +67,7 @@ public void testParseModelToAndFromXml_1() throws HmxException {
modelHandler.setInterviewText(modelHandler.createInterview("a"), "1 2 3\n4 5 6 7 8 9\n10");
modelHandler.createInterview("b");
// all interview views open, and a sub model group
final List<Object> openViewElements = new LinkedList<>(model.getInterviews());
final List<Object> openViewElements = new ArrayList<>(model.getInterviews());
openViewElements.add("a");
final Document xml = this.service.parseXmlFromModel(model, openViewElements);
final Entry<AisProject, List<?>> parsed = this.service.parseModelFromXml(xml, new File("test.aisp"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
Expand All @@ -25,8 +25,8 @@ public class AisMessageTest {
public void testMessageAvailability() {
final ResourceBundle bundle = ResourceBundle.getBundle(AisMessage.class.getName(), Locale.ENGLISH, new XmlResourceBundleControl());
Assert.assertNotNull(bundle);
final List<String> unusedMessages = new LinkedList<>();
final List<String> unavailableMessages = new LinkedList<>();
final List<String> unusedMessages = new ArrayList<>();
final List<String> unavailableMessages = new ArrayList<>();
final Enumeration<String> availableKeys = bundle.getKeys();
while (availableKeys.hasMoreElements()) {
unusedMessages.add(availableKeys.nextElement());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand All @@ -40,7 +39,7 @@ public final class AisProject implements IMultiObjectModel<AisProject, Interview
/** The detail categories that can be used for scoring tokens in interviews. */
private final List<DetailCategory> categories;
/** The contained interviews. */
private final List<Interview> interviews = new LinkedList<>();
private final List<Interview> interviews = new ArrayList<>();

/**
* Main constructor.
Expand Down Expand Up @@ -129,7 +128,7 @@ public Map<String, List<Interview>> getSubModelObjects() {
if (subModelMap.containsKey(groupKey)) {
groupedInterviews = subModelMap.get(groupKey);
} else {
groupedInterviews = new LinkedList<>();
groupedInterviews = new ArrayList<>();
subModelMap.put(groupKey, groupedInterviews);
}
groupedInterviews.add(singleInterview);
Expand All @@ -144,7 +143,7 @@ public List<DetailCategory> provide() {

@Override
public List<DetailCategory> provideSelectables() {
final List<DetailCategory> selectables = new LinkedList<>();
final List<DetailCategory> selectables = new ArrayList<>();
for (final DetailCategory singleCategory : this.categories) {
if (singleCategory.isSelectable()) {
selectables.add(singleCategory);
Expand All @@ -155,7 +154,7 @@ public List<DetailCategory> provideSelectables() {

@Override
public AisProject clone() {
final List<Interview> clonedInterviews = new LinkedList<>();
final List<Interview> clonedInterviews = new ArrayList<>();
for (final Interview singleInterview : this.getInterviews()) {
clonedInterviews.add(singleInterview.clone());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

import org.hmx.scitos.domain.IModel;
Expand All @@ -36,7 +36,7 @@ public final class Interview implements IModel<Interview>, Comparable<Interview>
/** The index (i.e. number) of this interview in the project containing it. */
private int index;
/** The actual interview including assigned details (i.e. applied scoring). */
private final List<TextToken> text = new LinkedList<>();
private final List<TextToken> text = new ArrayList<>();

/**
* Main constructor.
Expand Down Expand Up @@ -127,7 +127,7 @@ public Interview setText(final List<TextToken> text) {
public Interview reset(final Interview replacingState) {
this.setParticipantId(replacingState.getParticipantId());
this.setIndex(replacingState.getIndex());
final List<TextToken> copiedParagraphs = new LinkedList<>();
final List<TextToken> copiedParagraphs = new ArrayList<>();
for (final TextToken singleParagraph : replacingState.getText()) {
copiedParagraphs.add(singleParagraph.clone());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -94,7 +93,7 @@ public List<DetailCategory> provide() {

@Override
public List<DetailCategory> provideSelectables() {
final List<DetailCategory> selectables = new LinkedList<>();
final List<DetailCategory> selectables = new ArrayList<>();
for (final DetailCategory singleCategory : this.categoryByCode.values()) {
if (singleCategory.isSelectable()) {
selectables.add(singleCategory);
Expand All @@ -120,7 +119,7 @@ public List<DetailCategory> getRootCategories() {
* @return detail category that have the given one as their parent
*/
public List<DetailCategory> getChildCategories(final DetailCategory parent) {
final List<DetailCategory> children = new LinkedList<>();
final List<DetailCategory> children = new ArrayList<>();
for (final DetailCategory singleCategory : this.categoryByCode.values()) {
if (ComparisonUtil.isNullAwareEqual(singleCategory.getParent(), parent)) {
children.add(singleCategory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -57,7 +57,7 @@ public final class AisViewProject implements IViewProject<AisProject>, ModelChan
/** The path this project has been loaded from and/or last saved to. It is used as the default path for the next requested save operation. */
private File savePath;
/** The elements displayed in open tabs when this view project was last loaded/saved. */
private final List<Object> openTabElements = new LinkedList<>();
private final List<Object> openTabElements = new ArrayList<>();

/**
* Creates a new project in the specified {@link ScitosClient}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.awt.Component;
import java.awt.LayoutManager;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JMenuItem;
Expand Down Expand Up @@ -67,7 +67,7 @@ protected AbstractAisProjectView(final AisViewProject project, final M model, fi

@Override
public List<JMenuItem> createEditMenuItems() {
final List<JMenuItem> editMenuItems = new LinkedList<>();
final List<JMenuItem> editMenuItems = new ArrayList<>();
final JMenuItem importInterviewsItem = new JMenuItem(AisMessage.PROJECT_IMPORT_INTERVIEWS.get(), ScitosIcon.FILE_ODS.create());
importInterviewsItem.addActionListener(event -> this.getProject().importInterviewsFromOds());
editMenuItems.add(importInterviewsItem);
Expand All @@ -83,7 +83,7 @@ public List<JMenuItem> createEditMenuItems() {

@Override
public List<Component> createToolBarItems() {
final List<Component> toolBarItems = new LinkedList<>();
final List<Component> toolBarItems = new ArrayList<>();
final JButton addInterviewButton = new JButton(ScitosIcon.CLIPBOARD_ADD.create());
addInterviewButton.setToolTipText(AisMessage.INTERVIEW_NEW.get());
addInterviewButton.addActionListener(event -> this.createInterview());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.awt.Color;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -61,7 +62,7 @@ final class DetailCategoryTreeModel extends AbstractTreeTableModel {
super(new Object());
final MutableDetailCategoryModel model = new MutableDetailCategoryModel();
model.addAll(categoryProvider.provide());
this.rootCategories = new LinkedList<>();
this.rootCategories = new ArrayList<>();
this.categoryChildren = new HashMap<>();
for (final DetailCategory singleRoot : model.getRootCategories()) {
this.rootCategories.add(this.addCategoryTreeToMap(model, singleRoot));
Expand All @@ -79,7 +80,7 @@ final class DetailCategoryTreeModel extends AbstractTreeTableModel {
* @return row object representing the given category
*/
private DetailCategoryRow addCategoryTreeToMap(final MutableDetailCategoryModel model, final DetailCategory detail) {
final List<DetailCategoryRow> children = new LinkedList<>();
final List<DetailCategoryRow> children = new ArrayList<>();
for (final DetailCategory singleChild : model.getChildCategories(detail)) {
children.add(this.addCategoryTreeToMap(model, singleChild));
}
Expand All @@ -106,7 +107,7 @@ TreePath addChildCategoryRow(final TreePath parent) {
} else {
final Object parentRow = parent.getLastPathComponent();
if (!this.categoryChildren.containsKey(parentRow)) {
this.categoryChildren.put((DetailCategoryRow) parentRow, new LinkedList<>());
this.categoryChildren.put((DetailCategoryRow) parentRow, new ArrayList<>());
}
parentsChildren = this.categoryChildren.get(parentRow);
// inherit color from parent
Expand Down Expand Up @@ -313,7 +314,7 @@ public void setValueAt(final Object value, final Object node, final int column)
* @return all detail categories in unsorted list
*/
private List<DetailCategoryRow> getFlatCategoryList() {
final List<DetailCategoryRow> categories = new LinkedList<>(this.rootCategories);
final List<DetailCategoryRow> categories = new ArrayList<>(this.rootCategories);
for (final List<DetailCategoryRow> childCategories : this.categoryChildren.values()) {
categories.addAll(childCategories);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
Expand Down Expand Up @@ -227,7 +227,7 @@ final boolean containsValidSelection() {
* @return selected text token ui components
*/
final List<TextTokenComponent> getSelection() {
final List<TextTokenComponent> selection = new LinkedList<>();
final List<TextTokenComponent> selection = new ArrayList<>();
for (final Component singleParagraph : this.getViewPortView().getComponents()) {
for (final Component singleToken : ((Container) singleParagraph).getComponents()) {
if (((TextTokenComponent) singleToken).isSelected()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
Expand All @@ -50,7 +50,7 @@ public final class InterviewView extends AbstractAisProjectView<Interview> {
*/
private IUndoManagedView viewPanel;
/** The main tool bar items that belong to this view – in order to enable/disable them according to the current selection. */
private final List<JButton> detailToolBarItems = new LinkedList<>();
private final List<JButton> detailToolBarItems = new ArrayList<>();

/**
* Main constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.hmx.scitos.core;

import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

import org.hmx.scitos.domain.IModel;
Expand Down Expand Up @@ -48,7 +48,7 @@ public abstract class AbstractModelHandler<M extends IModel<M>> implements IMode
*/
protected AbstractModelHandler(final M model) {
this.model = model;
this.listeners = new LinkedList<>();
this.listeners = new ArrayList<>();
}

@Override
Expand Down
Loading

0 comments on commit decca29

Please sign in to comment.