/// <summary> Constructor for nominal attributes and string attributes, where /// metadata is supplied. If a null vector of attribute values is passed /// to the method, the attribute is assumed to be a string. /// /// </summary> /// <param name="attributeName">the name for the attribute /// </param> /// <param name="attributeValues">a vector of strings denoting the /// attribute values. Null if the attribute is a string attribute. /// </param> /// <param name="metadata">the attribute's properties /// </param> //@ requires attributeName != null; //@ requires metadata != null; /*@ ensures m_Name == attributeName; ensures m_Index == -1; ensures attributeValues == null && m_Type == STRING || attributeValues != null && m_Type == NOMINAL && m_Values.size() == attributeValues.size(); signals (IllegalArgumentException ex) (* if duplicate strings in attributeValues *); */ public Attribute(System.String attributeName, FastVector attributeValues, ProtectedProperties metadata) { m_Name = attributeName; m_Index = - 1; if (attributeValues == null) { m_Values = new FastVector(); m_Hashtable = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable()); m_Type = STRING; } else { m_Values = new FastVector(attributeValues.size()); //m_Hashtable = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable(attributeValues.size())); m_Hashtable = new System.Collections.Hashtable(attributeValues.size()); for (int i = 0; i < attributeValues.size(); i++) { // No serialization System.Object store = attributeValues.elementAt(i); //if (((System.String) store).Length > STRING_COMPRESS_THRESHOLD) //{ // try // { // store = new SerializedObject(attributeValues.elementAt(i), true); // } // catch (System.Exception ex) // { // System.Console.Error.WriteLine("Couldn't compress nominal attribute value -" + " storing uncompressed."); // } //} if (m_Hashtable.ContainsKey(store)) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" throw new System.ArgumentException("A nominal attribute (" + attributeName + ") cannot" + " have duplicate labels (" + store + ")."); } m_Values.addElement(store); m_Hashtable.Add(store, (System.Int32) i); } m_Type = NOMINAL; } setMetadata(metadata); }
/// <summary> Constructor for a numeric attribute, where metadata is supplied. /// /// </summary> /// <param name="attributeName">the name for the attribute /// </param> /// <param name="metadata">the attribute's properties /// </param> //@ requires attributeName != null; //@ requires metadata != null; //@ ensures m_Name == attributeName; public Attribute(System.String attributeName, ProtectedProperties metadata) { m_Name = attributeName; m_Index = - 1; m_Values = null; m_Hashtable = null; m_Type = NUMERIC; setMetadata(metadata); }
/// <summary> Constructor for a date attribute, where metadata is supplied. /// /// </summary> /// <param name="attributeName">the name for the attribute /// </param> /// <param name="dateFormat">a string suitable for use with /// SimpleDateFormatter for parsing dates. /// </param> /// <param name="metadata">the attribute's properties /// </param> //@ requires attributeName != null; //@ requires dateFormat != null; //@ requires metadata != null; //@ ensures m_Name == attributeName; public Attribute(System.String attributeName, System.String dateFormat, ProtectedProperties metadata) { m_Name = attributeName; m_Index = - 1; m_Values = null; m_Hashtable = null; m_Type = DATE; if (dateFormat != null) { //UPGRADE_ISSUE: Constructor 'java.text.SimpleDateFormat.SimpleDateFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextSimpleDateFormat'" m_DateFormat = dateFormat.ToString(); } else { //UPGRADE_ISSUE: Constructor 'java.text.SimpleDateFormat.SimpleDateFormat' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextSimpleDateFormat'" m_DateFormat = "yyyy-MM-dd'T'HH:mm:ss"; } //UPGRADE_ISSUE: Method 'java.text.DateFormat.setLenient' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javatextDateFormatsetLenient_boolean'" //m_DateFormat.setLenient(false); setMetadata(metadata); }
/// <summary> Sets the metadata for the attribute. Processes the strings stored in the /// metadata of the attribute so that the properties can be set up for the /// easy-access metadata methods. Any strings sought that are omitted will /// cause default values to be set. /// /// The following properties are recognised: /// ordering, averageable, zeropoint, regular, weight, and range. /// /// All other properties can be queried and handled appropriately by classes /// calling the getMetadata() method. /// /// </summary> /// <param name="metadata">the metadata /// </param> /// <exception cref="IllegalArgumentException">if the properties are not consistent /// </exception> //@ requires metadata != null; private void setMetadata(ProtectedProperties metadata) { m_Metadata = metadata; if (m_Type == DATE) { m_Ordering = ORDERING_ORDERED; m_IsRegular = true; m_IsAveragable = false; m_HasZeropoint = false; } else { // get ordering System.String orderString = m_Metadata["ordering"] == null?"":m_Metadata["ordering"]; // numeric ordered attributes are averagable and zeropoint by default System.String def; if (m_Type == NUMERIC && (System.String.CompareOrdinal(orderString, "modulo") != 0) && (System.String.CompareOrdinal(orderString, "symbolic") != 0)) def = "true"; else def = "false"; // determine boolean states m_IsAveragable = (System.String.CompareOrdinal(m_Metadata["averageable"] == null ? def : m_Metadata["averageable"], "true") == 0); m_HasZeropoint = (System.String.CompareOrdinal(m_Metadata["zeropoint"] == null ? def : m_Metadata["zeropoint"], "true") == 0); // averagable or zeropoint implies regular if (m_IsAveragable || m_HasZeropoint) def = "true"; m_IsRegular = (System.String.CompareOrdinal(m_Metadata["regular"] == null?def:m_Metadata["regular"], "true") == 0); // determine ordering if (System.String.CompareOrdinal(orderString, "symbolic") == 0) m_Ordering = ORDERING_SYMBOLIC; else if (System.String.CompareOrdinal(orderString, "ordered") == 0) m_Ordering = ORDERING_ORDERED; else if (System.String.CompareOrdinal(orderString, "modulo") == 0) m_Ordering = ORDERING_MODULO; else { if (m_Type == NUMERIC || m_IsAveragable || m_HasZeropoint) m_Ordering = ORDERING_ORDERED; else m_Ordering = ORDERING_SYMBOLIC; } } // consistency checks if (m_IsAveragable && !m_IsRegular) throw new System.ArgumentException("An averagable attribute must be" + " regular"); if (m_HasZeropoint && !m_IsRegular) throw new System.ArgumentException("A zeropoint attribute must be" + " regular"); if (m_IsRegular && m_Ordering == ORDERING_SYMBOLIC) throw new System.ArgumentException("A symbolic attribute cannot be" + " regular"); if (m_IsAveragable && m_Ordering != ORDERING_ORDERED) throw new System.ArgumentException("An averagable attribute must be" + " ordered"); if (m_HasZeropoint && m_Ordering != ORDERING_ORDERED) throw new System.ArgumentException("A zeropoint attribute must be" + " ordered"); // determine weight m_Weight = 1.0; System.String weightString = m_Metadata.Get("weight"); if (weightString != null) { try { m_Weight = System.Double.Parse(weightString); } catch (System.FormatException e) { // Check if value is really a number throw new System.ArgumentException("Not a valid attribute weight: '" + weightString + "'" + " " + e.ToString()); } } // determine numeric range if (m_Type == NUMERIC) NumericRange = m_Metadata.Get("range"); }