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

redis.clients.util.JedisURIHelper Maven / Gradle / Ivy

There is a newer version: 1.13.0
Show newest version
package redis.clients.util;

import java.net.URI;

public final class JedisURIHelper {

  private static final int DEFAULT_DB = 0;

  private JedisURIHelper(){
    throw new InstantiationError( "Must not instantiate this class" );
  }

  public static String getPassword(URI uri) {
    String userInfo = uri.getUserInfo();
    if (userInfo != null) {
      return userInfo.split(":", 2)[1];
    }
    return null;
  }

  public static int getDBIndex(URI uri) {
    String[] pathSplit = uri.getPath().split("/", 2);
    if (pathSplit.length > 1) {
      String dbIndexStr = pathSplit[1];
      if (dbIndexStr.isEmpty()) {
        return DEFAULT_DB;
      }
      return Integer.parseInt(dbIndexStr);
    } else {
      return DEFAULT_DB;
    }
  }

  public static boolean isValid(URI uri) {
    if (isEmpty(uri.getScheme()) || isEmpty(uri.getHost()) || uri.getPort() == -1) {
      return false;
    }

    return true;
  }

  private static boolean isEmpty(String value) {
    return value == null || value.trim().length() == 0;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy