private DataModelCounter() { super(); dataGroup = DataGroup.COUNTER; for (int i = 0; i < DataType.MAX_TYPES.getLocalIndex(); i++) if (DataType.getItem(i).getGroup().equals(dataGroup)) data.add(new DataListCounters(DataType.getItem(i))); }
@Override public void testTypeCast() throws Exception { final Object[] values = {null, "uuid'2aad615a-d8e1-11e2-b8ed-50e549c9b654'"}; final byte[][] expected = { null, new byte[] { (byte) 0x2a, (byte) 0xad, (byte) 0x61, (byte) 0x5a, (byte) 0xd8, (byte) 0xe1, (byte) 0x11, (byte) 0xe2, (byte) 0xb8, (byte) 0xed, (byte) 0x50, (byte) 0xe5, (byte) 0x49, (byte) 0xc9, (byte) 0xb6, (byte) 0x54 } }; assertEquals("actual vs expected count", values.length, expected.length); for (DataType element : TYPES) { for (int j = 0; j < values.length; j++) { byte[] actual = (byte[]) element.typeCast(values[j]); assertTrue("typecast " + j, Arrays.equals(expected[j], actual)); } } }
@Override public DataType visitFactor(@NotNull PythonParser.FactorContext ctx) { if (ctx.power() != null) { return visitPower(ctx.power()); } else if (ctx.factor() != null) { DataType type = visitFactor(ctx.factor()); if (type.isInteger()) { if (ctx.PLUS() != null) { return type; } else if (ctx.MINUS() != null) { mv.visitInsn(INEG); return type; } } else if (type.isBoolean()) { if (ctx.PLUS() != null) { return type; } else if (ctx.MINUS() != null) { mv.visitInsn(INEG); return PrimitiveType.INTEGER; } } else { if (ctx.PLUS() != null) { throw new CompileException( String.format("Doing %s with %s is making no sense!", ctx.PLUS().getText(), type)); } else if (ctx.MINUS() != null) { throw new CompileException( String.format("Doing %s with %s is making no sense!", ctx.MINUS().getText(), type)); } } } throw new CompileException( String.format( "Something gone wrong! Please write to [email protected] with example test.")); }
public void testCompareEqualsUuidAware() throws Exception { final Object[] values1 = {null, "uuid'2aad615a-d8e1-11e2-b8ed-50e549c9b654'"}; final byte[][] values2 = { null, new byte[] { (byte) 0x2a, (byte) 0xad, (byte) 0x61, (byte) 0x5a, (byte) 0xd8, (byte) 0xe1, (byte) 0x11, (byte) 0xe2, (byte) 0xb8, (byte) 0xed, (byte) 0x50, (byte) 0xe5, (byte) 0x49, (byte) 0xc9, (byte) 0xb6, (byte) 0x54 } }; assertEquals("values count", values1.length, values2.length); for (DataType element : TYPES) { for (int j = 0; j < values1.length; j++) { assertEquals("compare1 " + j, 0, element.compare(values1[j], values2[j])); assertEquals("compare2 " + j, 0, element.compare(values2[j], values1[j])); } } }
public BufferEvent(ByteBuffer buf) { wType = new WrappedObject(); wValue = new WrappedObject(); wType.type = buf.getInt(); wType.numel = buf.getInt(); wValue.type = buf.getInt(); wValue.numel = buf.getInt(); sample = buf.getInt(); offset = buf.getInt(); duration = buf.getInt(); int size = buf.getInt(); wType.array = DataType.getObject(wType.type, wType.numel, buf); if (wType.array != null) { wType.size = wType.numel * DataType.wordSize[wType.type]; } wValue.array = DataType.getObject(wValue.type, wValue.numel, buf); if (wValue.array != null) { wValue.size = wValue.numel * DataType.wordSize[wValue.type]; } size -= wType.size + wValue.size; if (size != 0) { buf.position(buf.position() + size); } }
public void testSetSqlValueWithSomethingThatLooksLikeUuidButIsNot() throws Exception { final MockPreparedStatement preparedStatement = new MockPreparedStatement(); final String[] given = { "2aad615a-d8e1-11e2-b8ed-50e549c9b654", "uuid'2aad615a-d8e1-11e2-b8ed-50e549c9b65'" }; final Object[] expected = {null, null}; final int[] expectedSqlTypesForDataType = {Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY}; for (int i = 0; i < expected.length; i++) { final String givenValue = given[i]; final Object expectedValue = expected[i]; for (int j = 0; j < TYPES.length; j++) { final DataType dataType = TYPES[j]; final int expectedSqlType = expectedSqlTypesForDataType[j]; dataType.setSqlValue(givenValue, 1, preparedStatement); assertEquals( "Loop " + i + " Type " + dataType, 1, preparedStatement.getLastSetObjectParamIndex()); assertEquals( "Loop " + i + " Type " + dataType, expectedSqlType, preparedStatement.getLastSetObjectTargetSqlType()); final Object actualValue = preparedStatement.getLastSetObjectParamValue(); assertEquals("Loop " + i + " Type " + dataType, expectedValue, actualValue); } } }
public static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) { Class<?>[] p = DataType.convertToPrimitive(parameterTypes); for (Method m : clazz.getMethods()) if (m.getName().equals(name) && DataType.equalsArray(DataType.convertToPrimitive(m.getParameterTypes()), p)) return m; return null; }
DataType.Name checkType(int i, DataType.Name name1, DataType.Name name2, DataType.Name name3) { DataType defined = getType(i); if (name1 != defined.getName() && name2 != defined.getName() && name3 != defined.getName()) throw new InvalidTypeException(String.format("Column %s is of type %s", getName(i), defined)); return defined.getName(); }
/** * Read data from encoded values and run len into regular data array * * @param ddata is encoded data values * @return the data array of row data */ public byte[] readOneRowData(byte[] ddata, int rLen, int xt) throws IOException, InvalidRangeException { int run; byte[] bdata = new byte[xt]; int nbin = 0; int total = 0; for (run = 0; run < rLen; run++) { int drun = DataType.unsignedByteToShort(ddata[run]) >> 4; byte dcode1 = (byte) (DataType.unsignedByteToShort(ddata[run]) & 0Xf); for (int i = 0; i < drun; i++) { bdata[nbin++] = dcode1; total++; } } if (total < xt) { for (run = total; run < xt; run++) { bdata[run] = 0; } } return bdata; }
@SuppressWarnings("unchecked") @Override public int compare(Object aObj, Object bObj) { if (aObj == bObj) { return 0; } DataType ta = getType(aObj); DataType tb = getType(bObj); if (ta != this && ta == tb) { return ta.compare(aObj, bObj); } // TODO ensure comparable type (both may be comparable but not // with each other) if (aObj instanceof Comparable) { if (aObj.getClass().isAssignableFrom(bObj.getClass())) { return ((Comparable<Object>) aObj).compareTo(bObj); } } if (bObj instanceof Comparable) { if (bObj.getClass().isAssignableFrom(aObj.getClass())) { return -((Comparable<Object>) bObj).compareTo(aObj); } } byte[] a = serialize(aObj); byte[] b = serialize(bObj); return compareNotNull(a, b); }
@SuppressWarnings("unchecked") public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass) { DataType type = metadata.getType(i); if (type.getName() != DataType.Name.MAP) throw new InvalidTypeException( String.format("Column %s is not of map type", metadata.getName(i))); Class<?> expectedKeysClass = type.getTypeArguments().get(0).getName().javaType; Class<?> expectedValuesClass = type.getTypeArguments().get(1).getName().javaType; if (!keysClass.isAssignableFrom(expectedKeysClass) || !valuesClass.isAssignableFrom(expectedValuesClass)) throw new InvalidTypeException( String.format( "Column %s is a map of %s->%s (CQL type %s), cannot be retrieve as a map of %s->%s", metadata.getName(i), expectedKeysClass, expectedValuesClass, type, keysClass, valuesClass)); ByteBuffer value = data.get(i); if (value == null) return Collections.<K, V>emptyMap(); return Collections.unmodifiableMap(Codec.<Map<K, V>>getCodec(type).compose(value)); }
@Override public DataType visitAnd_test(@NotNull PythonParser.And_testContext ctx) { DataType type = visitNot_test(ctx.not_test(0)); if (!ctx.isEmpty() && ctx.not_test().size() > 1) { if (!type.isPrimitive()) { throw new CompileException(String.format("Doing and with %s is making no sense!", type)); } for (int i = 1; i < ctx.not_test().size(); i++) { visitNot_test(ctx.not_test(i)); Label falseLabel = new Label(); Label fastFalseLabel = new Label(); Label exitLabel = new Label(); mv.visitJumpInsn(IFEQ, fastFalseLabel); mv.visitJumpInsn(IFEQ, falseLabel); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, exitLabel); mv.visitLabel(fastFalseLabel); mv.visitInsn(POP); mv.visitLabel(falseLabel); mv.visitInsn(ICONST_0); mv.visitLabel(exitLabel); } return PrimitiveType.BOOLEAN; } return type; }
/** Prints the sample collections that will be used in testing (for exporting purposes) */ @Test(groups = "doc") @SuppressWarnings("unchecked") public void printSampleCollections() { String objective = "Sample Collections"; System.out.println(String.format("Printing %s...", objective)); for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) { HashMap<DataType, Object> sampleValueMap = (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType); if (dataType.getName() == DataType.Name.MAP) { DataType typeArgument = sampleValueMap.keySet().iterator().next(); HashMap<DataType, Object> sampleMap = (HashMap<DataType, Object>) sampleValueMap.get(typeArgument); Object mapKey = SAMPLE_DATA.get(typeArgument); Object mapValue = sampleMap.get(typeArgument); System.out.println(String.format("%1$-30s {%2$s : %3$s}", dataType, mapKey, mapValue)); } else { DataType typeArgument = sampleValueMap.keySet().iterator().next(); Object sampleValue = sampleValueMap.get(typeArgument); System.out.println(String.format("%1$-30s %2$s", dataType, sampleValue)); } } System.out.println(String.format("\nEnd of %s\n\n", objective)); }
@Override public DataType visitArith_expr(@NotNull PythonParser.Arith_exprContext ctx) { DataType type = visitTerm(ctx.term(0)); int i = 1; if (!ctx.MINUS().isEmpty()) { if (!type.isPrimitive()) { throw new CompileException( String.format( "Doing %s with %s is making no sense!", ctx.MINUS().get(0).getText(), type)); } for (TerminalNode ignored : ctx.MINUS()) { type = visitTerm(ctx.term(i++)); mv.visitInsn(ISUB); } if (type.equals(PrimitiveType.BOOLEAN)) return PrimitiveType.INTEGER; } else if (!ctx.PLUS().isEmpty()) { if (!type.isPrimitive()) { throw new CompileException( String.format( "Doing %s with %s is making no sense!", ctx.PLUS().get(0).getText(), type)); } for (TerminalNode ignored : ctx.PLUS()) { type = visitTerm(ctx.term(i++)); mv.visitInsn(IADD); } if (type.equals(PrimitiveType.BOOLEAN)) return PrimitiveType.INTEGER; } return type; }
public void testShouldBeAbleToAddCustomDataTypes() throws Exception { DataType.registerUserDefinedDataTypes(Point.class.getName(), new PointDataType()); DataType returnedDataType = DataType.instance(Point.class.getName()); assertEquals("(5,5)", returnedDataType.addTo("(5,5)", new Point(1, 1), 0)); assertEquals("(6,6)", returnedDataType.addTo("(5,5)", new Point(1, 1), 1)); assertEquals("(10,10)", returnedDataType.addTo("(5,5)", new Point(1, 1), 5)); }
private void setProbability(double loggf) { DataType dt = new DataType(); ValueType val = new ValueType(); val.setValue(loggf); val.setUnits("unitless"); dt.setValue(val); rtp.setLog10WeightedOscillatorStregnth(dt); }
private void setgup(double g) { DataType dt = new DataType(); ValueType val = new ValueType(); val.setValue(g); val.setUnits("unitless"); dt.setValue(val); andtup.setLandeFactor(dt); }
private void setEup(double Ep) { DataType dt = new DataType(); ValueType val = new ValueType(); val.setValue(Ep); val.setUnits("cm-1"); dt.setValue(val); andtup.setStateEnergy(dt); }
@Override public int getMemory(Object obj) { DataType t = getType(obj); if (t == this) { return 1000; } return t.getMemory(obj); }
/** * Used internally to generate the types that a widget supports. Widgets support more than what * they explicitly support, they also deal with parent types and what not, so that is what this * will figure out. * * @param set the set that we will add the types to * @param types the types that a widget supports * @return the set that was given (except it will have types added to it) */ private static Set<DataType> generateTypes(Set<DataType> set, DataType[] types) { for (DataType type : types) { if (set.add(type)) { generateTypes(set, type.getParents()); } } return set; }
/** Generates the sample collections that will be used in testing */ private static HashMap<DataType, Object> getSampleCollections() { HashMap<DataType, Object> sampleCollections = new HashMap<DataType, Object>(); HashMap<DataType, Object> setAndListCollection; HashMap<DataType, HashMap<DataType, Object>> mapCollection; for (DataType.Name dataTypeName : DATA_TYPE_NON_PRIMITIVE_NAMES) { switch (dataTypeName) { case LIST: for (DataType typeArgument : DATA_TYPE_PRIMITIVES) { if (exclude(typeArgument)) continue; List<Object> list = new ArrayList<Object>(); for (int i = 0; i < 5; i++) { list.add(SAMPLE_DATA.get(typeArgument)); } setAndListCollection = new HashMap<DataType, Object>(); setAndListCollection.put(typeArgument, list); sampleCollections.put(DataType.list(typeArgument), setAndListCollection); } break; case SET: for (DataType typeArgument : DATA_TYPE_PRIMITIVES) { if (exclude(typeArgument)) continue; Set<Object> set = new HashSet<Object>(); for (int i = 0; i < 5; i++) { set.add(SAMPLE_DATA.get(typeArgument)); } setAndListCollection = new HashMap<DataType, Object>(); setAndListCollection.put(typeArgument, set); sampleCollections.put(DataType.set(typeArgument), setAndListCollection); } break; case MAP: for (DataType typeArgument1 : DATA_TYPE_PRIMITIVES) { if (exclude(typeArgument1)) continue; for (DataType typeArgument2 : DATA_TYPE_PRIMITIVES) { if (exclude(typeArgument2)) continue; HashMap<DataType, Object> map = new HashMap<DataType, Object>(); map.put(typeArgument1, SAMPLE_DATA.get(typeArgument2)); mapCollection = new HashMap<DataType, HashMap<DataType, Object>>(); mapCollection.put(typeArgument1, map); sampleCollections.put(DataType.map(typeArgument1, typeArgument2), mapCollection); } } break; default: throw new RuntimeException("Missing handling of " + dataTypeName); } } return sampleCollections; }
/** * Create a scalar numeric-valued Attribute. * * @param name name of Attribute * @param val value of Attribute */ public Attribute(String name, Number val) { this.name = name; int[] shape = new int[1]; shape[0] = 1; DataType dt = DataType.getType(val.getClass()); Array vala = Array.factory(dt.getPrimitiveClassType(), shape); Index ima = vala.getIndex(); vala.setDouble(ima.set0(0), val.doubleValue()); setValues(vala); }
public boolean evalAction(DataType owner, Action<?> action) { if (action.getSource() instanceof Enemy<?>) { if (action instanceof PostMoveAction) { if (owner.isWithinRange((ICollidable) action.getSource())) { owner.addEnemyToAttackList((Enemy<?>) action.getSource()); } } } return false; }
public RArrayImpl(final DataType data, final String className1, final int[] dim) { if (data == null || className1 == null || dim == null) { throw new NullPointerException(); } if (data.getLength() >= 0) { checkDim(data.getLength(), dim); } this.className1 = className1; this.dimAttribute = new RIntegerDataImpl(dim); this.data = data; }
/** * Get a 1DArray for the type and length * * @param type DataType * @param len length * @return the array */ private Array get1DArray(DataType type, int len) { Array varArray = null; if (type.equals(DataType.FLOAT)) { varArray = new ArrayFloat.D1(len); } else if (type.equals(DataType.DOUBLE)) { varArray = new ArrayDouble.D1(len); } else if (type.equals(DataType.INT)) { varArray = new ArrayInt.D1(len); } return varArray; }
private void setWavelength(double lam) { EnergyWavelengthType ewl = new EnergyWavelengthType(); WavelengthWavenumberType wl = new WavelengthWavenumberType(); DataType dt = new DataType(); ValueType val = new ValueType(); val.setValue(lam); val.setUnits("A"); dt.setValue(val); wl.setRitz(dt); ewl.setWavelength(wl); rt.setEnergyWavelength(ewl); }
public DataType get(int type) { DataType dataType; String name; for (Enumeration<String> en = dataTypeList.keys(); en.hasMoreElements(); ) { name = en.nextElement(); dataType = get(name); if (dataType.getSqlType() == type) { return dataType; } } return null; }
@Override public ByteBuffer write(ByteBuffer buff, Object obj) { DataType t = getType(obj); if (t != this) { return t.write(buff, obj); } buff.put((byte) TYPE_SERIALIZED_OBJECT); byte[] data = serialize(obj); DataUtils.writeVarInt(buff, data.length); buff = DataUtils.ensureCapacity(buff, data.length); buff.put(data); return buff; }
/** * Returns the constructor of a given class with the given parameter types * * @param clazz Target class * @param parameterTypes Parameter types of the desired constructor * @return The constructor of the target class with the specified parameter types * @throws NoSuchMethodException If the desired constructor with the specified parameter types * cannot be found * @see DataType * @see DataType#getPrimitive(Class[]) * @see DataType#compare(Class[], Class[]) */ public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException { Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes); for (Constructor<?> constructor : clazz.getConstructors()) { if (!DataType.compare( DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) { continue; } return constructor; } throw new NoSuchMethodException( "There is no such constructor in this class with the specified parameter types"); }
/** * Returns a method of a class with the given parameter types * * @param clazz Target class * @param methodName Name of the desired method * @param parameterTypes Parameter types of the desired method * @return The method of the target class with the specified name and parameter types * @throws NoSuchMethodException If the desired method of the target class with the specified name * and parameter types cannot be found * @see DataType#getPrimitive(Class[]) * @see DataType#compare(Class[], Class[]) */ public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException { Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes); for (Method method : clazz.getMethods()) { if (!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) { continue; } return method; } throw new NoSuchMethodException( "There is no such method in this class with the specified name and parameter types"); }