Where to Find Up-to-date yFiles Information

This page is from the outdated yFiles for Java 2.13 documentation. You can find the most up-to-date documentation for all yFiles products on the yFiles documentation overview page.

Please see the following links for more information about the yFiles product family of diagramming programming libraries and corresponding yFiles products for modern web apps, for cross-platform Java(FX) applications, and for applications for the Microsoft .NET environment.

More about the yFiles product family Close X

Containers

Classes NodeList and EdgeList, the typed descendants of class YList, are the most frequently encountered yFiles data structures to store graph elements. Figure 4.6, “yFiles graph element containers” shows their relationship.

Figure 4.6. yFiles graph element containers

The yFiles graph element containers.

Common to all lists is their support for the methods from interface java.util.Collection via the implementation in class YList. Beyond this implementation, class YList provides advanced list access and manipulation services which strongly rely on the possibilities offered by class ListCell.

High-Level Features

In addition to the methods from interface java.util.Collection there are several further methods offered. For instance, it is possible to add elements explicitly to the front or the back of a list. Also, removing elements from the list is possible from both the front and the back. Note that the method names for removing elements from either end of the list resemble those of abstract data type stack.

Other methods offer list sorting, reversing a list, or the splicing of two lists into one.

Example 4.8. Adding elements to and removing elements from a list

// 'list' is of type y.base.YList. 

// Add new elements to either end of the list. 
list.addFirst("I am the first node!");
list.addLast("I am the last node!");

// Remove elements from either end of the list. 
list.pop();
list.popLast();

To iterate over the elements of the list it provides a YCursor (respectively NodeCursor and EdgeCursor with classes NodeList and EdgeList). Even though java.util.Iterator is also available as an alternative, the yFiles cursors are the commonly used and most qualified means for iteration. See also the discussion in the section called “Iteration Mechanisms”.

Example 4.9, “Efficiently removing elements from a list” shows how to efficiently remove an element from a list. The cursor directly points to the element, there is no need to search the list.

Example 4.9. Efficiently removing elements from a list

// 'list' is of type y.base.YList. 

// Remove unwanted objects from the list. 
for (YCursor c = list.cursor(); c.ok(); c.next()) {
  if (isUnwanted(c.current())) {
    list.removeAt(c);
  }
}

Low-Level Features

Class ListCell is the building block of the doubly linked list structure. It knows both its predecessor and its successor, and provides read/write behavior for the actual data it is holding.

Example 4.10. Using class ListCell

// 'list' is of type y.base.YList. 

// Get the first cell of the list. 
ListCell firstCell = list.firstCell();

// Get the actual data the cell is holding. 
Object obj = firstCell.getInfo();

// Change the actual data. 
firstCell.setInfo("Updated Data.");

Using an instance of type ListCell, for example, it is possible to have fast access to the preceeding, respectively succeeding cell from the containing list, or to insert new cells relatively to already contained ones. By way of the successors (predecessors) of a ListCell instance, direct iteration over the elements of a list is possible.

Example 4.11. Directly iterating over the cells of a YList

// 'list' is of type y.base.YList. 

// Directly (backward) iterate over the list. 
for (ListCell lc = list.lastCell(); lc != null; lc = list.predCell(lc)) {
  if (conditionIsSatisfied(lc.getInfo())) {
    // Insert a new cell with given data relatively to the held reference cell. 
    // The newly allocated cell will be returned. 
    ListCell newCell = list.insertBefore("Prepended Data.", lc);
  }
}

For further code examples see also ListDemo.java from the tutorial demo applications.