本文整理汇总了Java中org.apache.gora.persistency.ListGenericArray类的典型用法代码示例。如果您正苦于以下问题:Java ListGenericArray类的具体用法?Java ListGenericArray怎么用?Java ListGenericArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListGenericArray类属于org.apache.gora.persistency包,在下文中一共展示了ListGenericArray类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newArray
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
/** Called to create new array instances. Subclasses may override to use a
* different array implementation. By default, this returns a
* GenericData.Array instance.*/
@Override
@SuppressWarnings("rawtypes")
protected Object newArray(Object old, int size, Schema schema) {
if (old instanceof ListGenericArray) {
((GenericArray) old).clear();
return old;
} else return new ListGenericArray(size, schema);
}
示例2: testHashCode
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
@Test
public void testHashCode() {
ListGenericArray array = new ListGenericArray(Schema.create(Schema.Type.STRING));
boolean stackOverflowError = false;
array.add(new Utf8("array test"));
try {
int hashCode = array.hashCode();
}
catch (StackOverflowError e) {
stackOverflowError = true;
}
Assert.assertFalse(stackOverflowError);
}
示例3: testCompareTo
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
@Test
public void testCompareTo() {
ListGenericArray array = new ListGenericArray(Schema.create(Schema.Type.STRING));
boolean stackOverflowError = false;
array.add(new Utf8("array comparison test"));
try {
int compareTo = array.compareTo(array);
} catch (StackOverflowError e) {
stackOverflowError = true;
}
Assert.assertFalse(stackOverflowError);
}
示例4: getType
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
public static Type getType(Class<?> clazz) {
if (clazz.equals(Utf8.class)) {
return Type.STRING;
} else if (clazz.equals(Boolean.class) || clazz.equals(boolean.class)) {
return Type.BOOLEAN;
} else if (clazz.equals(ByteBuffer.class)) {
return Type.BYTES;
} else if (clazz.equals(Double.class) || clazz.equals(double.class)) {
return Type.DOUBLE;
} else if (clazz.equals(Float.class) || clazz.equals(float.class)) {
return Type.FLOAT;
} else if (clazz.equals(Integer.class) || clazz.equals(int.class)) {
return Type.INT;
} else if (clazz.equals(Long.class) || clazz.equals(long.class)) {
return Type.LONG;
} else if (clazz.equals(ListGenericArray.class)) {
return Type.ARRAY;
} else if (clazz.equals(StatefulHashMap.class)) {
return Type.MAP;
} else if (clazz.equals(Persistent.class)) {
return Type.RECORD;
} else if (clazz.getSuperclass().equals(SpecificFixed.class)) {
return Type.FIXED;
} else {
return null;
}
}
示例5: getClass
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
public static Class getClass(Type type) {
if (type == Type.STRING) {
return Utf8.class;
} else if (type == Type.BOOLEAN) {
return Boolean.class;
} else if (type == Type.BYTES) {
return ByteBuffer.class;
} else if (type == Type.DOUBLE) {
return Double.class;
} else if (type == Type.FLOAT) {
return Float.class;
} else if (type == Type.INT) {
return Integer.class;
} else if (type == Type.LONG) {
return Long.class;
} else if (type == Type.ARRAY) {
return ListGenericArray.class;
} else if (type == Type.MAP) {
return StatefulHashMap.class;
} else if (type == Type.RECORD) {
return Persistent.class;
} else if (type == Type.FIXED) {
// return SpecificFixed.class;
return null;
} else {
return null;
}
}
示例6: fromByteBuffer
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
@Override
public GenericArray<T> fromByteBuffer(ByteBuffer byteBuffer) {
if (byteBuffer == null) {
return null;
}
GenericArray<T> array = new ListGenericArray<T>(elementSchema);
int i = 0;
while (true) {
T element = null;
try {
if (size > 0) {
element = elementSerializer.fromByteBuffer(byteBuffer);
}
else {
int n = IntegerSerializer.get().fromByteBuffer(byteBuffer);
byte[] bytes = new byte[n];
byteBuffer.get(bytes, 0, n);
element = elementSerializer.fromByteBuffer( BytesArraySerializer.get().toByteBuffer(bytes) );
}
} catch (BufferUnderflowException e) {
break;
}
if (element == null) {
break;
}
array.add(element);
}
return array;
}
示例7: WebPage
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
public WebPage(StateManager stateManager) {
super(stateManager);
parsedContent = new ListGenericArray<Utf8>(getSchema().getField("parsedContent").schema());
outlinks = new StatefulHashMap<Utf8,Utf8>();
}
示例8: clear
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public void clear() {
List<Field> fields = getSchema().getFields();
for(int i=0; i<getFields().length; i++) {
switch(fields.get(i).schema().getType()) {
case MAP:
if(get(i) != null) {
if (get(i) instanceof StatefulHashMap) {
((StatefulHashMap)get(i)).reuse();
} else {
((Map)get(i)).clear();
}
}
break;
case ARRAY:
if(get(i) != null) {
if(get(i) instanceof ListGenericArray) {
((ListGenericArray)get(i)).clear();
} else {
put(i, new ListGenericArray(fields.get(i).schema()));
}
}
break;
case RECORD :
Persistent field = ((Persistent)get(i));
if(field != null) field.clear();
break;
case BOOLEAN: put(i, false); break;
case INT : put(i, 0); break;
case DOUBLE : put(i, 0d); break;
case FLOAT : put(i, 0f); break;
case LONG : put(i, 0l); break;
case NULL : break;
default : put(i, null); break;
}
}
clearDirty();
clearReadable();
}
示例9: getElementType
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
public static Type getElementType(ListGenericArray array) {
return getElementSchema(array).getType();
}
示例10: put
import org.apache.gora.persistency.ListGenericArray; //导入依赖的package包/类
/**
* Duplicate instance to keep all the objects in memory till flushing.
* @see org.apache.gora.store.DataStore#put(java.lang.Object, org.apache.gora.persistency.Persistent)
*/
@Override
public void put(K key, T value) {
T p = (T) value.newInstance(new StateManagerImpl());
Schema schema = value.getSchema();
for (Field field: schema.getFields()) {
int fieldPos = field.pos();
if (value.isDirty(fieldPos)) {
Object fieldValue = value.get(fieldPos);
// check if field has a nested structure (array, map, or record)
Schema fieldSchema = field.schema();
Type type = fieldSchema.getType();
switch(type) {
case RECORD:
PersistentBase persistent = (PersistentBase) fieldValue;
PersistentBase newRecord = (PersistentBase) persistent.newInstance(new StateManagerImpl());
for (Field member: fieldSchema.getFields()) {
newRecord.put(member.pos(), persistent.get(member.pos()));
}
fieldValue = newRecord;
break;
case MAP:
StatefulHashMap map = (StatefulHashMap) fieldValue;
StatefulHashMap newMap = new StatefulHashMap();
for (Object mapKey : map.keySet()) {
newMap.put(mapKey, map.get(mapKey));
newMap.putState(mapKey, map.getState(mapKey));
}
fieldValue = newMap;
break;
case ARRAY:
GenericArray array = (GenericArray) fieldValue;
ListGenericArray newArray = new ListGenericArray(fieldSchema.getElementType());
Iterator iter = array.iterator();
while (iter.hasNext()) {
newArray.add(iter.next());
}
fieldValue = newArray;
break;
case UNION:
// storing the union selected schema, the actual value will be stored as soon as getting out of here
// TODO determine which schema we are using: int schemaPos = getUnionSchema(fieldValue,fieldSchema);
// and save it p.put( p.getFieldIndex(field.name() + CassandraStore.UNION_COL_SUFIX), schemaPos);
break;
}
p.put(fieldPos, fieldValue);
}
}
// this performs a structural modification of the map
this.buffer.put(key, p);
}