@BeforeClass public static void oneTimeSetUp() throws Exception { CallingContext cc = TestContextFactory.getCallingContext(); MyRelation rel = MyRelation.assertRelation(cc); System.out.println("dropping the large dataset"); cc.getDatastore() .dropRelation(rel, cc.getCurrentUser()); // drop it, in case prior test was messed up... rel = MyRelation.assertRelation(cc); System.out.println("writing the large dataset"); // write a lot of data... for (DataValue value : values) { value.assertInstance(rel, cc); } try { Thread.sleep(PersistConsts.MAX_SETTLE_MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("done writing the large dataset"); }
@Override public boolean equals(DataValue v) { if (v == null) return false; if (Types.isNumericType(v.getDataType())) { return this.compareTo(v) == 0; } else { return false; } }
private void toXml(XmppStreamWriter out, DataOption option) throws IOException, XMLStreamException { out.writeStartElement("option"); if (option.getLabel() != null) out.writeAttribute("label", option.getLabel()); DataValue[] values = option.getValue(); if (values != null) { for (int i = 0; i < values.length; i++) { DataValue value = values[i]; out.writeStartElement("value"); out.writeCharacters(value.getValue()); out.writeEndElement(); // </value> } } out.writeEndElement(); // </option> }
private void toXml(XmppStreamWriter out, DataField field) throws IOException, XMLStreamException { out.writeStartElement("field"); if (field.getLabel() != null) out.writeAttribute("label", field.getLabel()); if (field.getType() != null) out.writeAttribute("type", field.getType()); if (field.getVar() != null) out.writeAttribute("var", field.getVar()); if (field.getDesc() != null) { out.writeStartElement("desc"); out.writeCharacters(field.getDesc()); out.writeEndElement(); // </desc> } if (field.isRequired()) { out.writeStartElement("required"); out.writeEndElement(); // </required> } DataValue[] values = field.getValue(); if (values != null) { for (int i = 0; i < values.length; i++) { DataValue value = values[i]; out.writeStartElement("value"); out.writeCharacters(value.getValue()); out.writeEndElement(); // </value> } } DataOption[] options = field.getOption(); if (options != null) { for (int i = 0; i < options.length; i++) { toXml(out, options[i]); } } out.writeEndElement(); // </field> }
@Override public int compareTo(DataValue dv2) { NumericValue other = dv2.getAsNumeric(); NumericType mutual = getMutualType(this, other); switch (mutual) { case BIG_DECIMAL: return this.getAsBigDecimal().compareTo(other.getAsBigDecimal()); case BIG_INTEGER: return this.getAsBigInteger().compareTo(other.getAsBigInteger()); case DOUBLE: return Double.compare(this.getAsDouble(), other.getAsDouble()); case FLOAT: return Float.compare(this.getAsFloat(), other.getAsFloat()); case INT: return Integer.compare(this.getAsInt(), other.getAsInt()); case LONG: return Long.compare(this.getAsLong(), other.getAsLong()); default: throw new UnsupportedOperationException(); } }
@Override public Value evaluate() { // If the instance specification is for an enumeration, then return the // identified enumeration literal. // If the instance specification is for a data type (but not a primitive // value or an enumeration), then create a data value of the given data // type. // If the instance specification is for an object, then create an object // at the current locus with the specified types. // Set each feature of the created value to the result of evaluating the // value specifications for the specified slot for the feature. // Debug.println("[evaluate] InstanceValueEvaluation..."); InstanceSpecification instance = ((InstanceValue) this.specification).getInstance(); // List<Classifier> types = instance.getClassifiers(); // Classifier myType = types.get(0); // Debug.println("[evaluate] type = " + myType.getName()); Value value; if (instance instanceof EnumerationLiteral) { // Debug.println("[evaluate] Type is an enumeration."); EnumerationValue enumerationValue = new EnumerationValue(); // enumerationValue.type = (Enumeration)myType; enumerationValue.type = ((EnumerationLiteral) instance).getEnumeration(); // ADDED enumerationValue.literal = (EnumerationLiteral) instance; value = enumerationValue; Debug.println("[evaluate] type = " + enumerationValue.type.getName()); // ADDED } else { // ADDED: List<Classifier> types = instance.getClassifiers(); Classifier myType = types.get(0); Debug.println("[evaluate] type = " + myType.getName()); // StructuredValue structuredValue = null; if (myType instanceof DataType) { // Debug.println("[evaluate] Type is a data type."); DataValue dataValue = new DataValue(); dataValue.type = (DataType) myType; structuredValue = dataValue; } else { Object_ object = null; if (myType instanceof Behavior) { // Debug.println("[evaluate] Type is a behavior."); object = this.locus.factory.createExecution((Behavior) myType, null); } else { // Debug.println("[evaluate] Type is a class."); object = new Object_(); for (int i = 0; i < types.size(); i++) { Classifier type = types.get(i); object.types.add((Class) type); } } this.locus.add(object); Reference reference = new Reference(); reference.referent = object; structuredValue = reference; } structuredValue.createFeatureValues(); // Debug.println("[evaluate] " + instance.slot.size() + // " slot(s)."); List<Slot> instanceSlots = instance.getSlots(); for (int i = 0; i < instanceSlots.size(); i++) { Slot slot = instanceSlots.get(i); List<Value> values = new ArrayList<Value>(); // Debug.println("[evaluate] feature = " + // slot.definingFeature.getName() + ", " + slot.value.size() + // " value(s)."); List<ValueSpecification> slotValues = slot.getValues(); for (int j = 0; j < slotValues.size(); j++) { ValueSpecification slotValue = slotValues.get(j); // Debug.println("[evaluate] Value = " + // slotValue.getClass().getName()); values.add(this.locus.executor.evaluate(slotValue)); } structuredValue.setFeatureValue(slot.getDefiningFeature(), values, 0); } value = structuredValue; } return value; }
@Override public boolean supportsCompare(DataValue dv2) { return Types.isNumericType(dv2.getDataType()); }