Skip to content

Instantly share code, notes, and snippets.

@vstorm83
Created August 1, 2014 09:51
Show Gist options
  • Save vstorm83/eb4c322ec1bc6b33bdd5 to your computer and use it in GitHub Desktop.
Save vstorm83/eb4c322ec1bc6b33bdd5 to your computer and use it in GitHub Desktop.
app comparation
@@ -25,21 +25,23 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import org.exoplatform.portal.config.model.Application;
+import org.exoplatform.portal.config.model.TransientApplicationState;
public class AddOnServiceImpl implements AddOnService {
- private Map<String, List<AddOnPlugin>> plugins = new HashMap<String, List<AddOnPlugin>>();
+ private Map<String, Map<Integer, List<Application<?>>>> plugins = new HashMap<String, Map<Integer, List<Application<?>>>>();
@Override
public List<Application<?>> getApplications(String containerName) {
List<Application<?>> apps = new LinkedList<Application<?>>();
- List<AddOnPlugin> ls = plugins.get(containerName);
+ Map<Integer, List<Application<?>>> ls = plugins.get(containerName);
if (ls != null) {
- for (AddOnPlugin p : ls) {
- apps.addAll(p.getApplications());
+ for (List<Application<?>> p : ls.values()) {
+ apps.addAll(p);
}
}
return apps;
@@ -47,16 +49,30 @@ public class AddOnServiceImpl implements AddOnService {
@Override
public void addPlugin(AddOnPlugin plugin) {
- List<AddOnPlugin> ls = plugins.get(plugin.getContainerName());
+ Map<Integer, List<Application<?>>> ls = plugins.get(plugin.getContainerName());
if (ls == null) {
- ls = new LinkedList<AddOnPlugin>();
+ ls = new TreeMap<Integer, List<Application<?>>>(new Comparator<Integer>() {
+ @Override
+ public int compare(Integer o1, Integer o2) {
+ return o1.compareTo(o2);
+ }
+ });
plugins.put(plugin.getContainerName(), ls);
}
- ls.add(plugin);
- Collections.sort(ls, new Comparator<AddOnPlugin>() {
+
+ List<Application<?>> tmp = ls.get(plugin.getPriority());
+ if (tmp == null) {
+ tmp = new LinkedList<Application<?>>();
+ ls.put(plugin.getPriority(), tmp);
+ }
+ tmp.addAll(plugin.getApplications());
+
+ Collections.sort(tmp, new Comparator<Application<?>>() {
@Override
- public int compare(AddOnPlugin o1, AddOnPlugin o2) {
- return o1.getPriority() - o2.getPriority();
+ public int compare(Application<?> o1, Application<?> o2) {
+ TransientApplicationState<?> s1 = (TransientApplicationState<?>)o1.getState();
+ TransientApplicationState<?> s2 = (TransientApplicationState<?>)o2.getState();
+ return s1.getContentId().compareTo(s2.getContentId());
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment