// Path: app/utils/CollectionUtils.java
// public class CollectionUtils
// {
//     private CollectionUtils()
//     {
//         // no-op
//     }
// 
//     /**
//      * Gets the first element of the list.
//      *
//      * @param list the list
//      * @param <T> the list's generic type
//      * @return the first element of the list, or null if the list is null or empty.  The returned value will also be null
//      * if the first element of the list is null.
//      */
//     public static <T> T first(List<T> list)
//     {
//         return isEmpty(list) ? null : list.get(0);
//     }
// 
//     /**
//      * Gets the last element of the list.
//      *
//      * @param list the list
//      * @param <T> the list's generic type
//      * @return the last element of the list, or null if the list is null or empty.  The returned value will also be null
//      * if the last element of the list is null.
//      */
//     public static <T> T last(List<T> list)
//     {
//         return isEmpty(list) ? null : list.get(list.size() - 1);
//     }
// 
//     /**
//      * Checks if a collection is null or empty.
//      *
//      * @param c the collection
//      * @return true if the collection is null or has a length of 0. A collection containing null entries is considered
//      * to be non-empty.
//      */
//     public static boolean isEmpty(Collection c)
//     {
//         return c == null || c.isEmpty();
//     }
// 
//     /**
//      * Gets the first matching element of collection, using the filter.
//      *
//      * @param collection the collection to filter
//      * @param filter filters the elements
//      * @param <T> the generic type
//      * @return the first element that is accepted by the filter, or null if the collection is null, empty or contains
//      * no acceptable elements
//      */
//     public static <T> T filterFirst(Collection<T> collection,
//                                     Filter<T> filter)
//     {
//         T t = null;
// 
//         if (!isEmpty(collection))
//         {
//             for (Iterator<T> iterator = collection.iterator(); t == null && iterator.hasNext(); )
//             {
//                 T element = iterator.next();
//                 t = filter.isAcceptable(element) ? element :  null;
//             }
//         }
// 
//         return t;
//     }
// 
//     /**
//      * Transforms a collection of objects of one type into a list of another type.
//      *
//      * @param input the collection to transform
//      * @param transformer transforms individual objects
//      * @param <I> the input type to tranform
//      * @param <O> the output type that is the result of the transformation
//      * @return a list of transformed objects
//      */
//     public static <I, O> List<O> transform(Collection<I> input,
//                                            Transformer<I, O> transformer)
//     {
//         List<O> output = new ArrayList<O>();
//         if (input != null)
//         {
//             for (I i : input)
//             {
//                 if (i != null)
//                 {
//                     output.add(transformer.transform(i));
//                 }
//             }
//         }
//         return output;
//     }
// 
//     /**
//      * Convenience method for type erasure when casting lists.
//      *
//      * @param list the list to cast
//      * @param t the class type
//      * @param <T> the generic type
//      * @return a list of type T
//      */
//     public static <T> List<T> castTo(List list,
//                                     Class<T> t)
//     {
//         return (List<T>)list;
//     }
// }
// 
// Path: app/utils/Transformer.java
// public interface Transformer<I, O>
// {
//     O transform(I input);
// }


import play.data.validation.Constraints;
import utils.CollectionUtils;
import utils.Transformer;
import javax.persistence.*;
import java.util.*;

/*
 * Copyright 2012 The Play! Framework
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package models;



/**
 * @author Steve Chaloner (steve@objectify.be)
 */
@Entity
public class ModuleVersion extends AbstractModel {

    @ManyToOne
    public Module playModule;

    // this will be taken from Build.scala
    @Column(nullable = false)
    @Constraints.Required
    public String versionCode;

    @Column(nullable = false)
    @Constraints.Required
    public String releaseNotes;

    @Column(nullable = false)
    public Date releaseDate;

    @ManyToMany
    public List<PlayVersion> compatibility;

    @OneToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public BinaryContent binaryFile;

    @OneToOne(optional = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public BinaryContent sourceFile;

    @OneToOne(optional = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public BinaryContent documentFile;

    public static final Finder<Long, ModuleVersion> FIND = new Finder<Long, ModuleVersion>(Long.class,
            ModuleVersion.class);

    public static int count() {
        return FIND.findRowCount();
    }

    public Set<PlayVersion.MajorVersion> getMajorVersions()
    {
        Set<PlayVersion.MajorVersion> majorVersions = new HashSet<PlayVersion.MajorVersion>();

// Path: app/utils/CollectionUtils.java
// public class CollectionUtils
// {
//     private CollectionUtils()
//     {
//         // no-op
//     }
// 
//     /**
//      * Gets the first element of the list.
//      *
//      * @param list the list
//      * @param <T> the list's generic type
//      * @return the first element of the list, or null if the list is null or empty.  The returned value will also be null
//      * if the first element of the list is null.
//      */
//     public static <T> T first(List<T> list)
//     {
//         return isEmpty(list) ? null : list.get(0);
//     }
// 
//     /**
//      * Gets the last element of the list.
//      *
//      * @param list the list
//      * @param <T> the list's generic type
//      * @return the last element of the list, or null if the list is null or empty.  The returned value will also be null
//      * if the last element of the list is null.
//      */
//     public static <T> T last(List<T> list)
//     {
//         return isEmpty(list) ? null : list.get(list.size() - 1);
//     }
// 
//     /**
//      * Checks if a collection is null or empty.
//      *
//      * @param c the collection
//      * @return true if the collection is null or has a length of 0. A collection containing null entries is considered
//      * to be non-empty.
//      */
//     public static boolean isEmpty(Collection c)
//     {
//         return c == null || c.isEmpty();
//     }
// 
//     /**
//      * Gets the first matching element of collection, using the filter.
//      *
//      * @param collection the collection to filter
//      * @param filter filters the elements
//      * @param <T> the generic type
//      * @return the first element that is accepted by the filter, or null if the collection is null, empty or contains
//      * no acceptable elements
//      */
//     public static <T> T filterFirst(Collection<T> collection,
//                                     Filter<T> filter)
//     {
//         T t = null;
// 
//         if (!isEmpty(collection))
//         {
//             for (Iterator<T> iterator = collection.iterator(); t == null && iterator.hasNext(); )
//             {
//                 T element = iterator.next();
//                 t = filter.isAcceptable(element) ? element :  null;
//             }
//         }
// 
//         return t;
//     }
// 
//     /**
//      * Transforms a collection of objects of one type into a list of another type.
//      *
//      * @param input the collection to transform
//      * @param transformer transforms individual objects
//      * @param <I> the input type to tranform
//      * @param <O> the output type that is the result of the transformation
//      * @return a list of transformed objects
//      */
//     public static <I, O> List<O> transform(Collection<I> input,
//                                            Transformer<I, O> transformer)
//     {
//         List<O> output = new ArrayList<O>();
//         if (input != null)
//         {
//             for (I i : input)
//             {
//                 if (i != null)
//                 {
//                     output.add(transformer.transform(i));
//                 }
//             }
//         }
//         return output;
//     }
// 
//     /**
//      * Convenience method for type erasure when casting lists.
//      *
//      * @param list the list to cast
//      * @param t the class type
//      * @param <T> the generic type
//      * @return a list of type T
//      */
//     public static <T> List<T> castTo(List list,
//                                     Class<T> t)
//     {
//         return (List<T>)list;
//     }
// }
// 
// Path: app/utils/Transformer.java
// public interface Transformer<I, O>
// {
//     O transform(I input);
// }


// Path: app/models/ModuleVersion.java
import play.data.validation.Constraints;
import utils.CollectionUtils;
import utils.Transformer;
import javax.persistence.*;
import java.util.*;

/*
 * Copyright 2012 The Play! Framework
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package models;



/**
 * @author Steve Chaloner (steve@objectify.be)
 */
@Entity
public class ModuleVersion extends AbstractModel {

    @ManyToOne
    public Module playModule;

    // this will be taken from Build.scala
    @Column(nullable = false)
    @Constraints.Required
    public String versionCode;

    @Column(nullable = false)
    @Constraints.Required
    public String releaseNotes;

    @Column(nullable = false)
    public Date releaseDate;

    @ManyToMany
    public List<PlayVersion> compatibility;

    @OneToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public BinaryContent binaryFile;

    @OneToOne(optional = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public BinaryContent sourceFile;

    @OneToOne(optional = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public BinaryContent documentFile;

    public static final Finder<Long, ModuleVersion> FIND = new Finder<Long, ModuleVersion>(Long.class,
            ModuleVersion.class);

    public static int count() {
        return FIND.findRowCount();
    }

    public Set<PlayVersion.MajorVersion> getMajorVersions()
    {
        Set<PlayVersion.MajorVersion> majorVersions = new HashSet<PlayVersion.MajorVersion>();

        Transformer<PlayVersion, PlayVersion.MajorVersion> transformer = new MajorVersionExtractor();
