当前位置: 首页>>代码示例>>Java>>正文


Java Function1.apply方法代码示例

本文整理汇总了Java中org.eclipse.xtext.xbase.lib.Functions.Function1.apply方法的典型用法代码示例。如果您正苦于以下问题:Java Function1.apply方法的具体用法?Java Function1.apply怎么用?Java Function1.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.xbase.lib.Functions.Function1的用法示例。


在下文中一共展示了Function1.apply方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: groupBy

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns a map for which the {@link Map#values} is a collection of lists, where the elements in the list will 
 * appear in the order as they appeared in the iterator. Each key is the product of invoking the supplied 
 * function {@code computeKeys} on its corresponding value. So a key of that map groups a list of values for 
 * which the function produced exactly that key. The value iterator is left exhausted.
 * 
 * @param values
 *            the values to use when constructing the {@code Map}. May not be <code>null</code>.
 * @param computeKeys
 *            the function used to produce the key for each value. May not be <code>null</code>.
 * @return a map mapping the result of evaluating the function {@code keyFunction} on each value in the input
 *         iterator to that value. As there can be more than one value mapped by a key, the mapping result is is a
 *         list of values.
 * @since 2.7
 */
public static <K, V> Map<K, List<V>> groupBy(Iterator<? extends V> values,
		Function1<? super V, ? extends K> computeKeys) {
	if (computeKeys == null)
		throw new NullPointerException("computeKeys");
	Map<K, List<V>> result = Maps.newLinkedHashMap();
	while(values.hasNext()) {
		V v = values.next();
		K key = computeKeys.apply(v);
		List<V> grouped = result.get(key);
		if (grouped == null) {
			grouped = new ArrayList<V>();
			result.put(key, grouped);
		}
		grouped.add(v);
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:33,代码来源:IteratorExtensions.java

示例2: takeWhile

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns an Iterator containing all elements starting from the head of the source up to and excluding the first
 * element that violates the predicate. The resulting Iterator is a lazily computed view, so any modifications to the
 * underlying Iterators will be reflected on iteration. The result does not support {@link Iterator#remove()}
 * 
 * @param iterator
 *            the elements from which to take. May not be <code>null</code>.
 * @param predicate
 *            the predicate which decides whether to keep taking elements. May not be <code>null</code>.
 * @return the taken elements
 * @since 2.7
 */
public static <T> Iterator<T> takeWhile(final Iterator<? extends T> iterator, final Function1<? super T, Boolean> predicate) {
	if (iterator == null)
		throw new NullPointerException("iterator");
	if (predicate == null)
		throw new NullPointerException("predicate");
	return new AbstractIterator<T>() {
		@Override
		protected T computeNext() {
			if (!iterator.hasNext())
				return endOfData();
			T next = iterator.next();
			if (predicate.apply(next)) {
				return next;
			} else {
				return endOfData();
			}
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:32,代码来源:IteratorExtensions.java

示例3: toQualifiedNames

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
protected <T extends Object> CharSequence toQualifiedNames(final List<T> it, final Function1<? super T, ? extends String> toQualifiedNameFunction) {
  CharSequence _xblockexpression = null;
  {
    if (((it == null) || (it.size() == 0))) {
      return "";
    }
    StringConcatenation _builder = new StringConcatenation();
    {
      boolean _hasElements = false;
      for(final T element : it) {
        if (!_hasElements) {
          _hasElements = true;
        } else {
          _builder.appendImmediate(", ", "");
        }
        String _apply = toQualifiedNameFunction.apply(element);
        _builder.append(_apply);
      }
    }
    _xblockexpression = _builder;
  }
  return _xblockexpression;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:24,代码来源:DefaultCopyQualifiedNameService.java

示例4: getValueAsString

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getValueAsString() {
	final StringBuilder result = new StringBuilder("`");
	final Function1<Expression, StringBuilder> _function = new Function1<Expression, StringBuilder>() {
		public StringBuilder apply(final Expression expr) {
			StringBuilder _switchResult = null;
			boolean _matched = false;
			if (expr instanceof Literal) {
				_matched=true;
				_switchResult = result.append(TemplateLiteralImpl.this.getValueAsString());
			}
			if (!_matched) {
				_switchResult = result.append("<<").append(TemplateLiteralImpl.this.eClass().getName()).append(">>");
			}
			return _switchResult;
		}
	};
	final Function1<Expression, StringBuilder> appender = _function;
	final Function2<Boolean, Expression, Boolean> _function_1 = new Function2<Boolean, Expression, Boolean>() {
		public Boolean apply(final Boolean isRaw, final Expression expression) {
			if ((!(isRaw).booleanValue())) {
				result.append("${");
				appender.apply(expression);
				result.append("}");
			}
			else {
				appender.apply(expression);
			}
			return Boolean.valueOf((!(isRaw).booleanValue()));
		}
	};
	IterableExtensions.<Expression, Boolean>fold(this.getSegments(), Boolean.valueOf(true), _function_1);
	result.append("`");
	return result.toString();
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:40,代码来源:TemplateLiteralImpl.java

示例5: surround

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
public Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> surround(final INode node, final Procedure1<? super FormattingDataInit> init) {
  final Function1<FormattableDocument, Iterable<FormattingData>> _function = (FormattableDocument doc) -> {
    ArrayList<FormattingData> _xblockexpression = null;
    {
      final ArrayList<FormattingData> result = CollectionLiterals.<FormattingData>newArrayList();
      if ((node != null)) {
        Iterable<FormattingData> _elvis = null;
        Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _newFormattingData = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsBefore(node), init);
        Iterable<FormattingData> _apply = null;
        if (_newFormattingData!=null) {
          _apply=_newFormattingData.apply(doc);
        }
        if (_apply != null) {
          _elvis = _apply;
        } else {
          List<FormattingData> _emptyList = CollectionLiterals.<FormattingData>emptyList();
          _elvis = _emptyList;
        }
        Iterables.<FormattingData>addAll(result, _elvis);
        Iterable<FormattingData> _elvis_1 = null;
        Function1<? super FormattableDocument, ? extends Iterable<FormattingData>> _newFormattingData_1 = this.newFormattingData(this._hiddenLeafAccess.getHiddenLeafsAfter(node), init);
        Iterable<FormattingData> _apply_1 = null;
        if (_newFormattingData_1!=null) {
          _apply_1=_newFormattingData_1.apply(doc);
        }
        if (_apply_1 != null) {
          _elvis_1 = _apply_1;
        } else {
          List<FormattingData> _emptyList_1 = CollectionLiterals.<FormattingData>emptyList();
          _elvis_1 = _emptyList_1;
        }
        Iterables.<FormattingData>addAll(result, _elvis_1);
      }
      _xblockexpression = result;
    }
    return _xblockexpression;
  };
  return _function;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:40,代码来源:FormattingDataFactory.java

示例6: exists

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns {@code true} if one or more elements in {@code iterator} satisfy the predicate.
 * 
 * @param iterator
 *            the iterator. May not be <code>null</code>.
 * @param predicate
 *            the predicate. May not be <code>null</code>.
 * @return <code>true</code> if one or more elements in {@code iterator} satisfy the predicate.
 */
public static <T> boolean exists(Iterator<T> iterator, Function1<? super T, Boolean> predicate) {
	if (predicate == null)
		throw new NullPointerException("predicate");
	while(iterator.hasNext()) {
		if (predicate.apply(iterator.next()))
			return true;
	}
	return false;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:19,代码来源:IteratorExtensions.java

示例7: dropWhile

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns an Iterator containing all elements starting from the first element for which the drop-predicate returned
 * false. The resulting Iterator is a lazily computed view, so any modifications to the
 * underlying Iterators will be reflected on iteration. The result does not support {@link Iterator#remove()}
 * 
 * @param iterator
 *            the elements from which to drop. May not be <code>null</code>.
 * @param predicate
 *            the predicate which decides whether to keep dropping elements. May not be <code>null</code>.
 * @return the remaining elements after dropping
 * @since 2.7
 */
public static <T> Iterator<T> dropWhile(final Iterator<? extends T> iterator, final Function1<? super T, Boolean> predicate) {
	if (iterator == null)
		throw new NullPointerException("iterator");
	if (predicate == null)
		throw new NullPointerException("predicate");
	return new AbstractIterator<T>() {
		private boolean headFound = false;

		@Override
		protected T computeNext() {
			while (!headFound) {
				if (!iterator.hasNext())
					return endOfData();
				T next = iterator.next();
				if (!predicate.apply(next)) {
					headFound = true;
					return next;
				}
			}
			if (iterator.hasNext()) {
				return iterator.next();
			} else {
				return endOfData();
			}
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:40,代码来源:IteratorExtensions.java

示例8: curry

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Curries a function that takes one argument.
 * 
 * @param function
 *            the original function. May not be <code>null</code>.
 * @param argument
 *            the fixed argument.
 * @return a function that takes no arguments. Never <code>null</code>.
 */
@Pure
public static <P1, RESULT> Function0<RESULT> curry(final Function1<? super P1, ? extends RESULT> function, final P1 argument) {
	if (function == null)
		throw new NullPointerException("function");
	return new Function0<RESULT>() {
		@Override
		public RESULT apply() {
			return function.apply(argument);
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:21,代码来源:FunctionExtensions.java

示例9: collect

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
protected <R extends Collection<? super T>, T extends Object> R collect(final T start, final Function1<? super T, ? extends Iterable<T>> reachable, final R collector) {
  boolean _add = collector.add(start);
  if (_add) {
    Iterable<T> _apply = reachable.apply(start);
    for (final T r : _apply) {
      this.<R, T>collect(r, reachable, collector);
    }
  }
  return collector;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:11,代码来源:AbstractTraceRegionToString.java

示例10: findFirst

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Finds the first element in the given iterator that fulfills the predicate. If none is found or the iterator is
 * empty, <code>null</code> is returned.
 * 
 * @param iterator
 *            the iterator. May not be <code>null</code>.
 * @param predicate
 *            the predicate. May not be <code>null</code>.
 * @return the first element in the iterator for which the given predicate returns <code>true</code>, returns
 *         <code>null</code> if no element matches the predicate or the iterator is empty.
 */
public static <T> T findFirst(Iterator<T> iterator, Function1<? super T, Boolean> predicate) {
	if (predicate == null)
		throw new NullPointerException("predicate");
	while(iterator.hasNext()) {
		T t = iterator.next();
		if (predicate.apply(t))
			return t;
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:22,代码来源:IteratorExtensions.java

示例11: forall

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns {@code true} if every element in {@code iterator} satisfies the predicate. If {@code iterator} is empty,
 * {@code true} is returned. In other words, <code>false</code> is returned if at least one element fails to fulfill
 * the predicate.
 * 
 * @param iterator
 *            the iterator. May not be <code>null</code>.
 * @param predicate
 *            the predicate. May not be <code>null</code>.
 * @return <code>true</code> if every element in {@code iterator} satisfies the predicate and also if there is no element.
 */
public static <T> boolean forall(Iterator<T> iterator, Function1<? super T, Boolean> predicate) {
	if (predicate == null)
		throw new NullPointerException("predicate");
	while(iterator.hasNext()) {
		if (!predicate.apply(iterator.next()))
			return false;
	}
	return true;
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:21,代码来源:IteratorExtensions.java

示例12: compose

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns a composed function that first applies the {@code before}
 * function to its input, and then applies the {@code after} function to the result.
 * If evaluation of either function throws an exception, it is relayed to
 * the caller of the composed function.
 *
 * @param <V> the type of input to the {@code before} function, and to the
 *        composed function
 * @param <T> the type of output of the {@code before} function, and input to the
 *        {@code after} function
 * @param <R> the type of output to the {@code after} function, and to the
 *        composed function
 * @param after the function to apply after the before function is applied
 * @param before the function to apply before the after function is applied
 * @return a composed function that first applies the {@code before}
 * function and then applies the {@code after} function
 * @throws NullPointerException if {@code before} or {@code after} is <code>null</code>
 *
 * @see #andThen(Function1, Function1)
 * @since 2.9
 */
public static <V,T,R> Function1<V, R> compose(final Function1<? super T, ? extends R> after, final Function1<? super V, ? extends T> before) {
	if (after == null)
		throw new NullPointerException("after");
	if (before == null)
		throw new NullPointerException("before");
	return new Function1<V,R>() {
		@Override
		public R apply(V v) {
			return after.apply(before.apply(v));
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:34,代码来源:FunctionExtensions.java

示例13: andThen

import org.eclipse.xtext.xbase.lib.Functions.Function1; //导入方法依赖的package包/类
/**
 * Returns a composed function that first applies the {@code before}
 * function to its input, and then applies the {@code after} function to the result.
 * If evaluation of either function throws an exception, it is relayed to
 * the caller of the composed function.
 *
 * @param <V1> the type of the first parameter to the {@code before} function, and to the composed function
 * @param <V2> the type of the second parameter to the {@code before} function, and to the composed function
 * @param <T> the type of output of the {@code before} function, and input to the {@code after} function
 * @param <R> the type of output to the {@code after} function, and to the composed function
 * @param before the function to apply before the {@code after} function is applied
 * @param after the function to apply after the {@code before} function is applied
 * @return a composed function that first applies the {@code before}
 * function and then applies the {@code after} function
 * @throws NullPointerException if {@code before} or {@code after} is null
 *
 * @see #compose(Function1, Function1)
 * @since 2.9
 */
public static <V1,V2,T,R> Function2<V1, V2, R> andThen(final Function2<? super V1,? super V2, ? extends T> before, final Function1<? super T, ? extends R> after) {
	if (after == null)
		throw new NullPointerException("after");
	if (before == null)
		throw new NullPointerException("before");
	return new Function2<V1, V2, R>() {
		@Override
		public R apply(V1 v1, V2 v2) {
			return after.apply(before.apply(v1, v2));
		}
	};
}
 
开发者ID:eclipse,项目名称:xtext-lib,代码行数:32,代码来源:FunctionExtensions.java


注:本文中的org.eclipse.xtext.xbase.lib.Functions.Function1.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。