001/* 002 * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025package Torello.Java.ReadOnly; 026 027import Torello.Java.Additional.RemoveUnsupportedIterator; 028import java.util.Collection; 029 030/** 031 * Immutable variant of Java Collections Framework interface 032 * <CODE>java.util.SequencedCollection<E></CODE>. 033 * 034 * <EMBED CLASS='external-html' DATA-JDK=ReadOnlySequencedCollection DATA-FILE-ID=INTERFACES> 035 * 036 * @param <E> the type of elements in this collection 037 */ 038@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="JDHBI_INTERFACE") 039public interface ReadOnlySequencedCollection<E> extends ReadOnlyCollection<E> 040{ 041 // ******************************************************************************************** 042 // ******************************************************************************************** 043 // Original JDK Interface Methods 044 // ******************************************************************************************** 045 // ******************************************************************************************** 046 047 048 /** 049 * Returns a reverse-ordered <a href="Collection.html#view">view</a> of this collection. The 050 * encounter order of elements in the returned view is the inverse of the encounter order of 051 * elements in this collection. The reverse ordering affects all order-sensitive operations, 052 * including those on the view collections of the returned view. 053 * 054 * @return a reverse-ordered view of this collection 055 */ 056 ReadOnlySequencedCollection<E> reversed(); 057 058 /** 059 * Gets the first element of this collection. 060 * 061 * @implSpec 062 * The implementation in this interface obtains an iterator of this collection, and then it 063 * obtains an element by calling the iterator's {@code next} method. Any 064 * {@code NoSuchElementException} thrown is propagated. Otherwise, it returns the element. 065 * 066 * @return the retrieved element 067 * @throws NoSuchElementException if this collection is empty 068 */ 069 default E getFirst() 070 { return this.iterator().next(); } 071 072 /** 073 * Gets the last element of this collection. 074 * 075 * @implSpec 076 * The implementation in this interface obtains an iterator of the reversed view of this 077 * collection, and then it obtains an element by calling the iterator's {@code next} method. 078 * Any {@code NoSuchElementException} thrown is propagated. Otherwise, it returns the element. 079 * 080 * @return the retrieved element 081 * @throws NoSuchElementException if this collection is empty 082 */ 083 default E getLast() 084 { return this.reversed().iterator().next(); } 085}