How to Pretty Print Java Code

This is a pretty print example with some Java code to boot.

Try it out at Hilight Me.

Recursive Method | ISO-3166 Geo Tree

    /**
     * <p>
     *     Find the GeoArea within this area's sub-tree that goes by the parameter
     *     identity (which is neither null nor consists solely of whitespace).
     * </p>
     *
     * <p>
     *     This method recursively iterates through the tree by calling itself
     *     with the identities of its children as the parameter.
     * </p>
     *
     * @param theGeoAreaCode the string area code that must match a tree element
     * @return the GeoArea whose identity matches the one given in the parameter
     */
    public GeoArea findGeoAreaById ( final String theGeoAreaCode )
    {
        if( this.getEntityId ().equalsIgnoreCase ( theGeoAreaCode ) )
            return this;

        for( final GeoArea childGeoArea: geoAreaChildren )
        {
            final GeoArea candidateGeoArea = childGeoArea.findGeoAreaById ( theGeoAreaCode );
            if( candidateGeoArea == null )
                continue;
            return candidateGeoArea;
        }

        return null;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *