lojix/power_model/src/main/com/thesett/aima/attribute/impl/HierarchyAttribute.java
public void setId(long id) throws IllegalArgumentException
    {
        // Find the category for this hierarchy attribute value.
        Tree<CategoryNode> category = attributeClass.lookup.get(value);

        // Extract the id.
        long existingId = category.getElement().id;

        // Do nothing if the new id matches the existing one.
        if (id == existingId)
        {
            return;
        }

        // The type is finalized.
        if (attributeClass.finalized)
        {
            // Raise an illegal argument exception if the id is not known.
            HierarchyAttribute newValue = attributeClass.getAttributeFromId(id);

            // Otherwise, change the value of this attribute to that of the new id.
            this.value = newValue.value;
        }

        // The type is unfinalized.
        else
        {
            // Check if another instance of the type already has the id and raise an exception if so.
            Tree<CategoryNode> existingNode = attributeClass.idMap.get(id);

            if (existingNode != null)
            {
                throw new IllegalArgumentException("The id value, " + id +
                    ", cannot be set because another instance of this type with that " + "id already exists.");
            }

            // Assign it to this instance if the type is unfinalized. Also removing the old id mapping from the id
            // map and replacing it with the new one.
            category.getElement().id = id;
            attributeClass.idMap.remove(existingId);
            attributeClass.idMap.put(id, category);
        }
    }
public void setId(long id) throws IllegalArgumentException
    {
        // Find the category for this hierarchy attribute value.
        Tree<CategoryNode> category = attributeClass.lookup.get(value);

        // Extract the id.
        long existingId = category.getElement().id;

        // Do nothing if the new id matches the existing one.
        if (id == existingId)
        {
            return;
        }

        // The type is finalized.
        if (attributeClass.finalized)
        {
            // Raise an illegal argument exception if the id is not known.
            HierarchyAttribute newValue = attributeClass.getAttributeFromId(id);

            // Otherwise, change the value of this attribute to that of the new id.
            this.value = newValue.value;
        }

        // The type is unfinalized.
        else
        {
            // Check if another instance of the type already has the id and raise an exception if so.
            Tree<CategoryNode> existingNode = attributeClass.idMap.get(id);

            if (existingNode != null)
            {
                throw new IllegalArgumentException("The id value, " + id +
                    ", cannot be set because another instance of this type with that " + "id already exists.");
            }

            // Assign it to this instance if the type is unfinalized. Also removing the old id mapping from the id
            // map and replacing it with the new one.
            category.getElement().id = id;
            attributeClass.idMap.remove(existingId);
            attributeClass.idMap.put(id, category);
        }
    }
Sets the integer id of the attribute. If the attribute class is finalized this will change the value of this
attribute to that of the matched id, or raise an exception if no matching id exists. If the attribute class is
unfinalized this will change the id value of this attribute within the attribute class to the new id, provided
that the id has not already been assigned to another attribute value. If it has been assigned to another
attribute value then an exception is raised.

@param  id The new id value.

@throws IllegalArgumentException If the type is finalized but the id does not exist. Or if the type is
unfinalized if the id has already been assigned to another instance of the type.