com.datastax.data.dataset.DataSelector Maven / Gradle / Ivy
package com.datastax.data.dataset;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
public class DataSelector {
protected static final String DEFAULT_NAME_PREFIX = "DataSelector";
private static final NameGenerator NAMEGEN = new NameGenerator(DEFAULT_NAME_PREFIX);
private DataTable table;
private String name;
private BitSet indices = new BitSet(0);
private int[] helper = new int[1];
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public DataSelector(DataTable table) {
assert table != null;
this.table = table;
name = NAMEGEN.generateName(this);
if (table != null && table.getRowCount() > 0) {
setRowIndices(new int[]{0});
}
}
public DataTable getDataTable() {
return table;
}
public DataTable getTable() {
return table;
}
void removeFromTable() {
table = null;
}
public void setName(String name) {
if (this.name != name) {
assert name != null && !name.trim().equals("");
String oldName = this.name;
this.name = name;
pcs.firePropertyChange("name", oldName, name);
}
}
public String getName() {
return name;
}
public List getRowIndices() {
List results = new ArrayList(indices.cardinality());
int n=-1;
for(int i=0; i 0 ? indices.nextSetBit(0) : -1;
}
public void setRowIndices(int[] rowIndices) {
List oldIndices = getRowIndices();
indices.clear();
for (int index : rowIndices) {
indices.set(index);
}
pcs.firePropertyChange("rowIndices", oldIndices, getRowIndices());
}
public void setRowIndex(int index) {
assert index < table.getRowCount();
if (index >= 0) {
helper[0] = index;
setRowIndices(helper);
} else {
setRowIndices(new int[0]);
}
}
public void setRowIndex(DataRow row) {
assert row != null;
setRowIndices(new int[]{table.indexOfRow(row)});
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
}
public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
pcs.addPropertyChangeListener(property, listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
pcs.removePropertyChangeListener(propertyName, listener);
}
}