Skip to content

Commit

Permalink
project wide Collection optimization: if contains(e) remove(e) => rem…
Browse files Browse the repository at this point in the history
…ove(e)
  • Loading branch information
mbien committed Mar 3, 2022
1 parent f35b829 commit 06baf7f
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ public void addCatalogListener(CatalogListener l) {
public void removeCatalogListener(CatalogListener l) {
if (null == l)
return;
if (catalogListeners.contains(l))
catalogListeners.remove(l);
catalogListeners.remove(l);
}

public void fireCatalogListeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,8 @@ private void updatePlatformVersionModel() {
}

// We don't support J2EE 1.3 and J2EE 1.4 anymore
if (profiles.contains(Profile.J2EE_13)) {
profiles.remove(Profile.J2EE_13);
}
if (profiles.contains(Profile.J2EE_14)) {
profiles.remove(Profile.J2EE_14);
}
profiles.remove(Profile.J2EE_13);
profiles.remove(Profile.J2EE_14);

// We want to have Java EE 6 Full profile for all project types except Web project
if (J2eeModule.Type.WAR.equals(projectType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ public void addCatalogListener(CatalogListener l) {
public void removeCatalogListener(CatalogListener l) {
if (null == l)
return;
if (catalogListeners.contains(l))
catalogListeners.remove(l);
catalogListeners.remove(l);
}

public void fireCatalogListeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ public boolean complete(Map<Object, CompletionProposal> proposals, CompletionCon
Map<FieldSignature, CompletionItem> result = new CompleteElementHandler(context).getFields();

FieldSignature prefixFieldSignature = new FieldSignature(context.getPrefix());
if (result.containsKey(prefixFieldSignature)) {
result.remove(prefixFieldSignature);
}
result.remove(prefixFieldSignature);
for (Map.Entry<FieldSignature, CompletionItem> e :result.entrySet()) {
proposals.putIfAbsent(e.getKey(), e.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public void removeAllUpdates() {
}

public void removeUpdateForSelectedRow(int row) {
if(changedData.containsKey(Integer.valueOf(row))){
changedData.remove(Integer.valueOf(row));
}
changedData.remove(Integer.valueOf(row));
}

public Set<Integer> getUpdateKeys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ private String getValue() {

private void updateHistory() {
String value = getValue();
if (history.contains(value)) {
history.remove(value); // move item to top
}
history.remove(value); // move item to top
history.add(0, value);
// assure it won't hold more than MAX_ITEMS
if (history.size() > MAX_HISTORY_ITEMS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,7 @@ public void updateTemplatesLRU(final FileObject template) {

String templateName = template.getPath();

if ( getRecentTemplates().contains( templateName ) ) {
getRecentTemplates().remove( templateName );
}
getRecentTemplates().remove(templateName);
getRecentTemplates().add( 0, templateName );

if ( getRecentTemplates().size() > 100 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ public void registerFinishedItem(Item item) {
list = new ArrayList<BuildExecutionSupport.ActionItem>();
historyItems.put(action, list);
}
if (list.contains(ai)) {
list.remove(ai);
}
list.remove(ai);
list.add(ai);
if (list.size() > HISTORY_MAX) {
list.remove(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3228,8 +3228,7 @@ public void setType(String t) {
t = null;
String oldType = type;
type = t;
if (schemaTypeDefs.containsKey(oldType)) // FIXME
schemaTypeDefs.remove(oldType);
schemaTypeDefs.remove(oldType); // FIXME
if (t == null)
return;
putSchemaTypeDef(type, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public static void storePlatform(
if(!javacProfile.equals(props.getProperty(javacProfileKey))) {
props.setProperty(javacProfileKey, javacProfile);
}
} else if (props.containsKey(javacProfileKey)) {
} else {
props.remove(javacProfileKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,7 @@ private void removeSourceLocation(String location) {
Iterator<JavaProjectGenerator.JavaCompilationUnit> it = javaCompilationUnitsList.iterator();
while (it.hasNext()) {
JavaProjectGenerator.JavaCompilationUnit cu = it.next();
if (cu.packageRoots.contains(location)) {
cu.packageRoots.remove(location);
}
cu.packageRoots.remove(location);
if (cu.packageRoots.size() == 0) {
it.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,8 @@ public boolean addUnloadedTopComponent(String tcID) {

public boolean removeUnloadedTopComponent(String tcID) {
synchronized(LOCK_TOPCOMPONENTS) {
if(openingTopComponents.contains(tcID)) {
openingTopComponents.remove(tcID);
}
if(closingTopComponents.contains(tcID)) {
closingTopComponents.remove(tcID);
}
openingTopComponents.remove(tcID);
closingTopComponents.remove(tcID);
return topComponents.remove(tcID);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ boolean getFiltersMode() {

void addRowFilter(RowFilter filter) {
if (filters == null) filters = new HashSet();
if (filters.contains(filter)) filters.remove(filter);
filters.remove(filter);
filters.add(filter);
refreshRowFilter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public UniqueVariableNameFinder() {
}

public void addPattern(String pattern, int count) {
if(varDeclMap.containsKey(pattern))
varDeclMap.remove(pattern);
varDeclMap.remove(pattern);
varDeclMap.put(pattern, new Integer(count));
}

Expand Down

0 comments on commit 06baf7f

Please sign in to comment.