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.metamodel.spec; 021 022import java.util.AbstractList; 023import java.util.Collections; 024import java.util.List; 025 026import org.apache.isis.core.commons.util.ToString; 027import org.apache.isis.core.metamodel.adapter.ObjectAdapter; 028 029/** 030 * A list returned from an action, ie not associated or owned by any entity. 031 */ 032public class FreeStandingList extends AbstractList<ObjectAdapter> { 033 034 private final List<ObjectAdapter> instances; 035 private final ObjectSpecification instanceSpecification; 036 037 public FreeStandingList(final ObjectSpecification instanceSpecification, final List<ObjectAdapter> instances) { 038 this.instanceSpecification = instanceSpecification; 039 this.instances = Collections.unmodifiableList(instances); 040 } 041 042 /** 043 * Required implementation of {@link AbstractList}. 044 */ 045 @Override 046 public ObjectAdapter get(final int index) { 047 return instances.get(index); 048 } 049 050 /** 051 * Required implementation of {@link AbstractList}. 052 */ 053 @Override 054 public int size() { 055 return instances.size(); 056 } 057 058 public ObjectSpecification getElementSpecification() { 059 return instanceSpecification; 060 } 061 062 public String titleString() { 063 return instanceSpecification.getPluralName() + ", " + size(); 064 } 065 066 @Override 067 public String toString() { 068 final ToString s = new ToString(this); 069 s.append("elements", instanceSpecification.getFullIdentifier()); 070 071 // title 072 String title; 073 try { 074 title = "'" + this.titleString() + "'"; 075 } catch (final NullPointerException e) { 076 title = "none"; 077 } 078 s.append("title", title); 079 080 s.append("vector", instances); 081 082 return s.toString(); 083 } 084 085}