com.linkedin.bowser.core.functions.List.java Source code

Java tutorial

Introduction

Here is the source code for com.linkedin.bowser.core.functions.List.java

Source

/*
 * Copyright 2010-2011 LinkedIn Corporation
 * 
 * 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 com.linkedin.bowser.core.functions;

import java.util.ArrayList;
import java.util.Map;

import com.google.common.collect.Iterables;
import com.linkedin.bowser.core.objects.Collection;
import com.linkedin.bowser.core.objects.ListObject;
import com.linkedin.bowser.core.objects.NQLObject;

/**
 * @author sdawson
 * 
 */
public class List extends AbstractNQLFunction implements NQLFunction {
    /*
     * (non-Javadoc)
     * 
     * @see com.linkedin.nql.core.functions.Function#getName()
     */
    @Override
    public String getName() {
        return "list";
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.linkedin.nql.core.functions.Function#apply(java.util.List)
     */
    @Override
    public NQLObject apply(Map<String, NQLObject> globals, java.util.List<NQLObject> arguments) {
        assertNumberOfArguments(arguments, 1);
        Collection c = getAsCollection(arguments.get(0));

        java.util.List<NQLObject> list = new ArrayList<NQLObject>();
        Iterables.addAll(list, c);

        return new ListObject(list);
    }
}