
org.robobinding.attribute.PendingGroupAttributes Maven / Gradle / Ivy
package org.robobinding.attribute;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
/**
*
* @since 1.0
* @version $Revision: 1.0 $
* @author Robert Taylor
* @author Cheng Wei
*/
public class PendingGroupAttributes {
private final Map presentAttributeMappings;
public PendingGroupAttributes(Map presentAttributeMappings) {
this.presentAttributeMappings = Maps.newHashMap(presentAttributeMappings);
}
Iterable> presentAttributes() {
return presentAttributeMappings.entrySet();
}
public void assertAttributesArePresent(String... attributeNames) {
if (!hasAttributes(attributeNames))
throw new MissingRequiredAttributesException(findAbsentAttributes(attributeNames));
}
private boolean hasAttributes(String... attributes) {
for (String attribute : attributes) {
if (!presentAttributeMappings.containsKey(attribute)) {
return false;
}
}
return true;
}
private Collection findAbsentAttributes(String... attributeNames) {
List absentAttributes = Lists.newArrayList();
for (String attributeName : attributeNames) {
if (!presentAttributeMappings.containsKey(attributeName)) {
absentAttributes.add(attributeName);
}
}
return absentAttributes;
}
@Override
public boolean equals(Object other) {
if (this == other)
return true;
if (!(other instanceof PendingGroupAttributes))
return false;
final PendingGroupAttributes that = (PendingGroupAttributes) other;
return Objects.equal(presentAttributeMappings, that.presentAttributeMappings);
}
@Override
public int hashCode() {
return Objects.hashCode(presentAttributeMappings);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy