Here you can find the source of toCollectionString(Collection> collection_p)
Parameter | Description |
---|---|
collection_p | a potentially null collection |
public static String toCollectionString(Collection<?> collection_p)
//package com.java2s; /**/* w ww . j a v a 2s. c om*/ * <copyright> * * Copyright (c) 2010-2012 Thales Global Services S.A.S. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Thales Global Services S.A.S. - initial API and implementation * * </copyright> */ import java.util.Collection; import java.util.Iterator; public class Main { /** A representation of the null value */ public static final String NULL = "null"; /** * Return a string representation of the given collection which is typically suitable * as a match ID representation * @param collection_p a potentially null collection * @return a non-null string */ public static String toCollectionString(Collection<?> collection_p) { if (collection_p == null) return NULL; StringBuilder builder = new StringBuilder(); builder.append('['); Iterator<?> it = collection_p.iterator(); while (it.hasNext()) { Object element = it.next(); String segment; if (element == collection_p) segment = "(this collection)"; //$NON-NLS-1$ else if (element == null) segment = NULL; else segment = element.toString(); builder.append(segment); if (it.hasNext()) builder.append('.'); } builder.append(']'); return builder.toString(); } }