View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.actionlist.web;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Collections;
21  import java.util.Comparator;
22  import java.util.List;
23  
24  import org.apache.commons.collections.comparators.ComparableComparator;
25  import org.kuali.rice.kew.actionrequest.Recipient;
26  import org.kuali.rice.kew.util.WebFriendlyRecipient;
27  
28  /**
29   * Internal Utility class for Action Lists.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public final class ActionListUtil {
35  	
36  	private ActionListUtil() {
37  		throw new UnsupportedOperationException("do not call");
38  	}
39  
40      /**
41       * Converts a collection of Recipients into a collection of WebFriendlyRecipients which can be displayed in the UI
42       * @param recipients recipients to convert
43       * @return a collection of WebFriendlyRecipients which can be displayed in the UI
44       */
45      public static List<WebFriendlyRecipient> getWebFriendlyRecipients(Collection<Recipient> recipients) {
46          Collection<WebFriendlyRecipient> newRecipients = new ArrayList<WebFriendlyRecipient>(recipients.size());
47          for (Recipient recipient : recipients) {
48              newRecipients.add(new WebFriendlyRecipient(recipient));
49          }
50          List<WebFriendlyRecipient> recipientList = new ArrayList<WebFriendlyRecipient>(newRecipients);
51          Collections.sort(recipientList, new Comparator<WebFriendlyRecipient>() {
52              Comparator<String> comp = new ComparableComparator();
53  
54              @Override
55  			public int compare(WebFriendlyRecipient o1, WebFriendlyRecipient o2) {
56                  return comp.compare(o1.getDisplayName().trim().toLowerCase(), o2.getDisplayName().trim().toLowerCase());
57              }
58          });
59          return recipientList;
60      }
61  }