/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.bbg.permission;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
/**
* A cache key used to hold the user ID and IP address for Bloomberg authentication.
*/
@BeanDefinition(builderScope = "private")
public final class IdentityCacheKey implements ImmutableBean {
/**
* The IP address.
*/
@PropertyDefinition(validate = "notNull")
private final String _ipAddress;
/**
* The user identifier.
*/
@PropertyDefinition(validate = "notNull")
private final String _userId;
/**
* Obtains an instance.
*
* @param ipAddress the IP address, not null
* @param userId the user identifier, not null
* @return the cache key, not null
*/
public static IdentityCacheKey of(String ipAddress, String userId) {
return new IdentityCacheKey(ipAddress, userId);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code IdentityCacheKey}.
* @return the meta-bean, not null
*/
public static IdentityCacheKey.Meta meta() {
return IdentityCacheKey.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(IdentityCacheKey.Meta.INSTANCE);
}
private IdentityCacheKey(
String ipAddress,
String userId) {
JodaBeanUtils.notNull(ipAddress, "ipAddress");
JodaBeanUtils.notNull(userId, "userId");
this._ipAddress = ipAddress;
this._userId = userId;
}
@Override
public IdentityCacheKey.Meta metaBean() {
return IdentityCacheKey.Meta.INSTANCE;
}
@Override
public <R> Property<R> property(String propertyName) {
return metaBean().<R>metaProperty(propertyName).createProperty(this);
}
@Override
public Set<String> propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the IP address.
* @return the value of the property, not null
*/
public String getIpAddress() {
return _ipAddress;
}
//-----------------------------------------------------------------------
/**
* Gets the user identifier.
* @return the value of the property, not null
*/
public String getUserId() {
return _userId;
}
//-----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
IdentityCacheKey other = (IdentityCacheKey) obj;
return JodaBeanUtils.equal(getIpAddress(), other.getIpAddress()) &&
JodaBeanUtils.equal(getUserId(), other.getUserId());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getIpAddress());
hash = hash * 31 + JodaBeanUtils.hashCode(getUserId());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("IdentityCacheKey{");
buf.append("ipAddress").append('=').append(getIpAddress()).append(',').append(' ');
buf.append("userId").append('=').append(JodaBeanUtils.toString(getUserId()));
buf.append('}');
return buf.toString();
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code IdentityCacheKey}.
*/
public static final class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code ipAddress} property.
*/
private final MetaProperty<String> _ipAddress = DirectMetaProperty.ofImmutable(
this, "ipAddress", IdentityCacheKey.class, String.class);
/**
* The meta-property for the {@code userId} property.
*/
private final MetaProperty<String> _userId = DirectMetaProperty.ofImmutable(
this, "userId", IdentityCacheKey.class, String.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"ipAddress",
"userId");
/**
* Restricted constructor.
*/
private Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 1634032845: // ipAddress
return _ipAddress;
case -836030906: // userId
return _userId;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends IdentityCacheKey> builder() {
return new IdentityCacheKey.Builder();
}
@Override
public Class<? extends IdentityCacheKey> beanType() {
return IdentityCacheKey.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code ipAddress} property.
* @return the meta-property, not null
*/
public MetaProperty<String> ipAddress() {
return _ipAddress;
}
/**
* The meta-property for the {@code userId} property.
* @return the meta-property, not null
*/
public MetaProperty<String> userId() {
return _userId;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 1634032845: // ipAddress
return ((IdentityCacheKey) bean).getIpAddress();
case -836030906: // userId
return ((IdentityCacheKey) bean).getUserId();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code IdentityCacheKey}.
*/
private static final class Builder extends DirectFieldsBeanBuilder<IdentityCacheKey> {
private String _ipAddress;
private String _userId;
/**
* Restricted constructor.
*/
private Builder() {
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 1634032845: // ipAddress
return _ipAddress;
case -836030906: // userId
return _userId;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 1634032845: // ipAddress
this._ipAddress = (String) newValue;
break;
case -836030906: // userId
this._userId = (String) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public Builder set(MetaProperty<?> property, Object value) {
super.set(property, value);
return this;
}
@Override
public Builder setString(String propertyName, String value) {
setString(meta().metaProperty(propertyName), value);
return this;
}
@Override
public Builder setString(MetaProperty<?> property, String value) {
super.setString(property, value);
return this;
}
@Override
public Builder setAll(Map<String, ? extends Object> propertyValueMap) {
super.setAll(propertyValueMap);
return this;
}
@Override
public IdentityCacheKey build() {
return new IdentityCacheKey(
_ipAddress,
_userId);
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("IdentityCacheKey.Builder{");
buf.append("ipAddress").append('=').append(JodaBeanUtils.toString(_ipAddress)).append(',').append(' ');
buf.append("userId").append('=').append(JodaBeanUtils.toString(_userId));
buf.append('}');
return buf.toString();
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}