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

com.shapestone.end.point.lock.EndPointLock Maven / Gradle / Ivy

The newest version!
package com.shapestone.end.point.lock;

import java.util.HashMap;
import java.util.Map;

import static java.lang.String.format;

/**
 * Name: Michael Williams
 * Date: 4/4/17.
 */
public class EndPointLock {

  private Map stringBooleanMap;

  public EndPointLock() {
    this.stringBooleanMap = new HashMap();
  }

  public boolean isLock(String endPoint) {
    final Boolean aBoolean = stringBooleanMap.get(endPoint);
    return aBoolean == null ? false : aBoolean;
  }

  public EndPointLock addEndPoint(String key, Boolean value) {
    this.stringBooleanMap.put(key, value);
    return this;
  }

  public boolean toggle(String endPointName) {
    final Boolean aBoolean = stringBooleanMap.get(endPointName);
    final boolean b = aBoolean == null;
    if (b) {
      throw new RuntimeException(format("End point name %s does not exists.", endPointName));
    }
    final boolean newBooleanValue = !aBoolean;
    stringBooleanMap.put(endPointName, newBooleanValue);
    return newBooleanValue;
  }

  public Map getEndPointLocks() {
    return stringBooleanMap;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy