lojix/learning/src/main/com/thesett/aima/learning/decisiontree/prototype/ProtoDTLearningMethod.java
private boolean allHaveSameClassification(String property, Iterable<State> examples)
    {
        // Used to hold the value of the first attribute seen.
        OrdinalAttribute firstAttribute = null;

        // Flag used to indicate that the test passed successfully.
        boolean success = true;

        // Loop over all the examples.
        for (State example : examples)
        {
            OrdinalAttribute nextAttribute = (OrdinalAttribute) example.getProperty(property);

            // If this is the first example just store its attribute value.
            if (firstAttribute == null)
            {
                firstAttribute = nextAttribute;
            }

            // Otherwise check if the attribute value does not match the first one in which case the test fails.
            else if (!nextAttribute.equals(firstAttribute))
            {
                success = false;

                break;
            }
        }

        // If the test passed then store the matching classification that all the examples have in a memeber variable
        // from where it can be accessed.
        if (success)
        {
            allClassification = firstAttribute;
        }

        return success;
    }
private boolean allHaveSameClassification(String property, Iterable<State> examples)
    {
        // Used to hold the value of the first attribute seen.
        OrdinalAttribute firstAttribute = null;

        // Flag used to indicate that the test passed successfully.
        boolean success = true;

        // Loop over all the examples.
        for (State example : examples)
        {
            OrdinalAttribute nextAttribute = (OrdinalAttribute) example.getProperty(property);

            // If this is the first example just store its attribute value.
            if (firstAttribute == null)
            {
                firstAttribute = nextAttribute;
            }

            // Otherwise check if the attribute value does not match the first one in which case the test fails.
            else if (!nextAttribute.equals(firstAttribute))
            {
                success = false;

                break;
            }
        }

        // If the test passed then store the matching classification that all the examples have in a memeber variable
        // from where it can be accessed.
        if (success)
        {
            allClassification = firstAttribute;
        }

        return success;
    }
private boolean allHaveSameClassification ( String property , Iterable < State > examples ) { // Used to hold the value of the first attribute seen. OrdinalAttribute firstAttribute = null ; // Flag used to indicate that the test passed successfully. boolean success = true ; // Loop over all the examples. for ( State example : examples ) { OrdinalAttribute nextAttribute = ( OrdinalAttribute ) example . getProperty ( property ) ; // If this is the first example just store its attribute value. if ( firstAttribute == null ) { firstAttribute = nextAttribute ; } // Otherwise check if the attribute value does not match the first one in which case the test fails. else if ( ! nextAttribute . equals ( firstAttribute ) ) { success = false ; break ; } } // If the test passed then store the matching classification that all the examples have in a memeber variable // from where it can be accessed. if ( success ) { allClassification = firstAttribute ; } return success ; }
Tests if a property of a set of examples has the same value for all the examples. This algorithm works by
iterating through the examples until two different values are found or the end of the collection is reached
having found only one value.

<p>As a side effect this method leaves the value of the classification in the member variable
{@link #allClassification} when all the examples do match.

@param  property The name of the property to test.
@param  examples A collection of state objects to iterate over in order to test if they all have the same value
for the named property.

@return true if they all have the same value; false otherwise.
Tests if a property of a set of examples has the same value for all the examples . This algorithm works by iterating through the examples until two different values are found or the end of the collection is reached having found only one value .