![JAR search and dependency download from the Maven repository](/logo.png)
com.netflix.astyanax.thrift.model.ThriftColumnListImpl Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright 2011 Netflix
*
* Licensed 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 com.netflix.astyanax.thrift.model;
import java.util.Collection;
import java.util.Iterator;
import java.util.HashMap;
import java.util.List;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.netflix.astyanax.Serializer;
import com.netflix.astyanax.model.AbstractColumnList;
import com.netflix.astyanax.model.Column;
/**
* Wrapper for a simple list of columns where each column has a scalar value.
*
* @author elandau
*
* @param
*/
public class ThriftColumnListImpl extends AbstractColumnList {
private final List columns;
private HashMap lookup;
private final Serializer colSer;
public ThriftColumnListImpl(List columns, Serializer colSer) {
Preconditions.checkArgument(columns != null, "Columns must not be null");
Preconditions.checkArgument(colSer != null, "Serializer must not be null");
this.colSer = colSer;
this.columns = columns;
}
@Override
public Iterator> iterator() {
class IteratorImpl implements Iterator> {
Iterator base;
public IteratorImpl(Iterator base) {
this.base = base;
}
@Override
public boolean hasNext() {
return base.hasNext();
}
@Override
public Column next() {
org.apache.cassandra.thrift.Column c = base.next();
return new ThriftColumnImpl(colSer.fromBytes(c.getName()), c);
}
@Override
public void remove() {
throw new UnsupportedOperationException("Iterator is immutable");
}
}
return new IteratorImpl(columns.iterator());
}
@Override
public Column getColumnByName(C columnName) {
constructColumnMap();
org.apache.cassandra.thrift.Column c = lookup.get(columnName);
if (c == null) {
return null;
}
return new ThriftColumnImpl(colSer.fromBytes(c.getName()), c);
}
private void constructColumnMap() {
if (lookup == null) {
lookup = Maps.newHashMap();;
for (org.apache.cassandra.thrift.Column column : columns) {
lookup.put(colSer.fromBytes(column.getName()), column);
}
}
}
@Override
public Column getColumnByIndex(int idx) {
org.apache.cassandra.thrift.Column c = columns.get(idx);
return new ThriftColumnImpl(colSer.fromBytes(c.getName()), c);
}
public C getNameByIndex(int idx) {
org.apache.cassandra.thrift.Column column = columns.get(idx);
return colSer.fromBytes(column.getName());
}
@Override
public Column getSuperColumn(C columnName, Serializer colSer) {
throw new UnsupportedOperationException();
}
@Override
public Column getSuperColumn(int idx, Serializer colSer) {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
return columns.isEmpty();
}
@Override
public int size() {
return columns.size();
}
@Override
public boolean isSuperColumn() {
return false;
}
@Override
public Collection getColumnNames() {
constructColumnMap();
return lookup.keySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy