/* [Signature("(LGraph;Ljava/lang/Iterable<Ljava/lang/Integer;>;)V")]*/ private void bfs(Graph graph, Iterable iterable) { Queue queue = new Queue(); Iterator iterator = iterable.iterator(); while (iterator.hasNext()) { int num = ((Integer)iterator.next()).intValue(); this.marked[num] = true; this.distTo[num] = 0; queue.enqueue(Integer.valueOf(num)); } while (!queue.isEmpty()) { int num2 = ((Integer)queue.dequeue()).intValue(); Iterator iterator2 = graph.adj(num2).iterator(); while (iterator2.hasNext()) { int num3 = ((Integer)iterator2.next()).intValue(); if (!this.marked[num3]) { this.edgeTo[num3] = num2; this.distTo[num3] = this.distTo[num2] + 1; this.marked[num3] = true; queue.enqueue(Integer.valueOf(num3)); } } } }
void TryGetNext() { if (Iterator == null) { Iterator = Source.iterator(); } while (true) { var hasNext = Iterator.hasNext(); if (!hasNext) { OnNoMoreNext(); if (IsYieldBreak) { break; } else { throw new RuntimeException("MyIteratorException"); } } var item = Iterator.next(); Process(item); if (IsYieldReturn) { break; } if (IsYieldBreak) { break; } } }
public static void forEach(Iterable @this, java.util.function.Consumer consumer) { java.util.Iterator i = @this.iterator(); while (i.hasNext()) { consumer.accept(i.next()); } }
public static IEnumerable <T> AsEnumerable <T>(this Iterable iterable) { var iterator = iterable.iterator(); while (iterator.hasNext()) { yield return((T)iterator.next()); } }
internal static IEnumerable <T> IterableToEnumerable <T>(Iterable <T> iterable) { Iterator <T> iterator = iterable.iterator(); while (iterator.hasNext()) { yield return(iterator.next()); } }
public static IEnumerable ToEnumerable(Iterable iterable) { var iterator = iterable.iterator(); while (iterator.hasNext()) { yield return(iterator.next()); } }
public static IEnumerable <object> ToSeq(this Iterable iterable) { var iterator = iterable.iterator(); while (iterator.hasNext()) { yield return(iterator.next()); } }
public virtual bool matchesSafely(Iterable collection) { Iterator iterator = collection.iterator(); while (iterator.hasNext()) { if (this.elementMatcher.matches(iterator.next())) return true; } return false; }
internal static Optional <T> getFirst <T>(Iterable <T> iterable) { var iterator = iterable.iterator(); if (iterator.hasNext()) { return(Optional.of(iterator.next())); } else { return(Optional.empty <T>()); } }
internal static T getFirst <T>(Iterable <T> iterable, T defaultValue) { var iterator = iterable.iterator(); if (iterator.hasNext()) { return(iterator.next()); } else { return(defaultValue); } }
/* [Signature("(LDigraph;Ljava/lang/Iterable<Ljava/lang/Integer;>;)V")]*/ public DirectedDFS(Digraph d, Iterable i) { this.marked = new bool[d.V()]; Iterator iterator = i.iterator(); while (iterator.hasNext()) { int num = ((Integer)iterator.next()).intValue(); if (!this.marked[num]) { this.dfs(d, num); } } }
internal static Optional <T> tryFind <T>(Iterable <T> iterable, Predicate <T> predicate) { var iterator = iterable.iterator(); while (iterator.hasNext()) { T value = iterator.next(); if (predicate.test(value)) { return(new Some <T>(value)); } } return(None <T> .Instance); }
public virtual void setWords(Iterable words) { this.tokens.clear(); Iterator iterator = words.iterator(); while (iterator.hasNext()) { string text = (string)iterator.next(); if (!String.instancehelper_isEmpty(text)) { this.tokens.add(text); } } this.createGrammar(); this.postProcessGrammar(); }
internal static OptionalInt findIndex <T>(Iterable <T> iterable, Predicate <T> predicate) { var iterator = iterable.iterator(); int index = 0; while (iterator.hasNext()) { T value = iterator.next(); if (predicate.test(value)) { return(new SomeInt(index)); } index++; } return(NoneInt.Instance); }
static void declareGenericTypeBindings(GenericParameterBindings genericsScope, Iterable <TypeInfo> keys, Iterable <TypeInfo> values) { if (keys.count() != values.count()) { throw new IllegalStateException(); } var it1 = keys.iterator(); var it2 = values.iterator(); while (it1.hasNext()) { var t1 = it1.next(); var t2 = it2.next(); if (t1.IsGenericParameter) { genericsScope.declareBinding(t1, t2); } } }
internal static Optional <T> tryGetLast <T>(Iterable <T> iterable) where T : class { var hasElement = false; T last = null; var iterator = iterable.iterator(); while (iterator.hasNext()) { hasElement = true; last = iterator.next(); } if (hasElement) { return(Optional.of(last)); } else { return(Optional.empty <T>()); } }
private boolean hasNoMatches(Iterable<PhoneNumberMatch> iterable) { return !iterable.iterator().hasNext(); }
MethodInfo resolveMethod(Iterable<MethodInfo> methods, Iterable<ExpressionNode> arguments, TypeInfo returnType, bool extensionMethods) { var candidates = new ArrayList<CandidateMethodInfo>(); var hasLambda = false; foreach (var method in methods) { var parameterCount = method.Parameters.count(); var argumentCount = arguments.count(); if (method.IsVarargs) { if (argumentCount < parameterCount - 1) { continue; } } else if (argumentCount != parameterCount) { continue; } var fixedArgumentCount = (method.IsVarargs) ? parameterCount - 1 : parameterCount; var isCompatible = true; var parameterTypes = new TypeInfo[argumentCount]; var expandedForm = method.IsVarargs; if (!method.IsClosed) { var typeVariableInfos = new HashMap<TypeInfo, TypeVariableInfo>(); foreach (var t in method.GenericArguments) { typeVariableInfos[t] = new TypeVariableInfo(t); } // Inference phase 1 var nit = arguments.iterator(); var pit = method.Parameters.iterator(); bool closedParams = true; for (int i = 0; i < fixedArgumentCount; i++) { var paramType = pit.next().Type; var argNode = nit.next(); if (paramType.IsClosed) { if (!isArgumentCompatible(argNode, paramType)) { goto continueLookup; } } else { closedParams = false; if (argNode.ExpressionKind == ExpressionKind.Lambda) { hasLambda = true; makeExplicitParameterTypeInference(argNode, paramType, typeVariableInfos); } else { var argInfo = argNode.getUserData(typeof(ExpressionInfo)); if (argInfo == null) { continue; } if (BytecodeHelper.isDelegateType(paramType) || BytecodeHelper.isExpressionTreeType(paramType)) { makeExplicitParameterTypeInference(argNode, paramType, typeVariableInfos); } else { ValidationHelper.getType(context, argNode); makeOutputTypeInference(argNode, paramType, typeVariableInfos); } } } } if (method.IsVarargs) { var paramType = pit.next().Type.ElementType; var isClosedParam = paramType.IsClosed; var first = true; while (nit.hasNext()) { var argNode = nit.next(); if (isClosedParam) { switch (isVarargCompatible(argNode, paramType, first)) { case False: goto continueLookup; case True: expandedForm = false; if (nit.hasNext()) { goto continueLookup; } break; } } else { closedParams = false; if (argNode.ExpressionKind == ExpressionKind.Lambda) { hasLambda = true; makeExplicitParameterTypeInference(argNode, paramType, typeVariableInfos); } else { var argInfo = argNode.getUserData(typeof(ExpressionInfo)); if (argInfo == null) { continue; } if (BytecodeHelper.isDelegateType(paramType) || BytecodeHelper.isExpressionTreeType(paramType)) { makeExplicitParameterTypeInference(argNode, paramType, typeVariableInfos); } else if (paramType != ValidationHelper.getType(context, argNode) && !ValidationHelper.isAssignable(context, paramType, argNode) && first && ValidationHelper.isAssignable(context, paramType.getArrayType(), argNode)) { expandedForm = false; makeOutputTypeInference(argNode, paramType.getArrayType(), typeVariableInfos); } else { makeOutputTypeInference(argNode, paramType, typeVariableInfos); } } } first = false; } } if (closedParams && returnType != null && returnType != context.TypeSystem.VoidType) { makeLowerBoundInference(returnType, method.ReturnType, typeVariableInfos); } // Inference phase 2 for (;;) { var varFixed = false; var hasUnfixed = false; foreach (var e in typeVariableInfos.entrySet()) { if (e.Value.fixedType != null) { continue; } if (!containsUnfixedVariables(e.getValue().dependencies, typeVariableInfos)) { if (fixTypeVariable(e.getValue())) { varFixed = true; continue; } } hasUnfixed = true; } if (!varFixed) { varFixed = false; foreach (var e in typeVariableInfos.entrySet()) { if (e.Value.fixedType != null) { continue; } if (hasUnfixedTypeVariablesDependingOn(e.Key, typeVariableInfos, new HashSet<TypeInfo>())) { if (!e.Value.bounds.isEmpty()) { if (fixTypeVariable(e.Value)) { varFixed = true; continue; } } } hasUnfixed = true; } } if (!varFixed && hasUnfixed) { goto continueLookup; } if (!hasUnfixed) { break; } var mit = method.Parameters.iterator(); TypeInfo paramType = null; foreach (var e in arguments) { if (mit.hasNext()) { paramType = mit.next().Type; } if (e.ExpressionKind != ExpressionKind.Lambda) { if (!BytecodeHelper.isDelegateType(paramType) && !BytecodeHelper.isExpressionTreeType(paramType)) { continue; } } var m = getInvokeMethod(paramType); if (hasUnfixedTypeVariables(m.ReturnType, typeVariableInfos)) { hasUnfixed = false; foreach (var p in m.Parameters) { if (hasUnfixedTypeVariables(p.Type, typeVariableInfos)) { hasUnfixed = true; break; } } if (!hasUnfixed) { makeOutputTypeInference(e, paramType, typeVariableInfos); } } } } var typeArguments = new ArrayList<TypeInfo>(); foreach (var t in method.GenericArguments) { typeArguments.add(typeVariableInfos[t].fixedType); } method = context.TypeSystem.getGenericMethod(method, typeArguments); } var it1 = arguments.iterator(); var it2 = method.Parameters.iterator(); int i; for (i = 0; i < fixedArgumentCount; i++) { var argNode = it1.next(); var paramType = it2.next().Type; parameterTypes[i] = paramType; if (!isArgumentCompatible(argNode, paramType)) { isCompatible = false; break; } else if (argNode.ExpressionKind == ExpressionKind.Lambda) { hasLambda = true; } } if (isCompatible && method.IsVarargs) { var paramType = it2.next().Type.ElementType; var first = true; while (isCompatible && it1.hasNext()) { var argNode = it1.next(); parameterTypes[i++] = paramType; switch (isVarargCompatible(argNode, paramType, first)) { case False: isCompatible = false; break; case True: expandedForm = false; if (it1.hasNext()) { isCompatible = false; break; } else if (argNode.ExpressionKind == ExpressionKind.Lambda) { hasLambda = true; } break; } first = false; } } if (isCompatible) { candidates.add(new CandidateMethodInfo(method, parameterTypes, arguments, expandedForm)); } continueLookup: ; } if (candidates.size() == 0) { return null; } CandidateMethodInfo result; if (candidates.size() > 1) { result = resolveOverloading(candidates, extensionMethods); if (result == null) { return null; } } else { result = candidates[0]; } if (hasLambda) { int parameterCount = result.method.Parameters.count(); int argumentCount = arguments.count(); int fixedArgumentCount = (result.method.IsVarargs) ? parameterCount - 1 : parameterCount; var parameterTypes = new TypeInfo[argumentCount]; var pit = result.method.getParameters().iterator(); int i; for (i = 0; i < fixedArgumentCount; i++) { parameterTypes[i] = pit.next().Type; } if (result.method.IsVarargs) { if (result.expandedForm) { var paramType = pit.next().Type.ElementType; while (i < argumentCount) { parameterTypes[i++] = paramType; } } else { parameterTypes[i] = pit.next().Type; } } i = 0; foreach (var argNode in arguments) { expressionValidator.handleExpression(argNode, parameterTypes[i], true); i++; } } return result.method; }
public virtual Description appendValueList(string start, string separator, string end, Iterable values) { return this.appendValueList(start, separator, end, values.iterator()); }
protected void drawMany(DrawContext dc, Iterable <Annotation> annotations, Layer layer) { if (dc == null) { String msg = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (dc.getVisibleSector() == null) { return; } SectorGeometryList geos = dc.getSurfaceGeometry(); //noinspection RedundantIfStatement if (geos == null) { return; } if (annotations == null) { String msg = Logging.getMessage("nullValue.AnnotationIterator"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (dc.isContinuous2DGlobe() && this.currentFrameTime != dc.getFrameTimeStamp()) { // Keep track of which annotations are added to the ordered renderable list so that they are not added // to that list more than once per frame. this.currentPickAnnotations.clear(); this.currentDrawAnnotations.clear(); this.currentFrameTime = dc.getFrameTimeStamp(); } Iterator <Annotation> iterator = annotations.iterator(); if (!iterator.hasNext()) { return; } double altitude = dc.getView().getEyePosition().getElevation(); while (iterator.hasNext()) { Annotation annotation = iterator.next(); if (!isAnnotationValid(annotation, true)) { continue; } if (!annotation.getAttributes().isVisible()) { continue; } // Do not draw the pick pass if not at pick point range; if (dc.isPickingMode() && !this.isAtPickRange(dc, annotation)) { continue; } if (altitude < annotation.getMinActiveAltitude() || altitude > annotation.getMaxActiveAltitude()) { continue; } if (dc.isContinuous2DGlobe() && annotation is ScreenAnnotation) { if (dc.isPickingMode() && this.currentPickAnnotations.contains(annotation)) { continue; } if (currentDrawAnnotations.contains(annotation)) { continue; } } // TODO: cull annotations that are beyond the horizon double eyeDistance = 1; if (annotation is Locatable) { // Determine Cartesian position from the surface geometry if the annotation is near the surface, // otherwise draw it from the globe. Vec4 annotationPoint = getAnnotationDrawPoint(dc, annotation); if (annotationPoint == null) { continue; } eyeDistance = annotation.isAlwaysOnTop() ? 0 : dc.getView().getEyePoint().distanceTo3(annotationPoint); } if (annotation is ScreenAnnotation) { Rectangle screenBounds = annotation.getBounds(dc); if (screenBounds != null && !dc.getView().getViewport().intersects(screenBounds)) { return; } } // The annotations aren't drawn here, but added to the ordered queue to be drawn back-to-front. dc.addOrderedRenderable(new OrderedAnnotation(annotation, layer, eyeDistance)); if (dc.isContinuous2DGlobe() && annotation is ScreenAnnotation) { if (dc.isPickingMode()) { this.currentPickAnnotations.add(annotation); } else { this.currentDrawAnnotations.add(annotation); } } } }