1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

cosmetics: generics

This commit is contained in:
Andrew Gvozdev 2010-01-28 20:08:25 +00:00
parent 3d60e9196b
commit fa91dcc051
3 changed files with 57 additions and 54 deletions

View file

@ -243,8 +243,7 @@ public final class PathSettingsContainer {
if(pMap != null){ if(pMap != null){
if(list == null) if(list == null)
list = new ArrayList<PathSettingsContainer>(); list = new ArrayList<PathSettingsContainer>();
for(Iterator iter = pMap.values().iterator(); iter.hasNext(); ){ for (PathSettingsContainer cr : pMap.values()) {
PathSettingsContainer cr = (PathSettingsContainer)iter.next();
if(cr.fValue == INEXISTENT_VALUE){ if(cr.fValue == INEXISTENT_VALUE){
cr.doGetDirectChildren(list); cr.doGetDirectChildren(list);
} else { } else {
@ -256,7 +255,7 @@ public final class PathSettingsContainer {
} }
public Object[] getValues(final boolean includeThis){ public Object[] getValues(final boolean includeThis){
final List list = new ArrayList(); final List<Object> list = new ArrayList<Object>();
accept(new IPathSettingsContainerVisitor(){ accept(new IPathSettingsContainerVisitor(){
public boolean visit(PathSettingsContainer container) { public boolean visit(PathSettingsContainer container) {
@ -332,8 +331,8 @@ public final class PathSettingsContainer {
return; return;
Collection c = pMap.values(); Collection<PathSettingsContainer> c = pMap.values();
PathSettingsContainer childContainers[] = (PathSettingsContainer[])c.toArray(new PathSettingsContainer[c.size()]); PathSettingsContainer childContainers[] = c.toArray(new PathSettingsContainer[c.size()]);
for (PathSettingsContainer childContainer : childContainers) { for (PathSettingsContainer childContainer : childContainers) {
childContainer.removeChildren(); childContainer.removeChildren();
@ -520,8 +519,7 @@ public final class PathSettingsContainer {
PatternNameMap pMap = getPatternChildrenMap(false); PatternNameMap pMap = getPatternChildrenMap(false);
if(pMap != null){ if(pMap != null){
for(Iterator iter = pMap.values().iterator(); iter.hasNext();){ for (PathSettingsContainer child : pMap.values()) {
PathSettingsContainer child = (PathSettingsContainer)iter.next();
if(!child.doAccept(visitor)) if(!child.doAccept(visitor))
return false; return false;
} }
@ -551,8 +549,8 @@ public final class PathSettingsContainer {
if(!moveChildren){ if(!moveChildren){
if(hasChildren()){ if(hasChildren()){
PathSettingsContainer cr = new PathSettingsContainer(fRootContainer, fDirectParentContainer, fName, fIsPatternMode); PathSettingsContainer cr = new PathSettingsContainer(fRootContainer, fDirectParentContainer, fName, fIsPatternMode);
for(Iterator iter = fPatternChildrenMap.values().iterator(); iter.hasNext();){ for(Iterator<PathSettingsContainer> iter = fPatternChildrenMap.values().iterator(); iter.hasNext();){
PathSettingsContainer child = (PathSettingsContainer)iter.next(); PathSettingsContainer child = iter.next();
iter.remove(); iter.remove();
child.setParent(cr); child.setParent(cr);
cr.connectChild(child); cr.connectChild(child);

View file

@ -18,6 +18,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Map.Entry;
import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.model.CoreModelUtil;
@ -25,9 +26,9 @@ public class PatternNameMap {
private static final char[] SPEC_CHARS = new char[]{'*', '?'}; private static final char[] SPEC_CHARS = new char[]{'*', '?'};
static final String DOUBLE_STAR_PATTERN = "**"; //$NON-NLS-1$ static final String DOUBLE_STAR_PATTERN = "**"; //$NON-NLS-1$
private Map fChildrenMap; private Map<String, PathSettingsContainer> fChildrenMap;
private Map fPatternMap; private Map<StringCharArray, PathSettingsContainer> fPatternMap;
private Collection fValues; private Collection<PathSettingsContainer> fValues;
private boolean fContainsDoubleStar; private boolean fContainsDoubleStar;
private static class StringCharArray { private static class StringCharArray {
@ -67,13 +68,13 @@ public class PatternNameMap {
} }
} }
private class EmptyIterator implements Iterator{ private class EmptyIterator implements Iterator<PathSettingsContainer>{
public boolean hasNext() { public boolean hasNext() {
return false; return false;
} }
public Object next() { public PathSettingsContainer next() {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
@ -83,27 +84,27 @@ public class PatternNameMap {
} }
private class ValuesCollection extends AbstractCollection { private class ValuesCollection extends AbstractCollection<PathSettingsContainer> {
private class Iter implements Iterator { private class Iter implements Iterator<PathSettingsContainer> {
private Iterator fEntrySetIter; private Iterator<Entry<String, PathSettingsContainer>> fEntrySetIter;
private Map.Entry fCur; private Entry<String, PathSettingsContainer> fCur;
Iter (Iterator entryIter){ Iter (Iterator<Entry<String, PathSettingsContainer>> entryIter){
this.fEntrySetIter = entryIter; this.fEntrySetIter = entryIter;
} }
public boolean hasNext() { public boolean hasNext() {
return fEntrySetIter.hasNext(); return fEntrySetIter.hasNext();
} }
public Object next() { public PathSettingsContainer next() {
fCur = (Map.Entry)fEntrySetIter.next(); fCur = fEntrySetIter.next();
return fCur.getValue(); return fCur.getValue();
} }
public void remove() { public void remove() {
fEntrySetIter.remove(); fEntrySetIter.remove();
String name = (String)fCur.getKey(); String name = fCur.getKey();
if(DOUBLE_STAR_PATTERN.equals(name)){ if(DOUBLE_STAR_PATTERN.equals(name)){
fContainsDoubleStar = false; fContainsDoubleStar = false;
} else { } else {
@ -113,8 +114,8 @@ public class PatternNameMap {
} }
@Override @Override
public Iterator iterator() { public Iterator<PathSettingsContainer> iterator() {
return fChildrenMap != null ? (Iterator)new Iter(fChildrenMap.entrySet().iterator()) : (Iterator)new EmptyIterator(); return fChildrenMap != null ? new Iter(fChildrenMap.entrySet().iterator()) : new EmptyIterator();
} }
@Override @Override
@ -133,7 +134,7 @@ public class PatternNameMap {
} }
} }
public Object get(String name){ public /* PathSettingsContainer */ Object get(String name){
return fChildrenMap != null ? fChildrenMap.get(name) : null; return fChildrenMap != null ? fChildrenMap.get(name) : null;
} }
@ -153,35 +154,35 @@ public class PatternNameMap {
return (fPatternMap != null && fPatternMap.size() != 0); return (fPatternMap != null && fPatternMap.size() != 0);
} }
public List getValues(String name){ public List<PathSettingsContainer> getValues(String name){
if(fChildrenMap == null) if(fChildrenMap == null)
return null; return null;
Object val = fChildrenMap.get(name); PathSettingsContainer val = fChildrenMap.get(name);
if(hasPatternsMap()){ if(hasPatternsMap()){
List list; List<PathSettingsContainer> list;
if(val != null){ if(val != null){
list = new ArrayList(3); list = new ArrayList<PathSettingsContainer>(3);
list.add(val); list.add(val);
} else { } else {
list = null;; list = null;
} }
Map.Entry entry; Map.Entry<PatternNameMap.StringCharArray,PathSettingsContainer> entry;
StringCharArray strCA; StringCharArray strCA;
char[] nameCharArray = name.toCharArray(); char[] nameCharArray = name.toCharArray();
for(Iterator iter = fPatternMap.entrySet().iterator(); iter.hasNext();){ for(Iterator<Map.Entry<PatternNameMap.StringCharArray,PathSettingsContainer>> iter = fPatternMap.entrySet().iterator(); iter.hasNext();){
entry = (Map.Entry)iter.next(); entry = iter.next();
strCA = (StringCharArray)entry.getKey(); strCA = entry.getKey();
if(CoreModelUtil.match(strCA.getCharArray(), nameCharArray, true)){ if(CoreModelUtil.match(strCA.getCharArray(), nameCharArray, true)){
if(list == null) if(list == null)
list = new ArrayList(2); list = new ArrayList<PathSettingsContainer>(2);
list.add(entry.getValue()); list.add(entry.getValue());
} }
} }
return list; return list;
} else if (val != null){ } else if (val != null){
List list = new ArrayList(1); List<PathSettingsContainer> list = new ArrayList<PathSettingsContainer>(1);
list.add(val); list.add(val);
return list; return list;
} }
@ -192,13 +193,17 @@ public class PatternNameMap {
return fContainsDoubleStar; return fContainsDoubleStar;
} }
public Object put(String name, Object value){ public /* PathSettingsContainer */ Object put(String name, /* PathSettingsContainer */Object value){
return put(name, (PathSettingsContainer)value);
}
private PathSettingsContainer put(String name, PathSettingsContainer value){
if(value == null) if(value == null)
return remove(name); return (PathSettingsContainer)remove(name);
Object oldValue; PathSettingsContainer oldValue;
if(fChildrenMap == null){ if(fChildrenMap == null){
fChildrenMap = new HashMap(); fChildrenMap = new HashMap<String, PathSettingsContainer>();
oldValue = null; oldValue = null;
} else { } else {
oldValue = fChildrenMap.get(name); oldValue = fChildrenMap.get(name);
@ -211,7 +216,7 @@ public class PatternNameMap {
} else if(isPatternName(name)){ } else if(isPatternName(name)){
StringCharArray strCA = new StringCharArray(name); StringCharArray strCA = new StringCharArray(name);
if(fPatternMap == null) if(fPatternMap == null)
fPatternMap = new HashMap(); fPatternMap = new HashMap<StringCharArray, PathSettingsContainer>();
fPatternMap.put(strCA, value); fPatternMap.put(strCA, value);
} }
@ -219,9 +224,9 @@ public class PatternNameMap {
return oldValue; return oldValue;
} }
public Object remove(String name){ public /* PathSettingsContainer */ Object remove(String name){
if(fChildrenMap != null){ if(fChildrenMap != null){
Object oldVal = fChildrenMap.remove(name); PathSettingsContainer oldVal = fChildrenMap.remove(name);
if(fChildrenMap.size() == 0){ if(fChildrenMap.size() == 0){
fChildrenMap = null; fChildrenMap = null;
fPatternMap = null; fPatternMap = null;
@ -263,7 +268,7 @@ public class PatternNameMap {
fContainsDoubleStar = false; fContainsDoubleStar = false;
} }
public Collection values(){ public Collection<PathSettingsContainer> values(){
if(fValues == null) if(fValues == null)
fValues = new ValuesCollection(); fValues = new ValuesCollection();
return fValues; return fValues;

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others. * Copyright (c) 2007, 2010 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -14,10 +14,10 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ThreadLocalMap { public class ThreadLocalMap {
private ThreadLocal fLocal = new ThreadLocal(); private ThreadLocal<Map<Object, Object>> fLocal = new ThreadLocal<Map<Object, Object>>();
public Object get(Object key){ public Object get(Object key){
Map map = getMap(false); Map<Object, Object> map = getMap(false);
return map != null ? map.get(key) : null; return map != null ? map.get(key) : null;
} }
@ -25,24 +25,24 @@ public class ThreadLocalMap {
if(value == null) if(value == null)
clear(key); clear(key);
else { else {
Map map = getMap(true); Map<Object, Object> map = getMap(true);
map.put(key, value); map.put(key, value);
} }
} }
public void clear(Object key){ public void clear(Object key){
Map map = getMap(false); Map<Object, Object> map = getMap(false);
if(map != null){ if(map != null){
map.remove(key); map.remove(key);
if(map == null)
fLocal.set(null);
} }
// if(map == null)
// fLocal.set(null);
} }
private Map getMap(boolean create){ private Map<Object, Object> getMap(boolean create){
Map map = (Map)fLocal.get(); Map<Object, Object> map = fLocal.get();
if(map == null && create){ if(map == null && create){
map = new HashMap(); map = new HashMap<Object, Object>();
fLocal.set(map); fLocal.set(map);
} }
return map; return map;