Here you can find the source of first(Collection
Parameter | Description |
---|---|
self | the source collection |
public static <E> E first(Collection<E> self)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006, 2012, 2011 IBM Corporation, Zeligsoft Inc., and others. * 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:/*from w w w.ja v a 2 s .com*/ * IBM - Initial API and implementation * Zeligsoft - Bugs 244946, 248869 * Axel Uhl (SAP AG) - Bug 342644 *******************************************************************************/ import java.util.Collection; public class Main { /** * Implementation of the OCL * <ul> * <li><tt>OrderedSet::first() : T</tt></li> * <li><tt>Sequence::first() : T</tt></li> * </ul> * operations. * * @param self the source collection * @return the first object of the source collection */ public static <E> E first(Collection<E> self) { if (self.isEmpty()) { return null; // undefined } return self.iterator().next(); } /** * Implementation of the OCL * <tt>Collection::isEmpty() : Boolean</tt> * operation. * * @param self the source collection * @return whether the collection does not have any elements */ public static boolean isEmpty(Collection<?> self) { return self.isEmpty(); } }