| /*=============================================================================# |
| # Copyright (c) 2008, 2020 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.r.core.sourcemodel; |
| |
| import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.List; |
| |
| import org.eclipse.statet.ltk.model.core.elements.IModelElement; |
| import org.eclipse.statet.r.core.model.IRLangSourceElement; |
| |
| |
| public class RSourceElements { |
| |
| static final List<? extends IRLangSourceElement> NO_R_SOURCE_CHILDREN= Collections.emptyList(); |
| |
| static final List<? extends IRLangSourceElement> getChildren(final List<? extends IRLangSourceElement> children, final IModelElement.Filter filter) { |
| if (filter == null) { |
| return children; |
| } |
| else { |
| final ArrayList<IRLangSourceElement> filtered= new ArrayList<>(children.size()); |
| for (final IRLangSourceElement child : children) { |
| if (filter.include(child)) { |
| filtered.add(child); |
| } |
| } |
| return filtered; |
| } |
| } |
| |
| static final boolean hasChildren(final List<? extends IRLangSourceElement> children, final IModelElement.Filter filter) { |
| if (filter == null) { |
| return (!children.isEmpty()); |
| } |
| else { |
| for (final IRLangSourceElement child : children) { |
| if (filter.include(child)) { |
| return true; |
| } |
| } |
| return false; |
| } |
| } |
| |
| } |