Here you can find the source of augmentList(Action[] list1, Action[] list2)
Parameter | Description |
---|---|
list1 | the first list, may be empty but not <code>null</code> |
list2 | the second list, may be empty but not <code>null</code> |
public static final Action[] augmentList(Action[] list1, Action[] list2)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.util.*; public class Main { /**/*from w w w . jav a2s.com*/ * Takes one list of * commands and augments it with another list * of commands. The second list takes precedence * over the first list; that is, when both lists * contain a command with the same name, the command * from the second list is used. * * @param list1 the first list, may be empty but not * <code>null</code> * @param list2 the second list, may be empty but not * <code>null</code> * @return the augmented list */ public static final Action[] augmentList(Action[] list1, Action[] list2) { Map<String, Action> h = new HashMap<String, Action>(); addActionsToMap(list1, h); addActionsToMap(list2, h); Action[] actions = mapToActionList(h); return actions; } /** * add a col;lections of actions to a Map where the key is the action name * * @param list1 non-noll list of actions * @param h non-null map as above */ public static void addActionsToMap(Action[] list1, Map<String, Action> h) { for (int i = 0; i < list1.length; i++) { Action a = list1[i]; String value = (String) a.getValue(Action.NAME); h.put((value != null ? value : ""), a); } } public static Action[] mapToActionList(Map<String, Action> h) { Action[] actions = new Action[h.size()]; h.values().toArray(actions); return actions; } }