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

com.helger.dao.wal.IMapBasedDAO Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2014-2021 Philip Helger (www.helger.com)
 * philip[at]helger[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.helger.dao.wal;

import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

import com.helger.commons.annotation.ReturnsMutableCopy;
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.collection.impl.ICommonsSet;
import com.helger.commons.id.IHasID;
import com.helger.commons.lang.IHasSize;

/**
 * Read-only base interface for the MAP based DAO
 *
 * @author Philip Helger
 * @param 
 *        The interface type of the elements handled by the DAO
 */
@ThreadSafe
public interface IMapBasedDAO > extends IHasSize
{
  /**
   * @param 
   *        Response type.
   * @return An empty collection of the suitable implementation type.
   * @since 9.4.5 in the interface
   */
  @Nonnull
  @ReturnsMutableCopy
   ICommonsList  getNone ();

  /**
   * @return A list of all contained items. Never null.
   */
  @Nonnull
  @ReturnsMutableCopy
  ICommonsList  getAll ();

  /**
   * @param aFilter
   *        Filter to be applied. May be null.
   * @return A list of all contained items matching the filter. Never
   *         null.
   */
  @Nonnull
  @ReturnsMutableCopy
  ICommonsList  getAll (@Nullable Predicate  aFilter);

  /**
   * Find all items matching the filter and invoke the consumer on all matching
   * entries.
   *
   * @param aFilter
   *        The filter to be applied. May be null.
   * @param aConsumer
   *        The consumer to be invoked for all matches. May not be
   *        null.
   */
  void findAll (@Nullable Predicate  aFilter, @Nonnull Consumer  aConsumer);

  /**
   * Get all contained items matching the provided filter and map them to
   * something else.
   *
   * @param aFilter
   *        The filter to be applied. May be null.
   * @param aMapper
   *        The mapper to be invoked. May not be null.
   * @return The list all matching and mapped elements. Never null.
   * @param 
   *        Return type to which is mapped
   */
  @Nonnull
  @ReturnsMutableCopy
   ICommonsList  getAllMapped (@Nullable Predicate  aFilter,
                                                 @Nonnull Function  aMapper);

  /**
   * Find all contained items that match the filter, map them to a different
   * type and invoke the consumer on all mapped items.
   *
   * @param aFilter
   *        The filter to be applied. May be null.
   * @param aMapper
   *        The mapper to be invoked. May not be null.
   * @param aConsumer
   *        The consumer to be invoked for all matches. May not be
   *        null.
   * @param 
   *        Return type to which is mapped
   */
   void findAllMapped (@Nullable Predicate  aFilter,
                                @Nonnull Function  aMapper,
                                @Nonnull Consumer  aConsumer);

  /**
   * Find the the first element that matches the filter.
   *
   * @param aFilter
   *        The filter to be applied. May be null.
   * @return The first matching item or null.
   */
  @Nullable
  INTERFACETYPE findFirst (@Nullable Predicate  aFilter);

  @Nullable
   RETTYPE findFirstMapped (@Nullable Predicate  aFilter,
                                     @Nonnull Function  aMapper);

  /**
   * @param aFilter
   *        The filter to be applied. May be null.
   * @return true if at least one item matches the filter
   */
  boolean containsAny (@Nullable Predicate  aFilter);

  /**
   * @param aFilter
   *        The filter to be applied. May be null.
   * @return true if no item matches the filter
   */
  boolean containsNone (@Nullable Predicate  aFilter);

  /**
   * @param aFilter
   *        The filter to be applied. May be null.
   * @return true if all items match the filter
   */
  boolean containsOnly (@Nullable Predicate  aFilter);

  /**
   * @param sID
   *        The ID to be checked. May be null.
   * @return true if an item with the provided ID is contained.
   */
  boolean containsWithID (@Nullable String sID);

  /**
   * Iterate each entry
   * 
   * @param aConsumer
   *        Consumer to use. May be null.
   * @since 9.4.5 in the interface
   */
  void forEach (@Nullable BiConsumer  aConsumer);

  /**
   * Iterate each entry
   * 
   * @param aFilter
   *        Optional filter to limit the entries for which the consumer is
   *        called. May be null.
   * @param aConsumer
   *        Consumer to use. May be null.
   * @since 9.4.5 in the interface
   */
  void forEach (@Nullable BiPredicate  aFilter,
                @Nullable BiConsumer  aConsumer);

  /**
   * Iterate each key
   * 
   * @param aConsumer
   *        Consumer to use. May be null.
   * @since 9.4.5 in the interface
   */
  void forEachKey (@Nullable Consumer  aConsumer);

  /**
   * Iterate each key
   * 
   * @param aFilter
   *        Optional filter to limit the entries for which the consumer is
   *        called. May be null.
   * @param aConsumer
   *        Consumer to use. May be null.
   * @since 9.4.5 in the interface
   */
  void forEachKey (@Nullable Predicate  aFilter, @Nullable Consumer  aConsumer);

  /**
   * Iterate each value
   * 
   * @param aConsumer
   *        Consumer to use. May be null.
   * @since 9.4.5 in the interface
   */
  void forEachValue (@Nullable Consumer  aConsumer);

  /**
   * Iterate each value
   * 
   * @param aFilter
   *        Optional filter to limit the entries for which the consumer is
   *        called. May be null.
   * @param aConsumer
   *        Consumer to use. May be null.
   * @since 9.4.5 in the interface
   */
  void forEachValue (@Nullable Predicate  aFilter, @Nullable Consumer  aConsumer);

  /**
   * Check if all IDs are contained
   *
   * @param aIDs
   *        IDs to check
   * @return true if all IDs are contained
   * @since 9.4.5 in the interface
   */
  boolean containsAllIDs (@Nullable Iterable  aIDs);

  /**
   * @return A set with the IDs of all contained items. Never null
   *         but maybe empty.
   */
  @Nonnull
  @ReturnsMutableCopy
  ICommonsSet  getAllIDs ();

  /**
   * @param aFilter
   *        The filter to be applied. May be null.
   * @return The number of items matching the provided filter. Always ≥ 0.
   */
  @Nonnegative
  int getCount (@Nullable Predicate  aFilter);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy