/*******************************************************************************
 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
 * which accompanies this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Oracle - initial API and implementation
 *
 ******************************************************************************/
package org.eclipse.persistence.jpa.jpql.spi;

import java.util.Arrays;
import java.util.List;

/**
 * An enumeration listing the various releases of the Java Persistence specification.
 *
 * @version 2.4
 * @since 2.3
 * @author Pascal Filion
 */
public enum JPAVersion {

	/**
	 * The constant for the default version used by the parsing system, which is always the latest
	 * version of the Java Persistence functional specification.
	 */
	DEFAULT_VERSION(2.0),

	/**
	 * The constant for the Java Persistence version 1.0.
	 */
	VERSION_1_0(1.0),

	/**
	 * The constant for the Java Persistence version 2.0.
	 */
	VERSION_2_0(2.0);

	/**
	 * The constant for the Java Persistence version 2.1.
	 */
//	VERSION_2_1(2.1);

	/**
	 * The real version number.
	 */
	private double version;

	/**
	 * Creates a new <code>IJPAVersion</code>.
	 *
	 * @param version The actual version number
	 */
	private JPAVersion(double version) {
		this.version = version;
	}

	/**
	 * Retrieves the enumeration constant for the given value. If the value is not known, then
	 * {@link #DEFAULT_VERSION} will be returned.
	 *
	 * @param value The value to retrieve its constant version
	 * @return The constant version of the given value
	 */
	public static JPAVersion value(String value) {
		for (JPAVersion version : versions()) {
			if (version.getVersion().equals(value)) {
				return version;
			}
		}
		return DEFAULT_VERSION;
	}

	/**
	 * Returns the list of {@link IJPAVersion IJPAVersions} excluding {@link #DEFAULT_VERSION}.
	 *
	 * @return The list of unique constants
	 */
	public static JPAVersion[] versions() {
		List<JPAVersion> values = Arrays.asList(values());
		values.remove(DEFAULT_VERSION);
		return values.toArray(new JPAVersion[values.size()]);
	}

	/**
	 * Returns the real version this constant represents.
	 *
	 * @return The string value of the version
	 */
	public String getVersion() {
		return String.valueOf(version);
	}

	/**
	 * Determines whether this constant represents a version that is newer than the given version.
	 *
	 * @param version The constant to verify if it's representing a version that is older than this one
	 * @return <code>true</code> if this constant represents a newer version and the given constant
	 * represents a version that is older; <code>false</code> if the given constant represents a
	 * newer and this constant represents an older version
	 */
	public boolean isNewerThan(JPAVersion version) {
		return this.version > version.version;
	}

	/**
	 * Determines whether this constant represents a version that is newer than the given version or
	 * if it's the same version.
	 *
	 * @param version The constant to verify if it's representing a version that is older than this
	 * one or if it's the same than this one
	 * @return <code>true</code> if this constant represents a newer version and the given constant
	 * represents a version that is older or if it's the same constant; <code>false</code> if the
	 * given constant represents a newer and this constant represents an older version
	 */
	public boolean isNewerThanOrEqual(JPAVersion version) {
		return this.version >= version.version;
	}

	/**
	 * Determines whether this constant represents a version that is older than the given version.
	 *
	 * @param jpaVersion The constant to verify if it's representing a version that is more recent
	 * than this one
	 * @return <code>true</code> if this constant represents an earlier version and the given
	 * constant represents a version that is more recent; <code>false</code> if the given constant
	 * represents an earlier version and this constant represents a more recent version
	 */
	public boolean isOlderThan(JPAVersion version) {
		return this.version < version.version;
	}

	/**
	 * Determines whether this constant represents a version that is older than the given version or
	 * if it's the same version.
	 *
	 * @param version The constant to verify if it's representing a version that is more recent than
	 * this one or if it's the same than this one
	 * @return <code>true</code> if this constant represents an earlier version and the given
	 * constant represents a version that is more recent or if it's the same constant; <code>false</code>
	 * if the given constant represents an earlier version and this constant represents a more recent
	 * version
	 */
	public boolean isOlderThanOrEqual(JPAVersion version) {
		return this.version <= version.version;
	}

	/**
	 * Converts the current constant to one of the known versions, this means if the constant is
	 * {@link #DEFAULT_VERSION}, then it will be converted into the actual constant representing that
	 * version.
	 *
	 * @return Either this same constant or the actual version constant
	 */
	public JPAVersion toCurrentVersion() {

		if (this == DEFAULT_VERSION) {

			String currentVersion = getVersion();

			for (JPAVersion version : versions()) {
				if (currentVersion.equals(version.version)) {
					return version;
				}
			}
		}

		return this;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		return getVersion();
	}
}
@@ -745,58 +745,8 @@
 %0D%0A%0D%0A
-import java.util.Arrays;%0D%0Aimport java.util.List;%0D%0A
 %0D%0A/*
@@ -2326,13 +2326,8 @@
 %0D%0A%09%09
-List%3C
 JPAV
@@ -2332,17 +2332,18 @@
 AVersion
-%3E
+%5B%5D
  values 
@@ -2348,66 +2348,81 @@
 s = 
-Arrays.asList(values());%0D%0A%09%09values.remove(DEFAULT_
+new JPAVersion%5B2%5D;%0D%0A%09%09values%5B0%5D = VERSION_1_0;%0D%0A%09%09values%5B1%5D = 
 VERSION
-)
+_2_0
 ;%0D%0A%09
@@ -2439,47 +2439,8 @@
 lues
-.toArray(new JPAVersion%5Bvalues.size()%5D)
 ;%0D%0A%09

Create an array directly in version()