Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian de Alwis2016-04-07 16:19:31 +0000
committerBrian de Alwis2016-04-07 17:11:26 +0000
commit3690d52e9e3c1f9452c3061a4e3fe91f006395d6 (patch)
treeaf8511a7ae8836838f143ce0a539587330803d8b /org.eclipse.help
parent0e483fb65c311488286034313cc5bd3639504ccd (diff)
downloadeclipse.platform.ua-3690d52e9e3c1f9452c3061a4e3fe91f006395d6.tar.gz
eclipse.platform.ua-3690d52e9e3c1f9452c3061a4e3fe91f006395d6.tar.xz
eclipse.platform.ua-3690d52e9e3c1f9452c3061a4e3fe91f006395d6.zip
Bug 488210 - Generify org.eclipse.help plugin
Generify some of the remaining difficult pieces Change-Id: I69926e4dff5ee0ce33e81307535ada8c11a79b10
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java1
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocSorter.java32
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/util/ProductPreferences.java55
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/util/SequenceResolver.java77
4 files changed, 85 insertions, 80 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
index 9c7626ddd..bfcddd435 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
@@ -149,6 +149,7 @@ public class ContextFileProvider extends AbstractContextProvider {
* Returns the context definitions for the given plug-in and locale,
* as a mapping of short IDs to Context objects (shortContextId -> Context).
*/
+ @SuppressWarnings("unchecked")
public Map<String, Context>[] getPluginContexts(String pluginId, String locale) {
List<Map<String, Context>> maps = new ArrayList<>();
Map<String, ContextFile[]> associations = getPluginAssociations();
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocSorter.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocSorter.java
index 28277eea1..e8bd39e7f 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocSorter.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocSorter.java
@@ -28,7 +28,7 @@ public class TocSorter {
* A category of tocs. A category has an id and a list of contained
* tocs.
*/
- private static class TocCategory extends ArrayList {
+ private static class TocCategory extends ArrayList<ITocContribution> {
private static final long serialVersionUID = 1L;
@@ -52,14 +52,14 @@ public class TocSorter {
Map<String, String> nameIdMap = createNameIdMap(categorized);
// order them
- List<ITocContribution> orderedItems = ProductPreferences.getTocOrder(itemsToOrder, nameIdMap);
+ List<String> orderedItems = ProductPreferences.getTocOrder(itemsToOrder, nameIdMap);
// replace with actual TocContribution or category
- orderedItems = substituteValues(orderedItems, categorized);
+ List<Object> actualItems = substituteValues(orderedItems, categorized);
// expand the categories
- orderedItems = expandCategories(orderedItems);
- return orderedItems.toArray(new ITocContribution[orderedItems.size()]);
+ List<ITocContribution> expandedItems = expandCategories(actualItems);
+ return expandedItems.toArray(new ITocContribution[orderedItems.size()]);
}
// Create a mapping from an id to a label that can be sorted
@@ -71,7 +71,7 @@ public class TocSorter {
ITocContribution toc;
if (value instanceof TocCategory) {
TocCategory category = (TocCategory)value;
- toc = (ITocContribution) category.get(0);
+ toc = category.get(0);
} else {
toc = (ITocContribution)value;
}
@@ -115,7 +115,7 @@ public class TocSorter {
String tocLabel = toc.getToc().getLabel();
boolean done = false;
for (int next = 0; next < category.size() && !done; next++ ) {
- String nextName = ((ITocContribution)category.get(next)).getToc().getLabel();
+ String nextName = category.get(next).getToc().getLabel();
if (tocLabel.compareToIgnoreCase(nextName) < 0) {
done = true;
category.add(next, toc);
@@ -149,13 +149,11 @@ public class TocSorter {
* Expands all categories in the given list to actual toc contributions
* organized by category.
*/
- private List expandCategories(List entries) {
- List expanded = new ArrayList();
- Iterator iter = entries.iterator();
- while (iter.hasNext()) {
- Object entry = iter.next();
+ private List<ITocContribution> expandCategories(List<Object> entries) {
+ List<ITocContribution> expanded = new ArrayList<>();
+ for (Object entry : entries) {
if (entry instanceof ITocContribution) {
- expanded.add(entry);
+ expanded.add((ITocContribution) entry);
}
else if (entry instanceof TocCategory) {
expanded.addAll((TocCategory)entry);
@@ -168,12 +166,10 @@ public class TocSorter {
* Substitutes each item with it's corresponding mapping from the map.
* Original List is not modified.
*/
- private static List substituteValues(List items, Map map) {
+ private static List<Object> substituteValues(List<String> items, Map<String, Object> map) {
if (items != null && map != null) {
- List result = new ArrayList(items.size());
- Iterator iter = items.iterator();
- while (iter.hasNext()) {
- Object key = iter.next();
+ List<Object> result = new ArrayList<>(items.size());
+ for (String key : items) {
Object value = map.get(key);
if (value != null) {
result.add(value);
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/util/ProductPreferences.java b/org.eclipse.help/src/org/eclipse/help/internal/util/ProductPreferences.java
index 193ff22cb..ef91601a7 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/util/ProductPreferences.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/util/ProductPreferences.java
@@ -18,7 +18,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -47,11 +46,11 @@ import com.ibm.icu.text.Collator;
public class ProductPreferences {
private static Properties[] productPreferences;
- private static SequenceResolver orderResolver;
+ private static SequenceResolver<String> orderResolver;
private static Map<Properties, String> preferencesToPluginIdMap;
private static Map<Properties, String> preferencesToProductIdMap;
- private static List primaryTocOrdering;
- private static List[] secondaryTocOrderings;
+ private static List<String> primaryTocOrdering;
+ private static List<String>[] secondaryTocOrderings;
private static final String PLUGINS_ROOT_SLASH = "PLUGINS_ROOT/"; //$NON-NLS-1$
private static boolean rtl;
private static boolean directionInitialized = false;
@@ -61,9 +60,10 @@ public class ProductPreferences {
* toc entry is a String, either the id of the toc contribution or the
* id of the category of tocs.
*/
- public static List getTocOrder(List itemsToOrder, Map nameIdMap) {
- List primaryOrdering = getPrimaryTocOrdering();
- List[] secondaryOrdering = new List[0];
+ public static List<String> getTocOrder(List<String> itemsToOrder, Map<String, String> nameIdMap) {
+ List<String> primaryOrdering = getPrimaryTocOrdering();
+ @SuppressWarnings("unchecked")
+ List<String>[] secondaryOrdering = new List[0];
if (primaryOrdering == null || primaryOrdering.size() == 0) {
secondaryOrdering = getSecondaryTocOrderings();
}
@@ -75,7 +75,7 @@ public class ProductPreferences {
* product (either specified via help data xml file or deprecated comma-separated
* list in plugin_customization.ini). Help data takes precedence.
*/
- public static List getPrimaryTocOrdering() {
+ public static List<String> getPrimaryTocOrdering() {
if (primaryTocOrdering == null) {
IProduct product = Platform.getProduct();
String pluginId = null;
@@ -87,7 +87,7 @@ public class ProductPreferences {
primaryTocOrdering = getTocOrdering(pluginId, helpDataFile, baseTOCS);
// active product has no preference for toc order
if (primaryTocOrdering == null) {
- primaryTocOrdering = new ArrayList();
+ primaryTocOrdering = new ArrayList<>();
}
}
return primaryTocOrdering;
@@ -97,19 +97,21 @@ public class ProductPreferences {
* Returns all secondary toc ordering. These are the preferred toc orders of all
* defined products except the active product.
*/
- public static List[] getSecondaryTocOrderings() {
+ @SuppressWarnings("unchecked")
+ public static List<String>[] getSecondaryTocOrderings() {
if (secondaryTocOrderings == null) {
- List<List> list = new ArrayList<>();
+ List<List<String>> list = new ArrayList<>();
Properties[] productPreferences = getProductPreferences(false);
for (int i=0;i<productPreferences.length;++i) {
String pluginId = preferencesToPluginIdMap.get(productPreferences[i]);
String helpDataFile = (String)productPreferences[i].get(HelpPlugin.PLUGIN_ID + '/' + HelpPlugin.HELP_DATA_KEY);
String baseTOCS = (String)productPreferences[i].get(HelpPlugin.PLUGIN_ID + '/' + HelpPlugin.BASE_TOCS_KEY);
- List ordering = getTocOrdering(pluginId, helpDataFile, baseTOCS);
+ List<String> ordering = getTocOrdering(pluginId, helpDataFile, baseTOCS);
if (ordering != null) {
list.add(ordering);
}
}
+ // can't instantiate arrays of generic type
secondaryTocOrderings = list.toArray(new List[list.size()]);
}
return secondaryTocOrderings;
@@ -187,7 +189,7 @@ public class ProductPreferences {
* but not present are skipped, and items present but not ordered are added
* at the end.
*/
- public static List getOrderedList(List items, List order) {
+ public static List getOrderedList(List<String> items, List<String> order) {
return getOrderedList(items, order, null, null);
}
@@ -196,23 +198,22 @@ public class ProductPreferences {
* The primary ordering must be satisfied in all cases. As many secondary orderings
* as reasonably possible will be satisfied.
*/
- public static List getOrderedList(List items, List primary, List[] secondary, Map nameIdMap) {
- List result = new ArrayList();
- List set = new ArrayList(items);
+ public static List<String> getOrderedList(List<String> items, List<String> primary, List<String>[] secondary,
+ Map<String, String> nameIdMap) {
+ List<String> result = new ArrayList<>();
+ List<String> set = new ArrayList<>(items);
if (orderResolver == null) {
- orderResolver = new SequenceResolver();
+ orderResolver = new SequenceResolver<>();
}
- List order = orderResolver.getSequence(primary, secondary);
- Iterator iter = order.iterator();
- while (iter.hasNext()) {
- Object obj = iter.next();
+ List<String> order = orderResolver.getSequence(primary, secondary);
+ for (String obj : order) {
if (set.contains(obj)) {
result.add(obj);
set.remove(obj);
}
}
if (HelpData.getProductHelpData().isSortOthers() && nameIdMap != null) {
- List remaining = new ArrayList();
+ List<String> remaining = new ArrayList<>();
remaining.addAll(set);
sortByName(remaining, nameIdMap);
result.addAll(remaining);
@@ -222,16 +223,16 @@ public class ProductPreferences {
return result;
}
- private static class NameComparator implements Comparator {
+ private static class NameComparator implements Comparator<String> {
- private Map tocNames;
+ private Map<String, String> tocNames;
- public NameComparator(Map tocNames) {
+ public NameComparator(Map<String, String> tocNames) {
this.tocNames = tocNames;
}
@Override
- public int compare(Object o1, Object o2) {
+ public int compare(String o1, String o2) {
Object name1 = tocNames.get(o1);
Object name2 = tocNames.get(o2);
if (!(name1 instanceof String)) {
@@ -245,7 +246,7 @@ public class ProductPreferences {
}
- private static void sortByName(List remaining, Map categorized) {
+ private static void sortByName(List<String> remaining, Map<String, String> categorized) {
Collections.sort(remaining, new NameComparator(categorized));
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/util/SequenceResolver.java b/org.eclipse.help/src/org/eclipse/help/internal/util/SequenceResolver.java
index ab815f468..a2eadc339 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/util/SequenceResolver.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/util/SequenceResolver.java
@@ -26,13 +26,13 @@ import java.util.Set;
* based on the active product's preferred order as well as all other products'
* preferred orders.
*/
-public class SequenceResolver {
+public class SequenceResolver<T> {
- private List primaryList;
- private List[] secondaryLists;
- private ListIterator primaryIter;
- private ListIterator[] secondaryIters;
- private Set<Object> processedItems;
+ private List<T> primaryList;
+ private List<T>[] secondaryLists;
+ private ListIterator<T> primaryIter;
+ private ListIterator<T>[] secondaryIters;
+ private Set<T> processedItems;
/*
* Merges the given primary and secondary orderings such that all ordering
@@ -71,12 +71,12 @@ public class SequenceResolver {
* as many orderings as possible are satisfied. For example, if most orderings
* want x before y, but a few want the opposite, x will be placed before y.
*/
- public List getSequence(List primary, List[] secondary) {
+ public List<T> getSequence(List<T> primary, List<T>[] secondary) {
primaryList = primary;
secondaryLists = secondary;
prepareDataStructures();
- List<Object> order = new ArrayList<>();
- Object item;
+ List<T> order = new ArrayList<>();
+ T item;
while ((item = getNextItem()) != null) {
processedItems.add(item);
advanceIterator(primaryIter);
@@ -91,6 +91,7 @@ public class SequenceResolver {
/*
* Create the data structures necessary for later operations.
*/
+ @SuppressWarnings("unchecked")
private void prepareDataStructures() {
primaryIter = primaryList.listIterator();
secondaryIters = new ListIterator[secondaryLists.length];
@@ -104,8 +105,8 @@ public class SequenceResolver {
* Determine the next item in the sequence based on the top
* candidate items.
*/
- private Object getNextItem() {
- Candidate[] candidates = getTopCandidates();
+ private T getNextItem() {
+ Candidate<T>[] candidates = getTopCandidates();
switch(candidates.length) {
case 0:
return null;
@@ -125,8 +126,8 @@ public class SequenceResolver {
* Retrieves the top candidates from all the available next item candidates.
* These are the candidates that have the lowest rank
*/
- private Candidate[] getTopCandidates() {
- Candidate[] candidates = getEligibleCandidates();
+ private Candidate<T>[] getTopCandidates() {
+ Candidate<T>[] candidates = getEligibleCandidates();
rankCandidates(candidates);
if (candidates.length > 0) {
int topRank = candidates[0].rank;
@@ -135,13 +136,13 @@ public class SequenceResolver {
topRank = candidates[i].rank;
}
}
- List<Candidate> topCandidates = new ArrayList<>();
+ List<Candidate<T>> topCandidates = new ArrayList<>();
for (int i=0;i<candidates.length;++i) {
if (candidates[i].rank == topRank) {
topCandidates.add(candidates[i]);
}
}
- return topCandidates.toArray(new Candidate[topCandidates.size()]);
+ return toCandidatesArray(topCandidates);
}
return candidates;
}
@@ -152,9 +153,9 @@ public class SequenceResolver {
* has that candidate after the primary candidate, it is contradicting the primary
* sequence and is not eligible.
*/
- private Candidate[] getEligibleCandidates() {
- Candidate[] allCandidates = getAllCandidates();
- Candidate primary = null;
+ private Candidate<T>[] getEligibleCandidates() {
+ Candidate<T>[] allCandidates = getAllCandidates();
+ Candidate<T> primary = null;
for (int i=0;i<allCandidates.length;++i) {
if (allCandidates[i].isPrimary) {
primary = allCandidates[i];
@@ -163,12 +164,12 @@ public class SequenceResolver {
}
// if we have no primary candidate then they're all eligible
if (primary != null) {
- List<Candidate> eligibleCandidates = new ArrayList<>(allCandidates.length);
+ List<Candidate<T>> eligibleCandidates = new ArrayList<>(allCandidates.length);
// primary candidate is always eligible
eligibleCandidates.add(primary);
- Set primarySet = Collections.singleton(primary.item);
+ Set<T> primarySet = Collections.singleton(primary.item);
for (int i=0;i<allCandidates.length;++i) {
- Candidate c = allCandidates[i];
+ Candidate<T> c = allCandidates[i];
if (c != primary) {
// does it contradict the primary sequence? if not, it is eligible
if (countPrecedingItems(c.item, primary.src, primarySet) == 0) {
@@ -176,7 +177,7 @@ public class SequenceResolver {
}
}
}
- return eligibleCandidates.toArray(new Candidate[eligibleCandidates.size()]);
+ return toCandidatesArray(eligibleCandidates);
}
return allCandidates;
}
@@ -185,11 +186,11 @@ public class SequenceResolver {
* Retrieve all the candidates for the next item in sequence, with
* no duplicates.
*/
- private Candidate[] getAllCandidates() {
- List<Candidate> candidates = new ArrayList<>();
- Object item = getNextItem(primaryIter);
+ private Candidate<T>[] getAllCandidates() {
+ List<Candidate<T>> candidates = new ArrayList<>();
+ T item = getNextItem(primaryIter);
if (item != null) {
- Candidate c = new Candidate();
+ Candidate<T> c = new Candidate<>();
c.item = item;
c.isPrimary = true;
c.src = primaryList;
@@ -198,7 +199,7 @@ public class SequenceResolver {
for (int i=0;i<secondaryIters.length;++i) {
item = getNextItem(secondaryIters[i]);
if (item != null) {
- Candidate c = new Candidate();
+ Candidate<T> c = new Candidate<>();
c.item = item;
c.isPrimary = false;
c.src = secondaryLists[i];
@@ -207,6 +208,12 @@ public class SequenceResolver {
}
}
}
+ return toCandidatesArray(candidates);
+ }
+
+ /** Helper function as we cannot create arrays of parameterized types */
+ @SuppressWarnings("unchecked")
+ private Candidate<T>[] toCandidatesArray(List<Candidate<T>> candidates) {
return candidates.toArray(new Candidate[candidates.size()]);
}
@@ -216,9 +223,9 @@ public class SequenceResolver {
* This essentially means how far back this item should be in the final
* sequence.
*/
- private void rankCandidates(Candidate[] candidates) {
+ private void rankCandidates(Candidate<T>[] candidates) {
// for quick lookup
- Set candidateItems = new HashSet();
+ Set<T> candidateItems = new HashSet<>();
for (int i=0;i<candidates.length;++i) {
candidateItems.add(candidates[i].item);
}
@@ -253,9 +260,9 @@ public class SequenceResolver {
* Returns the next item available to this iterator, without moving it
* forward.
*/
- private Object getNextItem(ListIterator iter) {
+ private T getNextItem(ListIterator<T> iter) {
if (iter.hasNext()) {
- Object next = iter.next();
+ T next = iter.next();
iter.previous();
return next;
}
@@ -266,9 +273,9 @@ public class SequenceResolver {
* Advances the given iterator to the next item in its
* sequence that we haven't yet processed.
*/
- private void advanceIterator(ListIterator iter) {
+ private void advanceIterator(ListIterator<T> iter) {
while (iter.hasNext()) {
- Object item = iter.next();
+ T item = iter.next();
if (!processedItems.contains(item)) {
iter.previous();
break;
@@ -280,8 +287,8 @@ public class SequenceResolver {
* A candidate item; one that could potentially be the next one in the final
* sequence.
*/
- private static class Candidate {
- public Object item;
+ private static class Candidate<T> {
+ public T item;
public boolean isPrimary;
public int rank;
public List src;

Back to the top