001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.commons.debug; 021 022import java.util.List; 023 024import com.google.common.collect.Lists; 025 026public class DebugList { 027 private final List<String[]> names = Lists.newArrayList(); 028 private final List<DebuggableWithTitle> debuggableList = Lists.newArrayList(); 029 030 public DebugList(final String name) { 031 debuggableList.add(new DebuggableWithTitle() { 032 @Override 033 public void debugData(final DebugBuilder debug) { 034 for (String[] name : names) { 035 debug.appendln(name[0], name[1]); 036 } 037 } 038 039 @Override 040 public String debugTitle() { 041 return name; 042 } 043 }); 044 } 045 046 public void add(final String name, final Object object) { 047 final boolean b = object instanceof DebuggableWithTitle; 048 if (b) { 049 debuggableList.add((DebuggableWithTitle) object); 050 } 051 if (object != null) { 052 String[] n = new String[2]; 053 n[0] = name + (b ? "*" : ""); 054 n[1] = object.toString(); 055 names.add(n); 056 } 057 } 058 059 public DebuggableWithTitle[] debug() { 060 return debuggableList.toArray(new DebuggableWithTitle[debuggableList.size()]); 061 } 062}