MongoUtils.java [src/java/utils] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import csip.ServiceException;

/**
 *
 * @author od
 */
public class MongoUtils {

  //Sorting
  public enum Sorting {
    ASCENDING(1), DESCENDING(-1);

    private int order;


    private Sorting(int order) {
      this.order = order;
    }


    public int getOrder() {
      return order;
    }

  }

  @FunctionalInterface
  public interface ServiceFunction<T, R> {

    R apply(T t) throws ServiceException;
  }


  public static String nestedDocuments(String... ss) {
    StringBuilder build = new StringBuilder(ss[0]);
    for (int i = 1; i < ss.length; i++) {
      build.append(".");
      build.append(ss[i]);
    }
    return build.toString();
  }


  static boolean checkForNormRange(String type) {
    if (type.contains("[") && type.contains("]")) {
      return true;
    } else if (type.contains("[") && !type.contains("]")) {
      String msg = "String missing type ";
      throw new IllegalArgumentException(msg + type);
    } else if (!type.contains("[") && type.contains("]")) {
      String msg = "String missing type ";
      throw new IllegalArgumentException(msg + type);
    } else {
      return false;
    }
  }

}