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

ru.cwcode.commands.extra.RepositoryAccessor Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
package ru.cwcode.commands.extra;

import ru.cwcode.commands.Argument;
import ru.cwcode.commands.api.Sender;
import ru.cwcode.commands.extra.command.argument.KeyArgument;

import java.util.Collection;
import java.util.function.BiFunction;
import java.util.function.Function;

public class RepositoryAccessor {
  private final BiFunction elementToKey;
  private final BiFunction keyToElement;
  private final Function keyToString;
  private final Function stringToKey;
  private final Function> keys;
  
  public RepositoryAccessor(BiFunction elementToKey,
                            BiFunction keyToElement,
                            Function keyToString,
                            Function stringToKey,
                            Function> keys) {
    this.elementToKey = elementToKey;
    this.keyToElement = keyToElement;
    this.keyToString = keyToString;
    this.stringToKey = stringToKey;
    this.keys = keys;
  }
  
  public Collection keys(S sender) {
    return keys.apply(sender);
  }
  
  public K elementToKey(E element, S sender) {
    return elementToKey.apply(element, sender);
  }
  
  public E keyToElement(S sender, K key) {
    return keyToElement.apply(key, sender);
  }
  
  public String keyToString(K key) {
    return keyToString.apply(key);
  }
  
  public K stringToKey(String string) {
    return stringToKey.apply(string);
  }
  
  public Argument keyArgument() {
    return new KeyArgument(this); //мб стоит 1 сохранить
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy