com.ning.api.client.item.Fields Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ning-api-java Show documentation
Show all versions of ning-api-java Show documentation
Java client library for accessing Ning external API
package com.ning.api.client.item;
import java.util.*;
/**
* Base class for per-Item type field definition containers.
*
* @param Enumeration that defines fields that are to be contained
* in this container
*/
public final class Fields & Typed>
{
protected final Class enumClass;
protected final EnumSet included;
public Fields(Class enumClass)
{
this(enumClass, EnumSet.noneOf(enumClass));
}
public Fields(Class enumClass, F first, F... rest) {
this(enumClass, EnumSet.of(first, rest));
}
public Fields(Class enumClass, Collection fields) {
this(enumClass);
included.addAll(fields);
}
private Fields(Class enumClass, EnumSet fields)
{
this.enumClass = enumClass;
included = fields;
}
public Fields add(F field) {
included.add(field);
return this;
}
public Fields remove(F field) {
included.remove(field);
return this;
}
public boolean contains(F field) {
return included.contains(field);
}
public boolean isEmpty() {
return included.isEmpty();
}
public int size() {
return included.size();
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
Fields> other = (Fields>) o;
return (other.enumClass == enumClass) && included.equals(other.included);
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder(100);
for (F entry : included) {
if (sb.length() > 0) {
sb.append(',');
}
// important: use toString(), may have aliases
sb.append(entry.toString());
}
return sb.toString();
}
}