Holger's Java API

## com.antelmann.net
Class URLTree

    java.lang.Object
      javax.swing.tree.DefaultTreeModel
          com.antelmann.net.URLTree

All Implemented Interfaces:
  Serializable, TreeModel

    public class URLTree

extends DefaultTreeModel

URLTree represents the model of a tree where each node is made of a URL wrapped in a URLNode object. The tree is configurable in size by adding restrictions that determine whether a URLNode is included in the tree or not.
Note that changing parameters of the CrawlerSetting used by the URL tree without recalculating the tree may put the tree in an inconsistent state.

Author:
  Holger Antelmann
See Also:
  `URLNode`, Serialized Form

Field Summary

Fields inherited from class javax.swing.tree.DefaultTreeModel
`asksAllowsChildren, listenerList, root`

Constructor Summary
`URLTree(URL root)` calls `URLTree(root, new SampleCrawlerSetting(), false)`
`URLTree(URL root, CrawlerSetting crawler, boolean singlePath)`

Method Summary
`CrawlerSetting` `getCrawler()`
`int` `getNumberOfNodes()`
`boolean` `getSinglePath()` if true, the URLTree allows every URL to only occur once in the tree
`void` `revalidate(boolean refresh)` recalculates the entire tree recursively from the root based on the current settings; this should be done every time when parameters of the crawler changed, otherwise the tree could be in an inconsisten state
`protected void` `revalidateNode(URLNode node, boolean refresh)` internally called by recalculate(); recalculates sub-tree recursively
`void` `setCrawler(CrawlerSetting crawler)` on calling this method, the entire tree will be recalculated based on the settings of the new crawler
`void` `setRoot(TreeNode root)` overwritten to ensure proper immediate calculation of the entire new tree based on the new settings.
`void` `setRoot(URL root)`
`void` `setSinglePath(boolean singlePath)` if set to true, the URLTree allows every URL to only occur once in the tree; calling this function forces the entire tree to be revalidated from the root
`String` `toString()`

Methods inherited from class javax.swing.tree.DefaultTreeModel

`addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, valueForPathChanged`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### URLTree

    public URLTree(URL root)

  calls `URLTree(root, new SampleCrawlerSetting(), false)`

### URLTree

    public URLTree(URL root,
                   CrawlerSetting crawler,
                   boolean singlePath)

Parameters:
  `root` - the root node of the tree
  `crawler` - restrictions that define the content of the URLTree
  `singlePath` - if true, the tree allows each URL to occur only once in the tree

Method Detail

### setRoot

    public void setRoot(URL root)

### setRoot

    public void setRoot(TreeNode root)

  overwritten to ensure proper immediate calculation of the entire new tree based on the new settings.

  Overrides:
    `setRoot` in class `DefaultTreeModel`
  Throws:
    `ClassCastException` - if given node is not a URLNode

### getCrawler

    public CrawlerSetting getCrawler()

### setCrawler

    public void setCrawler(CrawlerSetting crawler)

  on calling this method, the entire tree will be recalculated based on the settings of the new crawler

### getSinglePath

    public boolean getSinglePath()

  if true, the URLTree allows every URL to only occur once in the tree

### setSinglePath

    public void setSinglePath(boolean singlePath)

  if set to true, the URLTree allows every URL to only occur once in the tree; calling this function forces the entire tree to be revalidated from the root

### revalidate

    public void revalidate(boolean refresh)

  recalculates the entire tree recursively from the root based on the current settings; this should be done every time when parameters of the crawler changed, otherwise the tree could be in an inconsisten state

  Parameters:
    `refresh` - if true, each cached node contend is refreshed, i.e. reloaded from the net

### revalidateNode

    protected void revalidateNode(URLNode node,
                                  boolean refresh)

  internally called by recalculate(); recalculates sub-tree recursively

### getNumberOfNodes

    public int getNumberOfNodes()

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads