Java Code Examples for org.eclipse.xtext.xbase.lib.IterableExtensions#fold()

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#fold() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HoverService.java    From xtext-web with Eclipse Public License 2.0 6 votes vote down vote up
protected String addIconDivs(IImageDescription it, String nameHtml) {
	if (it instanceof SimpleImageDescription) {
		return surroundWithDiv(nameHtml, ((SimpleImageDescription) it).getImageID() + "-icon");
	} else if (it instanceof AlternativeImageDescription) {
		List<String> strings = Lists
				.transform(((AlternativeImageDescription) it).getImageIDs(), (String s) -> s + "-icon");
		return surroundWithDiv(nameHtml,
				strings.toArray(new String[strings.size()]));
	} else if (it instanceof DecoratedImageDescription) {
		return IterableExtensions.fold(
				Iterables.concat(((DecoratedImageDescription) it).getDecorators(),
						Lists.newArrayList(((DecoratedImageDescription) it).getBaseImage())),
				nameHtml, (String $0, IImageDescription $1) -> addIconDivs($1, $0));
	}
	return null;
}
 
Example 2
Source File: Solution_023.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isAbundant(final int input) {
  final int sqrt = Double.valueOf(Math.floor(Math.sqrt(input))).intValue();
  final Function1<Integer, Boolean> _function = (Integer div) -> {
    return Boolean.valueOf((((div).intValue() != input) && ((input % (div).intValue()) == 0)));
  };
  final Function2<Integer, Integer, Integer> _function_1 = (Integer i1, Integer i2) -> {
    int _xblockexpression = (int) 0;
    {
      final int other = (input / (i2).intValue());
      int _xifexpression = (int) 0;
      if (((other != (i2).intValue()) && (other != input))) {
        _xifexpression = (((i1).intValue() + (i2).intValue()) + other);
      } else {
        _xifexpression = ((i1).intValue() + (i2).intValue());
      }
      _xblockexpression = _xifexpression;
    }
    return Integer.valueOf(_xblockexpression);
  };
  final Integer sumOfDivisors = IterableExtensions.<Integer, Integer>fold(IterableExtensions.<Integer>filter(new IntegerRange(2, sqrt), _function), Integer.valueOf(1), _function_1);
  return ((sumOfDivisors).intValue() > input);
}
 
Example 3
Source File: Solution_021.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static Integer sumOfDivisors(final int input) {
  Integer _xblockexpression = null;
  {
    final int sqrt = Double.valueOf(Math.floor(Math.sqrt(input))).intValue();
    final Function1<Integer, Boolean> _function = (Integer div) -> {
      return Boolean.valueOf(((input % (div).intValue()) == 0));
    };
    final Function2<Integer, Integer, Integer> _function_1 = (Integer i1, Integer i2) -> {
      int _xblockexpression_1 = (int) 0;
      {
        final int other = (input / (i2).intValue());
        int _xifexpression = (int) 0;
        if ((other != (i2).intValue())) {
          _xifexpression = (((i1).intValue() + (i2).intValue()) + other);
        } else {
          _xifexpression = ((i1).intValue() + (i2).intValue());
        }
        _xblockexpression_1 = _xifexpression;
      }
      return Integer.valueOf(_xblockexpression_1);
    };
    _xblockexpression = IterableExtensions.<Integer, Integer>fold(IterableExtensions.<Integer>filter(new IntegerRange(2, sqrt), _function), Integer.valueOf(1), _function_1);
  }
  return _xblockexpression;
}
 
Example 4
Source File: TemplateLiteralImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
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();
}
 
Example 5
Source File: HiddenLeafs.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public int getLenght() {
	return IterableExtensions.fold(leafs, 0, (x, i) -> {
		int length = 0;
		if (i.getNode() != null) {
			length = i.getNode().getLength();
		}
		return x + length;
	});
}
 
Example 6
Source File: Solution_006.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
  final Function2<Integer, Integer, Integer> _function = (Integer i1, Integer i2) -> {
    return Integer.valueOf(((i1).intValue() + (i2).intValue()));
  };
  Integer result = IterableExtensions.<Integer>reduce(new IntegerRange(1, 100), _function);
  result = Integer.valueOf(((result).intValue() * (result).intValue()));
  final Function2<Integer, Integer, Integer> _function_1 = (Integer r, Integer i) -> {
    return Integer.valueOf(((r).intValue() - ((i).intValue() * (i).intValue())));
  };
  result = IterableExtensions.<Integer, Integer>fold(new IntegerRange(1, 100), result, _function_1);
  InputOutput.<Integer>println(result);
}
 
Example 7
Source File: HiddenLeafs.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public int getNewLines() {
	return IterableExtensions.fold(leafs, 0, (x, i) -> x + i.getNewLines());
}
 
Example 8
Source File: HiddenLeafs.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public int getNewLinesInComments() {
	return IterableExtensions.fold(Iterables.filter(leafs, CommentInfo.class), 0,
			(x, i) -> x + i.getNewLines());
}
 
Example 9
Source File: DelegateProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public TypeReference replace(final TypeReference target, final Map<? extends TypeReference, ? extends TypeReference> mappings) {
  final Function2<TypeReference, Map.Entry<? extends TypeReference, ? extends TypeReference>, TypeReference> _function = (TypeReference result, Map.Entry<? extends TypeReference, ? extends TypeReference> mapping) -> {
    return this.replace(result, mapping.getKey(), mapping.getValue());
  };
  return IterableExtensions.fold(mappings.entrySet(), target, _function);
}
 
Example 10
Source File: GeneratorNodeProcessor.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected int recalculateIndentLength() {
	return indentLength = IterableExtensions.fold(getCurrentIndents(), 0,
			($0, $1) -> $0.intValue() + $1.getIndentationString().length());
}