Field implements Element { public static EnumSet<Constraint> getContraintEnumSet(boolean isRequired, boolean isDesSorted, boolean isAscSorted, boolean isFrequentlyUsed, boolean isDerived, boolean hasLargeList) { Preconditions.checkArgument(!(isDesSorted && isAscSorted), "No way to keep ASC sorting and DES sorting at the same time"); EnumSet<Constraint> ret; if (isRequired) { ret = EnumSet.of(Constraint.REQUIRED); } else { ret = EnumSet.of(Constraint.OPTIONAL); } if (isDesSorted) { ret.add(Constraint.DES_SORTED); } if (isAscSorted) { ret.add(Constraint.ASC_SORTED); } if (isFrequentlyUsed) { ret.add(Constraint.FREQUENTLY_USED); } if (isDerived) { ret.add(Constraint.DERIVED); } if (hasLargeList) { ret.add(Constraint.LARGE_LIST); } return ret; } private  Field(Builder builder); static Builder newBuilder(int id, String name, FieldType type); static EnumSet<Constraint> getContraintEnumSet(boolean isRequired,
                                                          boolean isDesSorted, boolean isAscSorted, boolean isFrequentlyUsed,
                                                          boolean isDerived, boolean hasLargeList); int getId(); String getName(); FieldType getType(); Object getDefaultValue(); EnumSet<Constraint> getConstraints(); boolean isRequired(); boolean isDesSortKey(); boolean isFrequentlyUsed(); boolean isDerived(); boolean isAscSortKey(); boolean hasLargeList(); boolean isSortKey(); @Override String toString(); @Override void accept(ElementVisitor visitor); boolean equalToDefaultValue(Object value); @Override int hashCode(); @Override boolean equals(Object obj); static final int DERIVED_FIELD_ID; }
@Test public void getContraintEnumSet() { boolean isRequired = false; boolean isDesSorted = false; boolean isAscSorted = false; boolean isFrequentlyUsed = false; boolean isDerived = false; boolean hasLargeList = false; EnumSet<Field.Constraint> constraints = Field.getContraintEnumSet( isRequired, isDesSorted, isAscSorted, isFrequentlyUsed, isDerived, hasLargeList); Assert.assertEquals(constraints, EnumSet.of(Field.Constraint.OPTIONAL)); isRequired = true; isDesSorted = false; isAscSorted = false; constraints = Field.getContraintEnumSet( isRequired, isDesSorted, isAscSorted, isFrequentlyUsed, isDerived, hasLargeList); Assert.assertEquals(constraints, EnumSet.of(Field.Constraint.REQUIRED)); isRequired = true; isDesSorted = true; isAscSorted = false; constraints = Field.getContraintEnumSet( isRequired, isDesSorted, isAscSorted, isFrequentlyUsed, isDerived, hasLargeList); Assert.assertEquals(constraints, EnumSet.of(Field.Constraint.REQUIRED, Field.Constraint.DES_SORTED)); }
@Test(expectedExceptions = java.lang.IllegalArgumentException.class) void checkDerived() { boolean isDesSorted = true; boolean isAscSorted = true; Field.getContraintEnumSet(false, isDesSorted, isAscSorted, false, false, false); }