io.github.palexdev.mfxcore.utils.ColumnIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of materialfx-all Show documentation
Show all versions of materialfx-all Show documentation
Material Design/Modern components for JavaFX, now packed as a single Jar
/*
* Copyright (C) 2022 Parisi Alessandro - [email protected]
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX)
*
* MaterialFX is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of the License,
* or (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see .
*/
package io.github.palexdev.mfxcore.utils;
import io.github.palexdev.mfxcore.collections.Grid;
import java.util.Iterator;
import java.util.List;
/**
* Custom {@link Iterator} capable of iterating over a {@link Grid} structure per column.
* Internally uses a "cursor" to keep track of the current visiting column.
*/
public class ColumnIterator implements Iterator> {
//================================================================================
// Properties
//================================================================================
private final Grid grid;
private int cursor = 0;
//================================================================================
// Constructors
//================================================================================
public ColumnIterator(Grid grid) {
this.grid = grid;
}
//================================================================================
// Overridden Methods
//================================================================================
/**
* {@inheritDoc}
*
* @return whether the cursor is still lesser than {@link Grid#getColumnsNum()}
*/
@Override
public boolean hasNext() {
return cursor < grid.getColumnsNum();
}
/**
* @return the column at the current cursor value by using {@link Grid#getColumn(int)}
*/
@Override
public List next() {
List column = grid.getColumn(cursor);
cursor++;
return column;
}
/**
* Removes the column at the current cursor value by using {@link Grid#removeColumn(int)}.
*
* The removal is done only if {@link #hasNext()} is true.
*/
@Override
public void remove() {
if (hasNext()) grid.removeColumn(cursor);
}
}