<commit_before>/*
The MIT License (MIT)

Copyright (c) 2016 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package linq.collections


import java.util.*
import kotlin.internal.getProgressionFinalElement

/**
 * Created by thoma on 02/02/2016.
 */

/**
 * Determines whether all elements of a sequence satisfy a condition.
 * @param list The collection to search
 * @param condition a lambda that returns true or false to indicate whether all elements meet the condition
 * @return whether all elements meet the condition
 */
fun<ElementType> All(list: AbstractList<ElementType>, condition: (ElementType) -> Boolean) : Boolean
{
    for(item: ElementType in list){
        if(!condition.invoke(item)){
            return false
        }
    }
    return true
}

/**
 * Determines whether all elements of a sequence satisfy a condition.
 * @param list The collection to search
 * @return whether the collection contains any elements
 **/
fun<ElementType> HasAny(list: AbstractList<ElementType>) : Boolean
{
    return list.size > 0
}
/**
 * Determines whether all elements of a sequence satisfy a condition.
 * @param list The collection to search
 * @param condition a lambda that returns true or false to indicate whether the collection contains any elements
 * that meet the specified condition
 * @return whether the collection contains any elements that meet the specified condition
 **/
fun<ElementType> HasAny(list: AbstractList<ElementType>, condition: (ElementType) -> Boolean) : Boolean
{
    if(list.size == 0){
        return false
    }
    for(item: ElementType in list){
        if(condition.invoke(item)){
            return true
        }
    }
    return false
}

/**
 * Retuns the inputted list as an AbstractList<Any>
 * @param list The collection to convert
 * @return the inputted list as an AbstractList<Any>
 */
fun<ElementType> AsAbstractList(list: AbstractList<ElementType>) : AbstractList<ElementType>{
    return list;
}

/**
 * Returns the average of a list of doubles
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType: Double> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Double = 0.0
    for(item: ElementType in list){
        total += item
    }
    total /= list.size
    return total as ElementType
}

/**
 * Returns the average of a list of floats
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Float> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Float = 0.0f
    for(item: ElementType in list){
        total += item
    }
    total /= list.size
    return total as ElementType
}

/**
 * Returns the average of a list of ints
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Int> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Int = 0
    for(item: ElementType in list){
        total += item
    }
    total /= list.size
    return total as ElementType
}

/**
 * Returns the average of a list of longs
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Long> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Long = 0L
    for(item: ElementType in list){
        total += item
    }
    total = list.size / total
    return total as ElementType
}

/**
 * Returns the average of a list of shorts
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Short> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Int = 0
    for(item: ElementType in list){
        total += (item as Short)
    }
    total /= list.size
    return total as ElementType
}

////TODO Report Error
///**
// * Returns the average of a list of shorts
// * @param list the list to average
// * @return the average value of the list
// */
//fun<ElementType : Short> Average(list: AbstractList<ElementType>) : ElementType
//{
//    var total : Short = 0 as Short
//    for(item: ElementType in list){
//        total += (item as Short)
//    }
//    total /= list.size
//    return total as ElementType
//}

/**
 * Casts all items in the list to the specified type
 * @param list the collection to cast
 * @return a collection containing the casted values<commit_msg>Remove Redundant Code<commit_after>/*
The MIT License (MIT)

Copyright (c) 2016 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package linq.collections


import java.util.*
import kotlin.internal.getProgressionFinalElement

/**
 * Created by thoma on 02/02/2016.
 */

/**
 * Determines whether all elements of a sequence satisfy a condition.
 * @param list The collection to search
 * @param condition a lambda that returns true or false to indicate whether all elements meet the condition
 * @return whether all elements meet the condition
 */
fun<ElementType> All(list: AbstractList<ElementType>, condition: (ElementType) -> Boolean) : Boolean
{
    for(item: ElementType in list){
        if(!condition.invoke(item)){
            return false
        }
    }
    return true
}

/**
 * Determines whether all elements of a sequence satisfy a condition.
 * @param list The collection to search
 * @return whether the collection contains any elements
 **/
fun<ElementType> HasAny(list: AbstractList<ElementType>) : Boolean
{
    return list.size > 0
}
/**
 * Determines whether all elements of a sequence satisfy a condition.
 * @param list The collection to search
 * @param condition a lambda that returns true or false to indicate whether the collection contains any elements
 * that meet the specified condition
 * @return whether the collection contains any elements that meet the specified condition
 **/
fun<ElementType> HasAny(list: AbstractList<ElementType>, condition: (ElementType) -> Boolean) : Boolean
{
    if(list.size == 0){
        return false
    }
    for(item: ElementType in list){
        if(condition.invoke(item)){
            return true
        }
    }
    return false
}

/**
 * Retuns the inputted list as an AbstractList<Any>
 * @param list The collection to convert
 * @return the inputted list as an AbstractList<Any>
 */
fun<ElementType> AsAbstractList(list: AbstractList<ElementType>) : AbstractList<ElementType>{
    return list;
}

/**
 * Returns the average of a list of doubles
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType: Double> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Double = 0.0
    for(item: ElementType in list){
        total += item
    }
    total /= list.size
    return total as ElementType
}

/**
 * Returns the average of a list of floats
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Float> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Float = 0.0f
    for(item: ElementType in list){
        total += item
    }
    total /= list.size
    return total as ElementType
}

/**
 * Returns the average of a list of ints
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Int> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Int = 0
    for(item: ElementType in list){
        total += item
    }
    total /= list.size
    return total as ElementType
}

/**
 * Returns the average of a list of longs
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Long> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Long = 0L
    for(item: ElementType in list){
        total += item
    }
    total = list.size / total
    return total as ElementType
}

/**
 * Returns the average of a list of shorts
 * @param list the list to average
 * @return the average value of the list
 */
fun<ElementType : Short> Average(list: AbstractList<ElementType>) : ElementType
{
    var total : Int = 0
    for(item: ElementType in list){
        total += (item as Short)
    }
    total /= list.size
    return total as ElementType
}
/**
 * Casts all items in the list to the specified type
 * @param list the collection to cast
 * @return a collection containing the casted values
{'fraction_non_alphanumeric': 0.08106786622335224, 'fraction_numerical': 0.004204967729317426, 'mean_word_length': 3.450391644908616, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5897966', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2684, 'n_words': 1250}