Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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:
 *   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::lset() : T</tt></li>
     * <li><tt>Sequence::lset() : T</tt></li>
     * </ul>
     * operations.
     * 
     * @param self the source collection
     * @return the last object in the source collection
     */
    public static <E> E last(Collection<E> self) {
        if (self.isEmpty()) {
            return null; // undefined
        }
        E result = null;
        for (E next : self) {
            result = next;
        }
        return result;
    }

    /**
     * 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();
    }
}