All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.phloc.commons.tree.IBasicTreeItem Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
/**
 * Copyright (C) 2006-2015 phloc systems
 * http://www.phloc.com
 * office[at]phloc[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phloc.commons.tree;

import java.util.Collection;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.phloc.commons.parent.IHasChildrenSorted;
import com.phloc.commons.parent.IHasParent;
import com.phloc.commons.state.ESuccess;

/**
 * Base interface both for normal tree items and tree items with ID.
 * 
 * @author Philip Helger
 * @param 
 *        Data type of the items.
 * @param 
 *        tree item type
 */
public interface IBasicTreeItem > extends
                                                                                                 IHasParent ,
                                                                                                 IHasChildrenSorted 
{
  /**
   * @return the data associated with this node. May be null.
   */
  @Nullable
  DATATYPE getData ();

  /**
   * @return the data associated with the parent node. May be null.
   */
  @Nullable
  DATATYPE getParentData ();

  /**
   * Get the data values of all contained children.
   * 
   * @return null if this item does not have children. Use
   *         {@link #hasChildren()} to check for the existence.
   */
  @Nullable
  Collection  getAllChildDatas ();

  /**
   * Change the data associated with this node.
   * 
   * @param aData
   *        The data associated with this node. May be null.
   * @throws IllegalArgumentException
   *         If the data is not valid (depending on any custom validator).
   */
  void setData (@Nullable DATATYPE aData);

  /**
   * @return true if this is the internal root item without a
   *         parent, false if this is a public item.
   */
  boolean isRootItem ();

  /**
   * Check if this item is the same or a child of the passed item. This is not
   * limited to direct children but to children on all levels.
   * 
   * @param aParent
   *        The parent item to check whether this is a child of it. May not be
   *        null.
   * @return true if this is the same or a child of
   *         aParent.
   */
  boolean isSameOrChildOf (@Nonnull ITEMTYPE aParent);

  /**
   * Change the parent node of this node to another node (subordination).
   * 
   * @param aNewParent
   *        The new parent to use. May not be null. To make it a
   *        root item, pass the owning tree's root item.
   * @return {@link ESuccess}
   */
  @Nonnull
  ESuccess changeParent (@Nonnull ITEMTYPE aNewParent);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy