| /*=============================================================================# |
| # Copyright (c) 2016, 2019 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.debug.core.model; |
| |
| import java.util.function.Consumer; |
| |
| import org.eclipse.statet.jcommons.lang.NonNullByDefault; |
| import org.eclipse.statet.jcommons.lang.Nullable; |
| |
| import org.eclipse.statet.r.debug.core.IRVariable; |
| |
| |
| @NonNullByDefault |
| public class RElementVariableCompactStore { |
| |
| |
| private final @Nullable RElementVariable[] array; |
| |
| |
| public RElementVariableCompactStore(final int length) { |
| this.array= new @Nullable RElementVariable[length]; |
| } |
| |
| |
| public void set(final int idx, final RElementVariable value) { |
| this.array[idx]= value; |
| } |
| |
| public @Nullable RElementVariable get(final int idx) { |
| return this.array[idx]; |
| } |
| |
| public @Nullable RElementVariable clear(final int idx) { |
| final RElementVariable value= this.array[idx]; |
| this.array[idx]= null; |
| return value; |
| } |
| |
| public void forEachSet(final Consumer<RElementVariable> action) { |
| for (int idx= 0; idx < this.array.length; idx++) { |
| final RElementVariable value= this.array[idx]; |
| if (value != null) { |
| action.accept(value); |
| } |
| } |
| } |
| |
| public void toArray(final @Nullable IRVariable[] to, final int idx) { |
| System.arraycopy(this.array, 0, to, idx, this.array.length); |
| } |
| |
| } |