org.apache.cassandra.db.UnsortedColumns Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.db;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.db.filter.ColumnSlice;
import org.apache.cassandra.utils.Allocator;
/**
* A ColumnFamily that allows inserting in any order, even unsorted.
*
* Operations that require sorting (getSortedColumns) or that cannot be efficient without it
* (replace, getColumn, etc.) are not supported.
*/
public class UnsortedColumns extends AbstractThreadUnsafeSortedColumns
{
private final ArrayList columns;
public static final Factory factory = new Factory()
{
public UnsortedColumns create(CFMetaData metadata, boolean insertReversed)
{
assert !insertReversed;
return new UnsortedColumns(metadata);
}
};
private UnsortedColumns(CFMetaData metadata)
{
this(metadata, new ArrayList());
}
private UnsortedColumns(CFMetaData metadata, ArrayList columns)
{
super(metadata);
this.columns = columns;
}
public Factory getFactory()
{
return factory;
}
public ColumnFamily cloneMe()
{
return new UnsortedColumns(metadata, new ArrayList(columns));
}
public boolean isInsertReversed()
{
return false;
}
public void clear()
{
columns.clear();
}
public void addColumn(Column column, Allocator allocator)
{
columns.add(column);
}
public void addAll(ColumnFamily cm, Allocator allocator, Function transformation)
{
delete(cm.deletionInfo());
for (Column column : cm)
addColumn(column);
}
public Iterator iterator()
{
return columns.iterator();
}
public boolean replace(Column oldColumn, Column newColumn)
{
throw new UnsupportedOperationException();
}
public Column getColumn(ByteBuffer name)
{
throw new UnsupportedOperationException();
}
public Iterable getColumnNames()
{
return Iterables.transform(columns, new Function()
{
public ByteBuffer apply(Column column)
{
return column.name;
}
});
}
public Collection getSortedColumns()
{
throw new UnsupportedOperationException();
}
public Collection getReverseSortedColumns()
{
throw new UnsupportedOperationException();
}
public int getColumnCount()
{
return columns.size();
}
public Iterator iterator(ColumnSlice[] slices)
{
throw new UnsupportedOperationException();
}
public Iterator reverseIterator(ColumnSlice[] slices)
{
throw new UnsupportedOperationException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy