Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2012 Martin Skurla
  *
  * 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 org.crazyjavahacking.astvisualizer.impl.javac.util;
Collection utility class.

Author(s):
Martin
public final class CollectionUtils {
    //-----------------------------------------------------------------------------------------------------------------
    // Constructors.
    //-----------------------------------------------------------------------------------------------------------------
    private CollectionUtils() {}
    //-----------------------------------------------------------------------------------------------------------------
    // Public Methods.
    //-----------------------------------------------------------------------------------------------------------------
    
Creates list from given first element and variable number of rest elements.

Parameters:
<T> type of elements
firstElement first element
restElements variable number of rest elements
Returns:
created list
    public static <T> List<T> listOf(T firstElement, T... restElements) {
        List<T> resultList = new ArrayList<T>(restElements.length + 1); // including first element
        resultList.add(firstElement);
        resultList.addAll(Arrays.asList(restElements));
        return resultList;
    }

    
Reverses given list order and returns it as immutable list.

Parameters:
<T> type of list elements
list list
Returns:
reversed immutable list
    public static <T> List<T> reverseListOrder(List<T> list) {
        List<T> shallowCopy = new ArrayList<T>(list);
        Collections.reverse(shallowCopy);
        return Collections.unmodifiableList(shallowCopy);
    }

    
Transforms given Iterator object into Iterable.

Parameters:
<T> type of iterable elements
iterator iterator
Returns:
iterable
    public static <T> Iterable<T> toIterable(final Iterator<T> iterator) {
        return new Iterable<T>() {
            @Override
            public Iterator<T> iterator() {
                return iterator;
            }
        };
    }
New to GrepCode? Check out our FAQ X