Package ar.com.restba.utils

Source Code of ar.com.restba.utils.RestBAUtils

package ar.com.restba.utils;

import ar.com.restba.json.JsonArray;
import ar.com.restba.json.JsonObject;


/**
* Utility Class con funciones comunes y sin comportamiento a todo el proyecto.
*
* @author Nicolás Meléndez |
* Email: nfmelendez@gmail.com |
* Twitter: @nfmelendezs
*
*/
public class RestBAUtils {

  private RestBAUtils() {
  }

  public static JsonObject findResourceById(JsonArray resources, String id) {
    if (null == id) {
      throw new RuntimeException("Id can't be null.");
    }

    if (null == resources) {
      throw new RuntimeException("resources can't be null");
    }

    for (int i = 0; i < resources.length(); i++) {
      JsonObject jsonObject = resources.getJsonObject(i);
      if (id.equals(jsonObject.getString("id"))) {
        return jsonObject;
      }
    }
    throw new RuntimeException("Could not find resource by id: " + id);
  }

}
TOP

Related Classes of ar.com.restba.utils.RestBAUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.