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.facets.collections.modify;
021
022import java.util.Collection;
023import java.util.Iterator;
024
025import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
026import org.apache.isis.core.metamodel.facetapi.Facet;
027import org.apache.isis.core.metamodel.facets.typeof.TypeOfFacet;
028import org.apache.isis.core.metamodel.spec.ObjectSpecification;
029
030/**
031 * Attached to {@link ObjectSpecification}s that represent a collection.
032 * 
033 * <p>
034 * Factories of (implementations of this) facet should ensure that a
035 * {@link TypeOfFacet} is also attached to the same facet holder. The
036 * {@link #getTypeOfFacet()} is a convenience for this.
037 */
038public interface CollectionFacet extends Facet {
039
040    int size(ObjectAdapter collection);
041
042    Iterable<ObjectAdapter> iterable(ObjectAdapter collectionAdapter);
043
044    Iterator<ObjectAdapter> iterator(ObjectAdapter collectionAdapter);
045
046    /**
047     * Returns an unmodifiable {@link Collection} of {@link ObjectAdapter}s.
048     */
049    Collection<ObjectAdapter> collection(ObjectAdapter collectionAdapter);
050
051    ObjectAdapter firstElement(ObjectAdapter collectionAdapter);
052
053    boolean contains(ObjectAdapter collectionAdapter, ObjectAdapter element);
054
055    /**
056     * Set the contents of this collection.
057     */
058    void init(ObjectAdapter collectionAdapter, ObjectAdapter[] elements);
059
060    /**
061     * Convenience method that returns the {@link TypeOfFacet} on this facet's
062     * {@link #getFacetHolder() holder}.
063     */
064    TypeOfFacet getTypeOfFacet();
065
066}