Search in sources :

Example 26 with DBIDVar

use of de.lmu.ifi.dbs.elki.database.ids.DBIDVar in project elki by elki-project.

the class MultipleObjectsBundle method fromStream.

/**
 * Convert an object stream to a bundle
 *
 * @param source Object stream
 * @return Static bundle
 */
public static MultipleObjectsBundle fromStream(BundleStreamSource source) {
    MultipleObjectsBundle bundle = new MultipleObjectsBundle();
    boolean stop = false;
    DBIDVar var = null;
    ArrayModifiableDBIDs ids = null;
    int size = 0;
    while (!stop) {
        BundleStreamSource.Event ev = source.nextEvent();
        switch(ev) {
            case END_OF_STREAM:
                stop = true;
                break;
            case META_CHANGED:
                BundleMeta smeta = source.getMeta();
                // rebuild bundle meta
                bundle.meta = new BundleMeta();
                for (int i = 0; i < bundle.columns.size(); i++) {
                    bundle.meta.add(smeta.get(i));
                }
                for (int i = bundle.metaLength(); i < smeta.size(); i++) {
                    List<Object> data = new ArrayList<>(bundle.dataLength() + 1);
                    bundle.appendColumn(smeta.get(i), data);
                }
                if (var == null && source.hasDBIDs()) {
                    var = DBIDUtil.newVar();
                    ids = DBIDUtil.newArray();
                }
                continue;
            case NEXT_OBJECT:
                if (var != null && source.assignDBID(var)) {
                    ids.add(var);
                }
                for (int i = 0; i < bundle.metaLength(); i++) {
                    @SuppressWarnings("unchecked") final List<Object> col = (List<Object>) bundle.columns.get(i);
                    col.add(source.data(i));
                }
                ++size;
                continue;
            default:
                LoggingUtil.warning("Unknown event: " + ev);
                continue;
        }
    }
    if (ids != null) {
        if (size != ids.size()) {
            LOG.warning("Not every object had an DBID - discarding DBIDs: " + size + " != " + ids.size());
        } else {
            bundle.setDBIDs(ids);
        }
    }
    return bundle;
}
Also used : DBIDVar(de.lmu.ifi.dbs.elki.database.ids.DBIDVar) ArrayList(java.util.ArrayList) ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DBIDVar (de.lmu.ifi.dbs.elki.database.ids.DBIDVar)26 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)13 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)12 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)7 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)6 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)6 DBIDRef (de.lmu.ifi.dbs.elki.database.ids.DBIDRef)5 ArrayList (java.util.ArrayList)5 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)4 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)4 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)3 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)3 Cluster (de.lmu.ifi.dbs.elki.data.Cluster)2 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)2 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)2 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)2 Pair (de.lmu.ifi.dbs.elki.utilities.pairs.Pair)2 List (java.util.List)2 ClusterModel (de.lmu.ifi.dbs.elki.data.model.ClusterModel)1 Model (de.lmu.ifi.dbs.elki.data.model.Model)1