All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swingtree.ArrayBasedComboModel Maven / Gradle / Ivy

package swingtree;

import org.jspecify.annotations.Nullable;
import sprouts.Var;

import java.util.Objects;

final class ArrayBasedComboModel extends AbstractComboModel
{
	private final E[] _items;


	ArrayBasedComboModel(E[] items) {
		this(Var.ofNullable(_findCommonType( items ), null), items);
	}

	ArrayBasedComboModel(Var selection, E @Nullable[] items) {
		super(selection);
		_items = Objects.requireNonNull(items);
		_selectedIndex = _indexOf(_selectedItem.orElseNull());
	}


	@Override
	public AbstractComboModel withVar( Var newVar ) {
		return new ArrayBasedComboModel<>(newVar, _items);
	}

	@Override protected void setAt( int index, @Nullable E element ) { _items[index] = element; }
	@Override public int getSize() { return _items.length; }
	@Override public @Nullable E getElementAt( int index ) { return _items[index]; }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy