package de.lmu.ifi.dbs.elki.datasource.bundle;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
import java.util.ArrayList;
import java.util.List;
import de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation;
import de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs;
import de.lmu.ifi.dbs.elki.database.ids.DBIDUtil;
import de.lmu.ifi.dbs.elki.database.ids.DBIDVar;
import de.lmu.ifi.dbs.elki.logging.Logging;
import de.lmu.ifi.dbs.elki.logging.LoggingUtil;
import de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException;
/**
* This class represents a set of "packaged" objects, which is a transfer
* container for objects e.g. from parsers to a database. It contains the object
* with multiple representations outside of any index structure.
*
* @author Erich Schubert
*
* @apiviz.landmark
*/
public class MultipleObjectsBundle implements ObjectBundle {
/**
* Class logger.
*/
private static final Logging LOG = Logging.getLogger(MultipleObjectsBundle.class);
/**
* Storing the meta data.
*/
private BundleMeta meta;
/**
* Storing the real contents.
*/
private List> columns;
/**
* DBIDs for these objects, but may be null.
*/
private ArrayDBIDs ids;
/**
* Constructor.
*/
public MultipleObjectsBundle() {
this.meta = new BundleMeta();
this.columns = new ArrayList<>();
}
@Override
public BundleMeta meta() {
return meta;
}
@Override
public SimpleTypeInformation> meta(int i) {
return meta.get(i);
}
@Override
public int metaLength() {
return meta.size();
}
@Override
public Object data(int onum, int rnum) {
return columns.get(rnum).get(onum);
}
@Override
public boolean assignDBID(int onum, DBIDVar var) {
if(ids == null) {
var.unset();
return false;
}
ids.assignVar(onum, var);
return true;
}
@Override
public int dataLength() {
return (ids != null) ? ids.size() : (columns.size() == 0) ? 0 : columns.get(0).size();
}
/**
* Append a new record to the data set. Pay attention to having the right
* number of values!
*
* @param data Data to append
*/
public void appendSimple(Object... data) {
if(data.length != meta.size()) {
throw new AbortException("Invalid number of attributes in 'append'.");
}
for(int i = 0; i < data.length; i++) {
@SuppressWarnings("unchecked")
final List