/*
(non-Javadoc)

@see
javax.persistence.criteria.CriteriaBuilder#tuple(javax.persistence.criteria
.Selection<?>[])
769884
@Override
    public CompoundSelection<Tuple> tuple(Selection<?>... arg0)
    {
        return new DefaultCompoundSelection<Tuple>(Arrays.asList(arg0), Tuple.class);

    }
37409
@Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        Cursor result = null;

        if (!controller.hasPreinitialized()) {
            throw new IllegalStateException("Controller has not been initialized.");
        }

        int patternCode = controller.getUriMatcher().match(uri);
        MatcherPattern pattern = controller.findMatcherPattern(patternCode);
        if (pattern == null) {
            throw new IllegalArgumentException("unknown uri : " + uri.toString());
        }

        Parameter parameter = new Parameter(uri, projection, selection, selectionArgs, sortOrder);
        SQLiteDatabase db = this.getHelper().getReadableDatabase();

        result = onQuery(this.getHelper(), db, pattern, parameter);
        if (result != null) {
            this.onQueryCompleted(result, uri, pattern, parameter);
        }
        return result;
    }
1135461
private static List<Tuple> tuplesResult(EntityKey[] keys, Object[] searchObjects, TupleContext tupleContext, MongoCursor<Document> cursor) {
		// The list is initialized with null because some keys might not have a corresponding value in the cursor
		Tuple[] tuples = new Tuple[searchObjects.length];
		while ( cursor.hasNext() ) {
			Document document = cursor.next();
			for ( int i = 0; i < searchObjects.length; i++ ) {
				if ( document.get( ID_FIELDNAME ).equals( searchObjects[i] ) ) {
					tuples[i] = createTuple( keys[i], tupleContext, document );
					// We assume there are no duplicated keys
					break;
				}
			}
		}
		return Arrays.asList( tuples );
	}
1171996
public static <T> LazyIterable<T> select(Iterable<T> iterable, Predicate<? super T> predicate)
    {
        return new SelectIterable<T>(iterable, predicate);
    }
971546
public static <Item extends IItem> void findSubItemSelections(Item item, List<String> selections) {
        if (item instanceof IExpandable && !((IExpandable) item).isExpanded() && ((IExpandable) item).getSubItems() != null) {
            List<Item> subItems = (List<Item>) ((IExpandable<Item, ?>) item).getSubItems();
            for (int i = 0, size = subItems.size(); i < size; i++) {
                Item subItem = subItems.get(i);
                String id = String.valueOf(subItem.getIdentifier());
                if (subItem.isSelected()) {
                    selections.add(id);
                }
                findSubItemSelections(subItem, selections);
            }
        }
    }
681508
public static List<Integer> asList(final IntTuple t)
    {
        if (t == null)
        {
            throw new NullPointerException("The tuple may not be null");
        }
        return new AbstractList<Integer>()
        {
            @Override
            public Integer get(int index)
            {
                return t.get(index);
            }

            @Override
            public int size()
            {
                return t.getSize();
            }
        };
    }
937347
public T select(T option)
	{
		int index = options().indexOf(option);
		if (index == -1 || index == selectedIndex)
			return selected();

		if (fireEvent(new SelectEvent<>(this, option)))
			setSelected(option);

		return selected();
	}
519233
@SuppressWarnings("unchecked")
    public static <K, V> List<Tuple<K, V>> pick(final Map<K, V> object, final K ... keys) {
        return without(map(newArrayList(object.entrySet()), new Function<Map.Entry<K, V>, Tuple<K, V>>() {
            @Override
            public Tuple<K, V> apply(Map.Entry<K, V> entry) {
                if (Arrays.asList(keys).contains(entry.getKey())) {
                    return Tuple.create(entry.getKey(), entry.getValue());
                } else {
                    return null;
                }
            }
        }), (Tuple<K, V>) null);
    }
153484
public static <G extends GroupedOptions> G select(String[] params, G... groupings)
    {
        for (String param : params)
        {
            boolean accepted = false;
            for (GroupedOptions grouping : groupings)
                accepted |= grouping.accept(param);
            if (!accepted)
                throw new IllegalArgumentException("Invalid parameter " + param);
        }
        for (G grouping : groupings)
            if (grouping.happy() && grouping.accepted == params.length)
                return grouping;
        return null;
    }
233176
private void setCollectionTupleValues(Tuple tuple, int position, Object value, AbstractType<?> validator) throws ExecException
    {
        if (validator instanceof MapType)
        {
            setMapTupleValues(tuple, position, value, validator);
            return;
        }
        AbstractType elementValidator;
        if (validator instanceof SetType)
            elementValidator = ((SetType<?>) validator).getElementsType();
        else if (validator instanceof ListType)
            elementValidator = ((ListType<?>) validator).getElementsType();
        else
            return;

        int i = 0;
        Tuple innerTuple = TupleFactory.getInstance().newTuple(((Collection<?>) value).size());
        for (Object entry : (Collection<?>) value)
        {
            setTupleValue(innerTuple, i, cassandraToPigData(entry, elementValidator), elementValidator);
            i++;
        }
        tuple.set(position, innerTuple);
    }
580541
GeometryIndex[] getSelection() {
		List<GeometryIndex> indices = delegate.getSelection();
		return indices.toArray(new GeometryIndex[indices.size()]);
	}
169883
private void buildSelect(final StringBuilder selectBuilder, final List<Projection> projections) {
        selectBuilder.append("SELECT ");
        if (null == projections || projections.isEmpty()) {
            selectBuilder.append(" * ");

            return;
        }

        selectBuilder.append(projections.stream().map(Projection::getKey).collect(Collectors.joining(", ")));
    }
697674
public void select(String[] optionLocators) {
        for (int i = 0; i < optionLocators.length; i++) {
            select(optionLocators[i]);
        }
    }
67203
static Set<String> serializeComparators(Criteria criteria, Configuration conf,
	    List<String> comparatorRefs, List<String> comparatorInstanceFiles, String prefix)
	    throws TupleMRException {

		Set<String> instanceFiles = new HashSet<String>();
		
		if(criteria == null) {
			return instanceFiles;
		}

		for(SortElement element : criteria.getElements()) {
			if(element.getCustomComparator() != null) {
				RawComparator<?> comparator = element.getCustomComparator();

				if(!(comparator instanceof Serializable)) {
					throw new TupleMRException("The class '" + comparator.getClass().getName()
					    + "' is not Serializable."
					    + " The customs comparators must implement Serializable.");
				}

				String ref = prefix + "|" + element.getName();
				String uniqueName = UUID.randomUUID().toString() + '.' + "comparator.dat";
				try {
					InstancesDistributor.distribute(comparator, uniqueName, conf);
					instanceFiles.add(uniqueName);
				} catch(Exception e) {
					throw new TupleMRException("The class " + comparator.getClass().getName() + 
							" can't be serialized"
							,e);
				}

				comparatorRefs.add(ref);
				comparatorInstanceFiles.add(uniqueName);
			}
		}
		
		return instanceFiles;
	}
406721
@NonNull
  public static Term tuple(@NonNull Term... components) {
    return tuple(Arrays.asList(components));
  }
757348
public Criteria subsetof(Collection<?> c) {
        notNull(c, "collection can not be null");
        this.criteriaType = RelationalOperator.SUBSETOF;
        this.right = new ValueListNode(c);
        return this;
    }
427568
public static Tuple of( Collection<VarBindingDef> tupleBindings)
    {
    Tuple tuple = new Tuple();
    
    boolean bindingsCompatible;
    Iterator<VarBindingDef> bindings;
    VarBindingDef nextBinding;
    for( bindings = tupleBindings.iterator(),
           bindingsCompatible = true; 

         bindings.hasNext()
           && (bindingsCompatible = isBindingCompatible( tuple, (nextBinding = bindings.next())));

         tuple.add( nextBinding));
    
    return
      bindingsCompatible && tuple.isCompatible()
      ? tuple
      : null;
    }