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

org.seekay.contract.model.tools.ContractTools Maven / Gradle / Ivy

The newest version!
package org.seekay.contract.model.tools;

import org.seekay.contract.model.domain.Contract;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.seekay.contract.model.tools.SetTools.*;

public class ContractTools {

  /**
   * Private constructor for utility class
   */
  private ContractTools() {
    throw new IllegalStateException("Utility classes should never be constructed");
  }

  public static List retainTags(List contracts, String... tagsToRetain) {
    if(tagsToRetain.length == 0) {
      return contracts;
    }
    Set contractsToRetain = new HashSet();
    for(Contract contract : contracts) {
      Set contractTags = contract.readTags();
      for(String tagToRetain : tagsToRetain) {
        if(contractTags.contains(tagToRetain)) {
          contractsToRetain.add(contract);
          continue;
        }
      }
    }
    return new ArrayList(contractsToRetain);
  }

  public static List excludeTags(List contracts, String... tagsToExclude) {
    if(tagsToExclude.length != 0) {
      Set contractsToExclude = new HashSet();
      for (Contract contract : contracts) {
        Set contractTags = contract.readTags();
        for (String tagToExclude : tagsToExclude) {
          if (contractTags.contains(tagToExclude)) {
            contractsToExclude.add(contract);
            continue;
          }
        }
      }
      contracts.removeAll(contractsToExclude);
    }
    return contracts;
  }

  public static List tags(List contracts, Set tagsToRetain, Set tagsToExclude) {
    if(tagsToRetain != null) {
      contracts = retainTags(contracts, toArray(tagsToRetain));
    }
    if(tagsToExclude != null) {
      contracts = excludeTags(contracts, toArray(tagsToExclude));
    }
    return contracts;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy