diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathSettingsContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathSettingsContainer.java index f4f35c94bd3..0b04dcab0f7 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathSettingsContainer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathSettingsContainer.java @@ -243,8 +243,7 @@ public final class PathSettingsContainer { if(pMap != null){ if(list == null) list = new ArrayList(); - for(Iterator iter = pMap.values().iterator(); iter.hasNext(); ){ - PathSettingsContainer cr = (PathSettingsContainer)iter.next(); + for (PathSettingsContainer cr : pMap.values()) { if(cr.fValue == INEXISTENT_VALUE){ cr.doGetDirectChildren(list); } else { @@ -256,7 +255,7 @@ public final class PathSettingsContainer { } public Object[] getValues(final boolean includeThis){ - final List list = new ArrayList(); + final List list = new ArrayList(); accept(new IPathSettingsContainerVisitor(){ public boolean visit(PathSettingsContainer container) { @@ -332,8 +331,8 @@ public final class PathSettingsContainer { return; - Collection c = pMap.values(); - PathSettingsContainer childContainers[] = (PathSettingsContainer[])c.toArray(new PathSettingsContainer[c.size()]); + Collection c = pMap.values(); + PathSettingsContainer childContainers[] = c.toArray(new PathSettingsContainer[c.size()]); for (PathSettingsContainer childContainer : childContainers) { childContainer.removeChildren(); @@ -520,8 +519,7 @@ public final class PathSettingsContainer { PatternNameMap pMap = getPatternChildrenMap(false); if(pMap != null){ - for(Iterator iter = pMap.values().iterator(); iter.hasNext();){ - PathSettingsContainer child = (PathSettingsContainer)iter.next(); + for (PathSettingsContainer child : pMap.values()) { if(!child.doAccept(visitor)) return false; } @@ -551,8 +549,8 @@ public final class PathSettingsContainer { if(!moveChildren){ if(hasChildren()){ PathSettingsContainer cr = new PathSettingsContainer(fRootContainer, fDirectParentContainer, fName, fIsPatternMode); - for(Iterator iter = fPatternChildrenMap.values().iterator(); iter.hasNext();){ - PathSettingsContainer child = (PathSettingsContainer)iter.next(); + for(Iterator iter = fPatternChildrenMap.values().iterator(); iter.hasNext();){ + PathSettingsContainer child = iter.next(); iter.remove(); child.setParent(cr); cr.connectChild(child); diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PatternNameMap.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PatternNameMap.java index 9caffb18251..36a96155035 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PatternNameMap.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PatternNameMap.java @@ -18,6 +18,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Map.Entry; import org.eclipse.cdt.core.model.CoreModelUtil; @@ -25,9 +26,9 @@ public class PatternNameMap { private static final char[] SPEC_CHARS = new char[]{'*', '?'}; static final String DOUBLE_STAR_PATTERN = "**"; //$NON-NLS-1$ - private Map fChildrenMap; - private Map fPatternMap; - private Collection fValues; + private Map fChildrenMap; + private Map fPatternMap; + private Collection fValues; private boolean fContainsDoubleStar; private static class StringCharArray { @@ -67,13 +68,13 @@ public class PatternNameMap { } } - private class EmptyIterator implements Iterator{ + private class EmptyIterator implements Iterator{ public boolean hasNext() { return false; } - public Object next() { + public PathSettingsContainer next() { throw new NoSuchElementException(); } @@ -83,27 +84,27 @@ public class PatternNameMap { } - private class ValuesCollection extends AbstractCollection { + private class ValuesCollection extends AbstractCollection { - private class Iter implements Iterator { - private Iterator fEntrySetIter; - private Map.Entry fCur; + private class Iter implements Iterator { + private Iterator> fEntrySetIter; + private Entry fCur; - Iter (Iterator entryIter){ + Iter (Iterator> entryIter){ this.fEntrySetIter = entryIter; } public boolean hasNext() { return fEntrySetIter.hasNext(); } - public Object next() { - fCur = (Map.Entry)fEntrySetIter.next(); + public PathSettingsContainer next() { + fCur = fEntrySetIter.next(); return fCur.getValue(); } public void remove() { fEntrySetIter.remove(); - String name = (String)fCur.getKey(); + String name = fCur.getKey(); if(DOUBLE_STAR_PATTERN.equals(name)){ fContainsDoubleStar = false; } else { @@ -113,8 +114,8 @@ public class PatternNameMap { } @Override - public Iterator iterator() { - return fChildrenMap != null ? (Iterator)new Iter(fChildrenMap.entrySet().iterator()) : (Iterator)new EmptyIterator(); + public Iterator iterator() { + return fChildrenMap != null ? new Iter(fChildrenMap.entrySet().iterator()) : new EmptyIterator(); } @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; } @@ -153,35 +154,35 @@ public class PatternNameMap { return (fPatternMap != null && fPatternMap.size() != 0); } - public List getValues(String name){ + public List getValues(String name){ if(fChildrenMap == null) return null; - Object val = fChildrenMap.get(name); + PathSettingsContainer val = fChildrenMap.get(name); if(hasPatternsMap()){ - List list; + List list; if(val != null){ - list = new ArrayList(3); + list = new ArrayList(3); list.add(val); } else { - list = null;; + list = null; } - Map.Entry entry; + Map.Entry entry; StringCharArray strCA; char[] nameCharArray = name.toCharArray(); - for(Iterator iter = fPatternMap.entrySet().iterator(); iter.hasNext();){ - entry = (Map.Entry)iter.next(); - strCA = (StringCharArray)entry.getKey(); + for(Iterator> iter = fPatternMap.entrySet().iterator(); iter.hasNext();){ + entry = iter.next(); + strCA = entry.getKey(); if(CoreModelUtil.match(strCA.getCharArray(), nameCharArray, true)){ if(list == null) - list = new ArrayList(2); + list = new ArrayList(2); list.add(entry.getValue()); } } return list; } else if (val != null){ - List list = new ArrayList(1); + List list = new ArrayList(1); list.add(val); return list; } @@ -192,13 +193,17 @@ public class PatternNameMap { 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) - return remove(name); + return (PathSettingsContainer)remove(name); - Object oldValue; + PathSettingsContainer oldValue; if(fChildrenMap == null){ - fChildrenMap = new HashMap(); + fChildrenMap = new HashMap(); oldValue = null; } else { oldValue = fChildrenMap.get(name); @@ -211,7 +216,7 @@ public class PatternNameMap { } else if(isPatternName(name)){ StringCharArray strCA = new StringCharArray(name); if(fPatternMap == null) - fPatternMap = new HashMap(); + fPatternMap = new HashMap(); fPatternMap.put(strCA, value); } @@ -219,9 +224,9 @@ public class PatternNameMap { return oldValue; } - public Object remove(String name){ + public /* PathSettingsContainer */ Object remove(String name){ if(fChildrenMap != null){ - Object oldVal = fChildrenMap.remove(name); + PathSettingsContainer oldVal = fChildrenMap.remove(name); if(fChildrenMap.size() == 0){ fChildrenMap = null; fPatternMap = null; @@ -263,7 +268,7 @@ public class PatternNameMap { fContainsDoubleStar = false; } - public Collection values(){ + public Collection values(){ if(fValues == null) fValues = new ValuesCollection(); return fValues; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/ThreadLocalMap.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/ThreadLocalMap.java index d72385d2b58..f5b07fafc37 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/ThreadLocalMap.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/ThreadLocalMap.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,10 +14,10 @@ import java.util.HashMap; import java.util.Map; public class ThreadLocalMap { - private ThreadLocal fLocal = new ThreadLocal(); + private ThreadLocal> fLocal = new ThreadLocal>(); public Object get(Object key){ - Map map = getMap(false); + Map map = getMap(false); return map != null ? map.get(key) : null; } @@ -25,24 +25,24 @@ public class ThreadLocalMap { if(value == null) clear(key); else { - Map map = getMap(true); + Map map = getMap(true); map.put(key, value); } } public void clear(Object key){ - Map map = getMap(false); + Map map = getMap(false); if(map != null){ map.remove(key); - if(map == null) - fLocal.set(null); } +// if(map == null) +// fLocal.set(null); } - private Map getMap(boolean create){ - Map map = (Map)fLocal.get(); + private Map getMap(boolean create){ + Map map = fLocal.get(); if(map == null && create){ - map = new HashMap(); + map = new HashMap(); fLocal.set(map); } return map;