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

redis.clients.jedis.resps.AccessControlUser Maven / Gradle / Ivy

The newest version!
package redis.clients.jedis.resps;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;

// TODO: remove
public class AccessControlUser {

  private final Map userInfo;
  private final List flags;
  private final List passwords;
  private final String commands;
  private final List keysList;
  private final String keys;
  private final List channelsList;
  private final String channels;
  private final List selectors;

  public AccessControlUser(Map map) {
    this.userInfo = map;

    this.flags = (List) map.get("flags");

    this.passwords = (List) map.get("passwords");

    this.commands = (String) map.get("commands");

    Object localKeys = map.get("keys");
    if (localKeys == null) {
      this.keys = null;
      this.keysList = null;
    } else if (localKeys instanceof List) {
      this.keysList = (List) localKeys;
      this.keys = joinStrings(this.keysList);
    } else {
      this.keys = (String) localKeys;
      this.keysList = Arrays.asList(this.keys.split(" "));
    }

    Object localChannels = map.get("channels");
    if (localChannels == null) {
      this.channels = null;
      this.channelsList = null;
    } else if (localChannels instanceof List) {
      this.channelsList = (List) localChannels;
      this.channels = joinStrings(this.channelsList);
    } else {
      this.channels = (String) localChannels;
      this.channelsList = Arrays.asList(this.channels.split(" "));
    }

    this.selectors = (List) map.get("selectors");
  }

  private static String joinStrings(List list) {
    StringJoiner joiner = new StringJoiner(" ");
    list.forEach(s -> joiner.add(s));
    return joiner.toString();
  }

  public List getFlags() {
    return flags;
  }

  /**
   * @deprecated Use {@link AccessControlUser#getPasswords()}.
   */
  @Deprecated
  public List getPassword() {
    return passwords;
  }

  public List getPasswords() {
    return passwords;
  }

  public String getCommands() {
    return commands;
  }

  /**
   * @return Generic map containing all key-value pairs returned by the server
   */
  public Map getUserInfo() {
    return userInfo;
  }

  public String getKeys() {
    return keys;
  }

  public List getKeysList() {
    return keysList;
  }

  public List getChannelsList() {
    return channelsList;
  }

  public String getChannels() {
    return channels;
  }

  public List getSelectors() {
    return selectors;
  }

  @Override
  public String toString() {
    return "AccessControlUser{" + "flags=" + flags + ", passwords=" + passwords
        + ", commands='" + commands + "', keys='" + keys + "', channels='" + channels
        + "', selectors=" + selectors + "}";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy