| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CollectionFormatter |
|
| 3.0;3 |
| 1 | /* | |
| 2 | * Copyright 2007-2008 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.core.web.format; | |
| 17 | ||
| 18 | import java.util.Collection; | |
| 19 | import java.util.Iterator; | |
| 20 | ||
| 21 | /** | |
| 22 | * Formats a collection into a string that looks like an array. To print out each element, | |
| 23 | * the toString method of each element is called. | |
| 24 | * | |
| 25 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 26 | * | |
| 27 | */ | |
| 28 | 0 | public class CollectionFormatter extends Formatter { |
| 29 | ||
| 30 | /** | |
| 31 | * Formats a collection into a string that looks like an array. | |
| 32 | * | |
| 33 | * @see org.kuali.rice.core.web.format.Formatter#format(java.lang.Object) | |
| 34 | */ | |
| 35 | @Override | |
| 36 | public Object format(Object value) { | |
| 37 | 0 | StringBuilder buf = new StringBuilder(); |
| 38 | 0 | buf.append("["); |
| 39 | ||
| 40 | 0 | Collection collection = (Collection) value; |
| 41 | 0 | Iterator i = collection.iterator(); |
| 42 | 0 | boolean hasNext = i.hasNext(); |
| 43 | 0 | while (hasNext) { |
| 44 | 0 | Object elem = i.next(); |
| 45 | 0 | buf.append(elem); |
| 46 | ||
| 47 | 0 | hasNext = i.hasNext(); |
| 48 | 0 | if (hasNext) { |
| 49 | 0 | buf.append(", "); |
| 50 | } | |
| 51 | 0 | } |
| 52 | 0 | buf.append("]"); |
| 53 | 0 | return buf.toString(); |
| 54 | } | |
| 55 | ||
| 56 | } |