mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
cosmetics: generics/enhanced loops
This commit is contained in:
parent
4d00b08201
commit
6945d7ce32
1 changed files with 81 additions and 83 deletions
|
@ -13,84 +13,86 @@ package org.eclipse.cdt.internal.core.settings.model;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
import org.eclipse.cdt.core.settings.model.CExternalSetting;
|
||||||
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
|
||||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||||
|
import org.eclipse.cdt.core.settings.model.util.EntryContentsKey;
|
||||||
|
import org.eclipse.cdt.core.settings.model.util.EntryNameKey;
|
||||||
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
||||||
|
|
||||||
class CExternalSettinsDeltaCalculator {
|
class CExternalSettinsDeltaCalculator {
|
||||||
static private CExternalSettinsDeltaCalculator fInstance;
|
static private CExternalSettinsDeltaCalculator fInstance;
|
||||||
|
|
||||||
private CExternalSettinsDeltaCalculator(){
|
private CExternalSettinsDeltaCalculator(){
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CExternalSettinsDeltaCalculator getInstance(){
|
public static CExternalSettinsDeltaCalculator getInstance(){
|
||||||
if(fInstance == null)
|
if(fInstance == null)
|
||||||
fInstance = new CExternalSettinsDeltaCalculator();
|
fInstance = new CExternalSettinsDeltaCalculator();
|
||||||
return fInstance;
|
return fInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class ExtSettingsDelta {
|
static class ExtSettingsDelta {
|
||||||
CExternalSetting fSetting;
|
CExternalSetting fSetting;
|
||||||
boolean fAdded;
|
boolean fAdded;
|
||||||
KindBasedStore fEntryChangeStore;
|
KindBasedStore<ICSettingEntry[][]> fEntryChangeStore;
|
||||||
|
|
||||||
ExtSettingsDelta(CExternalSetting setting){
|
ExtSettingsDelta(CExternalSetting setting){
|
||||||
fSetting = setting;
|
fSetting = setting;
|
||||||
fEntryChangeStore = new KindBasedStore(false);
|
fEntryChangeStore = new KindBasedStore<ICSettingEntry[][]>(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtSettingsDelta(CExternalSetting setting, boolean added){
|
ExtSettingsDelta(CExternalSetting setting, boolean added){
|
||||||
fSetting = setting;
|
fSetting = setting;
|
||||||
fAdded = added;
|
fAdded = added;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isChange(){
|
boolean isChange(){
|
||||||
return fEntryChangeStore != null;
|
return fEntryChangeStore != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAdded(){
|
boolean isAdded(){
|
||||||
return fAdded;
|
return fAdded;
|
||||||
}
|
}
|
||||||
|
|
||||||
CExternalSetting getSetting(){
|
CExternalSetting getSetting(){
|
||||||
return fSetting;
|
return fSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
ICSettingEntry[][] getEntriesDelta(int kind){
|
ICSettingEntry[][] getEntriesDelta(int kind){
|
||||||
if(fEntryChangeStore != null)
|
if(fEntryChangeStore != null)
|
||||||
return (ICSettingEntry[][])fEntryChangeStore.get(kind);
|
return fEntryChangeStore.get(kind);
|
||||||
ICSettingEntry [] entries = fSetting.getEntries(kind);
|
ICSettingEntry [] entries = fSetting.getEntries(kind);
|
||||||
if(entries == null || entries.length == 0)
|
if(entries == null || entries.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
ICSettingEntry[][] delta = new ICSettingEntry[2][];
|
ICSettingEntry[][] delta = new ICSettingEntry[2][];
|
||||||
if(fAdded)
|
if(fAdded)
|
||||||
delta[0] = entries;
|
delta[0] = entries;
|
||||||
else
|
else
|
||||||
delta[1] = entries;
|
delta[1] = entries;
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
ICSettingEntry[][] getEntriesDelta(){
|
ICSettingEntry[][] getEntriesDelta(){
|
||||||
int kinds[] = KindBasedStore.getLanguageEntryKinds();
|
int kinds[] = KindBasedStore.getLanguageEntryKinds();
|
||||||
List added = new ArrayList();
|
List<ICSettingEntry> added = new ArrayList<ICSettingEntry>();
|
||||||
List removed = new ArrayList();
|
List<ICSettingEntry> removed = new ArrayList<ICSettingEntry>();
|
||||||
for(int i = 0; i < kinds.length; i++){
|
for (int kind : kinds) {
|
||||||
ICSettingEntry[][] d = getEntriesDelta(kinds[i]);
|
ICSettingEntry[][] d = getEntriesDelta(kind);
|
||||||
if(d == null)
|
if(d == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(d[0] != null){
|
if(d[0] != null){
|
||||||
added.addAll(Arrays.asList(d[0]));
|
added.addAll(Arrays.asList(d[0]));
|
||||||
}
|
}
|
||||||
|
@ -100,24 +102,24 @@ class CExternalSettinsDeltaCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
ICSettingEntry[][] delta = new ICSettingEntry[2][];
|
ICSettingEntry[][] delta = new ICSettingEntry[2][];
|
||||||
|
|
||||||
if(added.size() != 0){
|
if(added.size() != 0){
|
||||||
delta[0] = (ICSettingEntry[])added.toArray(new ICSettingEntry[added.size()]);
|
delta[0] = added.toArray(new ICSettingEntry[added.size()]);
|
||||||
}
|
}
|
||||||
if(removed.size() != 0){
|
if(removed.size() != 0){
|
||||||
delta[1] = (ICSettingEntry[])removed.toArray(new ICSettingEntry[removed.size()]);
|
delta[1] = removed.toArray(new ICSettingEntry[removed.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ExtSettingMapKey {
|
static class ExtSettingMapKey {
|
||||||
private ICExternalSetting fSetting;
|
private ICExternalSetting fSetting;
|
||||||
public ExtSettingMapKey(ICExternalSetting setting){
|
public ExtSettingMapKey(ICExternalSetting setting){
|
||||||
fSetting = setting;
|
fSetting = setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(obj == this)
|
if(obj == this)
|
||||||
|
@ -125,7 +127,7 @@ class CExternalSettinsDeltaCalculator {
|
||||||
|
|
||||||
if(!(obj instanceof ExtSettingMapKey))
|
if(!(obj instanceof ExtSettingMapKey))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ExtSettingMapKey other = (ExtSettingMapKey)obj;
|
ExtSettingMapKey other = (ExtSettingMapKey)obj;
|
||||||
return settingsMatch(fSetting, other.fSetting);
|
return settingsMatch(fSetting, other.fSetting);
|
||||||
}
|
}
|
||||||
|
@ -135,37 +137,35 @@ class CExternalSettinsDeltaCalculator {
|
||||||
+ code(fSetting.getCompatibleContentTypeIds())
|
+ code(fSetting.getCompatibleContentTypeIds())
|
||||||
+ code(fSetting.getCompatibleExtensions());
|
+ code(fSetting.getCompatibleExtensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int code(String[] arr){
|
private int code(String[] arr){
|
||||||
if(arr == null || arr.length == 0)
|
if(arr == null || arr.length == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
|
||||||
for(int i = 0; i < arr.length; i++){
|
for (String str : arr) {
|
||||||
code += arr[i].hashCode();
|
code += str.hashCode();
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICExternalSetting getSetting(){
|
public ICExternalSetting getSetting(){
|
||||||
return fSetting;
|
return fSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExtSettingsDelta createDelta(CExternalSetting setting1, CExternalSetting setting2){
|
private static ExtSettingsDelta createDelta(CExternalSetting setting1, CExternalSetting setting2){
|
||||||
|
|
||||||
int kind;
|
|
||||||
int kinds[] = KindBasedStore.getAllEntryKinds();
|
int kinds[] = KindBasedStore.getAllEntryKinds();
|
||||||
ExtSettingsDelta extDelta = null;
|
ExtSettingsDelta extDelta = null;
|
||||||
for(int i = 0; i < kinds.length; i++){
|
for (int kind : kinds) {
|
||||||
kind = kinds[i];
|
|
||||||
ICSettingEntry entries1[] = setting1.getEntries(kind);
|
ICSettingEntry entries1[] = setting1.getEntries(kind);
|
||||||
ICSettingEntry entries2[] = setting2.getEntries(kind);
|
ICSettingEntry entries2[] = setting2.getEntries(kind);
|
||||||
Map map1 = CDataUtil.fillEntriesMapByContentsKey(new LinkedHashMap(), entries1);
|
Map<EntryContentsKey, ICSettingEntry> map1 = CDataUtil.fillEntriesMapByContentsKey(new LinkedHashMap<EntryContentsKey, ICSettingEntry>(), entries1);
|
||||||
Map map2 = CDataUtil.fillEntriesMapByContentsKey(new LinkedHashMap(), entries2);
|
Map<EntryContentsKey, ICSettingEntry> map2 = CDataUtil.fillEntriesMapByContentsKey(new LinkedHashMap<EntryContentsKey, ICSettingEntry>(), entries2);
|
||||||
Map map1Copy = new LinkedHashMap(map1);
|
Map<EntryContentsKey, ICSettingEntry> map1Copy = new LinkedHashMap<EntryContentsKey, ICSettingEntry>(map1);
|
||||||
// Set set1 = new HashSet(Arrays.asList(entries1));
|
// Set set1 = new HashSet(Arrays.asList(entries1));
|
||||||
// Set set2 = new HashSet(Arrays.asList(entries2));
|
// Set set2 = new HashSet(Arrays.asList(entries2));
|
||||||
// Set set1Copy = new HashSet(set1);
|
// Set set1Copy = new HashSet(set1);
|
||||||
|
@ -175,34 +175,34 @@ class CExternalSettinsDeltaCalculator {
|
||||||
ICSettingEntry entriesAdded[] = null, entriesRemoved[] = null;
|
ICSettingEntry entriesAdded[] = null, entriesRemoved[] = null;
|
||||||
|
|
||||||
if(map1.size() != 0)
|
if(map1.size() != 0)
|
||||||
entriesAdded = (ICSettingEntry[])map1.values().toArray(new ICSettingEntry[map1.size()]);
|
entriesAdded = map1.values().toArray(new ICSettingEntry[map1.size()]);
|
||||||
|
|
||||||
if(map2.size() != 0)
|
if(map2.size() != 0)
|
||||||
entriesRemoved = (ICSettingEntry[])map2.values().toArray(new ICSettingEntry[map2.size()]);
|
entriesRemoved = map2.values().toArray(new ICSettingEntry[map2.size()]);
|
||||||
|
|
||||||
if(entriesAdded == null && entriesRemoved == null)
|
if(entriesAdded == null && entriesRemoved == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(extDelta == null){
|
if(extDelta == null){
|
||||||
extDelta = new ExtSettingsDelta(setting1);
|
extDelta = new ExtSettingsDelta(setting1);
|
||||||
}
|
}
|
||||||
extDelta.fEntryChangeStore.put(kind, new ICSettingEntry[][]{entriesAdded, entriesRemoved});
|
extDelta.fEntryChangeStore.put(kind, new ICSettingEntry[][]{entriesAdded, entriesRemoved});
|
||||||
}
|
}
|
||||||
|
|
||||||
return extDelta;
|
return extDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean settingsMatch(ICExternalSetting setting1, ICExternalSetting setting2) {
|
static boolean settingsMatch(ICExternalSetting setting1, ICExternalSetting setting2) {
|
||||||
if(setting1.equals(setting2))
|
if(setting1.equals(setting2))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return settingsMatch(setting1,
|
return settingsMatch(setting1,
|
||||||
setting2.getCompatibleLanguageIds(),
|
setting2.getCompatibleLanguageIds(),
|
||||||
setting2.getCompatibleContentTypeIds(),
|
setting2.getCompatibleContentTypeIds(),
|
||||||
setting2.getCompatibleExtensions());
|
setting2.getCompatibleExtensions());
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean settingsMatch(ICExternalSetting setting,
|
static boolean settingsMatch(ICExternalSetting setting,
|
||||||
String languageIDs[], String contentTypeIDs[], String extensions[]){
|
String languageIDs[], String contentTypeIDs[], String extensions[]){
|
||||||
if(!Arrays.equals(setting.getCompatibleLanguageIds(), languageIDs))
|
if(!Arrays.equals(setting.getCompatibleLanguageIds(), languageIDs))
|
||||||
return false;
|
return false;
|
||||||
|
@ -213,11 +213,11 @@ class CExternalSettinsDeltaCalculator {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map toSettingsKeyMap(ICExternalSetting[] settings){
|
private static Map<ExtSettingMapKey, ICExternalSetting> toSettingsKeyMap(ICExternalSetting[] settings){
|
||||||
Map map = new HashMap();
|
Map<ExtSettingMapKey, ICExternalSetting> map = new HashMap<ExtSettingMapKey, ICExternalSetting>();
|
||||||
for(int i = 0; i < settings.length; i++){
|
for (ICExternalSetting setting : settings) {
|
||||||
if(map.put(new ExtSettingMapKey(settings[i]), settings[i]) != null)
|
if(map.put(new ExtSettingMapKey(setting), setting) != null)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
@ -232,12 +232,11 @@ class CExternalSettinsDeltaCalculator {
|
||||||
if(oldSettings == null || oldSettings.length == 0)
|
if(oldSettings == null || oldSettings.length == 0)
|
||||||
return createDeltas(newSettings, true);
|
return createDeltas(newSettings, true);
|
||||||
|
|
||||||
List deltaList = new ArrayList();
|
List<ExtSettingsDelta> deltaList = new ArrayList<ExtSettingsDelta>();
|
||||||
|
|
||||||
Map newMap= toSettingsKeyMap(newSettings);
|
Map<ExtSettingMapKey, ICExternalSetting> newMap= toSettingsKeyMap(newSettings);
|
||||||
Map oldMap = toSettingsKeyMap(oldSettings);
|
Map<ExtSettingMapKey, ICExternalSetting> oldMap = toSettingsKeyMap(oldSettings);
|
||||||
for(Iterator iter = newMap.entrySet().iterator(); iter.hasNext();){
|
for (Entry<ExtSettingMapKey, ICExternalSetting> entry : newMap.entrySet()) {
|
||||||
Map.Entry entry = (Map.Entry)iter.next();
|
|
||||||
CExternalSetting newSetting = (CExternalSetting)entry.getValue();
|
CExternalSetting newSetting = (CExternalSetting)entry.getValue();
|
||||||
CExternalSetting oldSetting = (CExternalSetting)oldMap.remove(entry.getKey());
|
CExternalSetting oldSetting = (CExternalSetting)oldMap.remove(entry.getKey());
|
||||||
if(oldSetting == null){
|
if(oldSetting == null){
|
||||||
|
@ -248,50 +247,49 @@ class CExternalSettinsDeltaCalculator {
|
||||||
deltaList.add(delta);
|
deltaList.add(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(Iterator iter = oldMap.values().iterator(); iter.hasNext();){
|
for (ICExternalSetting oldSettng : oldMap.values()) {
|
||||||
CExternalSetting oldSettng = (CExternalSetting)iter.next();
|
deltaList.add(new ExtSettingsDelta((CExternalSetting)oldSettng, false));
|
||||||
deltaList.add(new ExtSettingsDelta(oldSettng, false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(deltaList.size() == 0)
|
if(deltaList.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
return (ExtSettingsDelta[])deltaList.toArray(new ExtSettingsDelta[deltaList.size()]);
|
return deltaList.toArray(new ExtSettingsDelta[deltaList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ExtSettingsDelta[] createDeltas(CExternalSetting settings[], boolean added){
|
private static ExtSettingsDelta[] createDeltas(CExternalSetting settings[], boolean added){
|
||||||
if(settings == null || settings.length == 0)
|
if(settings == null || settings.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
ExtSettingsDelta deltas[] = new ExtSettingsDelta[settings.length];
|
ExtSettingsDelta deltas[] = new ExtSettingsDelta[settings.length];
|
||||||
for(int i = 0; i < settings.length; i++){
|
for(int i = 0; i < settings.length; i++){
|
||||||
deltas[i] = new ExtSettingsDelta(settings[i], added);
|
deltas[i] = new ExtSettingsDelta(settings[i], added);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deltas;
|
return deltas;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set calculateUpdatedEntries(ICSettingEntry current[], ICSettingEntry added[], ICSettingEntry removed[]){
|
Set<ICSettingEntry> calculateUpdatedEntries(ICSettingEntry current[], ICSettingEntry added[], ICSettingEntry removed[]){
|
||||||
// EntryComparator comparator = new EntryComparator();
|
// EntryComparator comparator = new EntryComparator();
|
||||||
LinkedHashSet set = new LinkedHashSet();
|
LinkedHashSet<ICSettingEntry> set = new LinkedHashSet<ICSettingEntry>();
|
||||||
set.addAll(Arrays.asList(current));
|
set.addAll(Arrays.asList(current));
|
||||||
set.addAll(Arrays.asList(added));
|
set.addAll(Arrays.asList(added));
|
||||||
set.removeAll(Arrays.asList(removed));
|
set.removeAll(Arrays.asList(removed));
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ICSettingEntry[][] getAllEntries(ExtSettingsDelta[] deltas, int kind){
|
static ICSettingEntry[][] getAllEntries(ExtSettingsDelta[] deltas, int kind){
|
||||||
if(deltas == null || deltas.length == 0)
|
if(deltas == null || deltas.length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Map addedMap = new LinkedHashMap();
|
Map<EntryNameKey, ICSettingEntry> addedMap = new LinkedHashMap<EntryNameKey, ICSettingEntry>();
|
||||||
Map removedMap = new LinkedHashMap();
|
Map<EntryNameKey, ICSettingEntry> removedMap = new LinkedHashMap<EntryNameKey, ICSettingEntry>();
|
||||||
for(int i = 0; i < deltas.length; i++){
|
for (ExtSettingsDelta delta : deltas) {
|
||||||
ICSettingEntry[][] change = deltas[i].getEntriesDelta(kind);
|
ICSettingEntry[][] change = delta.getEntriesDelta(kind);
|
||||||
if(change == null)
|
if(change == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(change[0] != null){
|
if(change[0] != null){
|
||||||
CDataUtil.fillEntriesMapByNameKey(addedMap, change[0]);
|
CDataUtil.fillEntriesMapByNameKey(addedMap, change[0]);
|
||||||
}
|
}
|
||||||
|
@ -300,16 +298,16 @@ class CExternalSettinsDeltaCalculator {
|
||||||
}
|
}
|
||||||
removedMap.keySet().removeAll(addedMap.keySet());
|
removedMap.keySet().removeAll(addedMap.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(addedMap.size() == 0 && removedMap.size() == 0)
|
if(addedMap.size() == 0 && removedMap.size() == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
ICSettingEntry[][] result = new ICSettingEntry[2][];
|
ICSettingEntry[][] result = new ICSettingEntry[2][];
|
||||||
if(addedMap.size() != 0){
|
if(addedMap.size() != 0){
|
||||||
result[0] = (ICSettingEntry[])addedMap.values().toArray(new ICSettingEntry[addedMap.size()]);
|
result[0] = addedMap.values().toArray(new ICSettingEntry[addedMap.size()]);
|
||||||
}
|
}
|
||||||
if(removedMap.size() != 0){
|
if(removedMap.size() != 0){
|
||||||
result[1] = (ICSettingEntry[])removedMap.values().toArray(new ICSettingEntry[removedMap.size()]);
|
result[1] = removedMap.values().toArray(new ICSettingEntry[removedMap.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue