Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2005-2008 Whirlwind Match Limited. All rights reserved. This is open source software; you can use, redistribute and/or modify it under the terms of the Open Software Licence v 3.0 as published by the Open Source Initiative. You should have received a copy of the Open Software Licence along with this application. if not, contact the Open Source Initiative (www.opensource.org) /
package org.fuzzydb.attrs.layout;
public class EnumMultiValueCodec extends LayoutAttrCodec<IAttribute> {
	private static final int ENUM_VALUES_LENGTH = (. + 7) / 32;
	private static EnumMultiValueCodec instance = null;
	public static synchronized EnumMultiValueCodec getInstance() {
		if ( == null) {
		}
		return ;
	}
	public void encode(LayoutAttrMap<IAttributemapint attrIdObject value) {
		int index = map.getIndexForIntsWrite(attrId);
		EnumMultipleValue enumValue = (EnumMultipleValue)value;
		if ( == 1){
			int bits = (intenumValue.getBitSet().getWord();
			map.getInts()[index] = bits;
else if ( == 2){
			long bitfield = enumValue.getBitSet().getWord();
			map.getInts()[index] = (int) (bitfield & 0xffffffffL); // FIXME: I don't trust the sign bits here needs testing
			map.getInts()[index+1] = (int) (bitfield >>> 32);
else {
			throw new RuntimeException"Unsupported Enum size");
		}
	}
	public IAttribute getDecoded(LayoutAttrMap<IAttributemapint attrId) {
		int index = map.getIndexQuick(attrId);
		long vals = getValues(map.getInts(), index);
		return new EnumMultipleValueattrId, (short)-1, vals );
	}
	public static long getValues(int[] intsint index) {
		if ( == 1){
			return ints[index];
else if ( == 2){
			long word = ints[index+1];
			word = (word << 32) | ints[index];
			return word;
else {
			throw new RuntimeException"Unsupported Enum size");
		}
	}
	protected boolean consistentForInternal(LayoutAttrMap<IAttributemapint attrIdIAttributeConstraint constraint) {
		// get the bit field
		int index = map.getIndexQuick(attrId);
		long vals = getValues(map.getInts(), index);
		// test against constraint
		if (constraint instanceof MultiEnumReverseNodeSelector) {
			return emc.consistent(vals);
		}
		return emc.consistent(vals);
	}
New to GrepCode? Check out our FAQ X