@Test(expected = IllegalArgumentException.class) public void testCacheSizeRequiresSetField() { Map<String, Object> optionsMap = new HashMap<>(); optionsMap.put("type", "int"); optionsMap.put("cacheSize", 1000); FieldOptions options = FieldOptions.fromMap(optionsMap); }
public static FieldOptions fromMap(final Map<String, Object> map) { String fieldTypeStr = (String)map.get("type"); if (fieldTypeStr == null) { fieldTypeStr = FieldType.SET.toString(); } FieldType fieldType = FieldType.fromString(fieldTypeStr); Builder builder = builder(); builder.setFieldType(fieldType); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); switch (entry.getKey()) { case "type": continue; case "keys": builder.setKeys((Boolean)entry.getValue()); continue; case "cacheType": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheType option is valid only for set and mutex fields"); } CacheType cacheType = CacheType.fromString((String)value); builder.setCacheType(cacheType); continue; case "cacheSize": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheSize option is valid only for set and mutex fields"); } builder.setCacheSize(((Number) value).intValue()); continue; case "timeQuantum": if (!fieldType.equals(FieldType.TIME)) { throw new IllegalArgumentException("timeQuantum option is valid only for time fields"); } TimeQuantum timeQuantum = TimeQuantum.fromString((String)value); builder.setTimeQuantum(timeQuantum); continue; case "min": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("min option is valid only for int fields"); } builder.setMin(((Number) value).longValue()); continue; case "max": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("max option is valid only for int fields"); } builder.setMax(((Number) value).longValue()); continue; default: throw new IllegalArgumentException(String.format("Unknown field option: '%s'", entry.getKey())); } } return builder.build(); }
FieldOptions { public static FieldOptions fromMap(final Map<String, Object> map) { String fieldTypeStr = (String)map.get("type"); if (fieldTypeStr == null) { fieldTypeStr = FieldType.SET.toString(); } FieldType fieldType = FieldType.fromString(fieldTypeStr); Builder builder = builder(); builder.setFieldType(fieldType); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); switch (entry.getKey()) { case "type": continue; case "keys": builder.setKeys((Boolean)entry.getValue()); continue; case "cacheType": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheType option is valid only for set and mutex fields"); } CacheType cacheType = CacheType.fromString((String)value); builder.setCacheType(cacheType); continue; case "cacheSize": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheSize option is valid only for set and mutex fields"); } builder.setCacheSize(((Number) value).intValue()); continue; case "timeQuantum": if (!fieldType.equals(FieldType.TIME)) { throw new IllegalArgumentException("timeQuantum option is valid only for time fields"); } TimeQuantum timeQuantum = TimeQuantum.fromString((String)value); builder.setTimeQuantum(timeQuantum); continue; case "min": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("min option is valid only for int fields"); } builder.setMin(((Number) value).longValue()); continue; case "max": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("max option is valid only for int fields"); } builder.setMax(((Number) value).longValue()); continue; default: throw new IllegalArgumentException(String.format("Unknown field option: '%s'", entry.getKey())); } } return builder.build(); } }
FieldOptions { public static FieldOptions fromMap(final Map<String, Object> map) { String fieldTypeStr = (String)map.get("type"); if (fieldTypeStr == null) { fieldTypeStr = FieldType.SET.toString(); } FieldType fieldType = FieldType.fromString(fieldTypeStr); Builder builder = builder(); builder.setFieldType(fieldType); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); switch (entry.getKey()) { case "type": continue; case "keys": builder.setKeys((Boolean)entry.getValue()); continue; case "cacheType": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheType option is valid only for set and mutex fields"); } CacheType cacheType = CacheType.fromString((String)value); builder.setCacheType(cacheType); continue; case "cacheSize": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheSize option is valid only for set and mutex fields"); } builder.setCacheSize(((Number) value).intValue()); continue; case "timeQuantum": if (!fieldType.equals(FieldType.TIME)) { throw new IllegalArgumentException("timeQuantum option is valid only for time fields"); } TimeQuantum timeQuantum = TimeQuantum.fromString((String)value); builder.setTimeQuantum(timeQuantum); continue; case "min": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("min option is valid only for int fields"); } builder.setMin(((Number) value).longValue()); continue; case "max": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("max option is valid only for int fields"); } builder.setMax(((Number) value).longValue()); continue; default: throw new IllegalArgumentException(String.format("Unknown field option: '%s'", entry.getKey())); } } return builder.build(); } private  FieldOptions(final TimeQuantum timeQuantum,
                         final CacheType cacheType,
                         final Integer cacheSize,
                         final FieldType fieldType,
                         final long min,
                         final long max,
                         final Boolean keys); }
FieldOptions { public static FieldOptions fromMap(final Map<String, Object> map) { String fieldTypeStr = (String)map.get("type"); if (fieldTypeStr == null) { fieldTypeStr = FieldType.SET.toString(); } FieldType fieldType = FieldType.fromString(fieldTypeStr); Builder builder = builder(); builder.setFieldType(fieldType); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); switch (entry.getKey()) { case "type": continue; case "keys": builder.setKeys((Boolean)entry.getValue()); continue; case "cacheType": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheType option is valid only for set and mutex fields"); } CacheType cacheType = CacheType.fromString((String)value); builder.setCacheType(cacheType); continue; case "cacheSize": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheSize option is valid only for set and mutex fields"); } builder.setCacheSize(((Number) value).intValue()); continue; case "timeQuantum": if (!fieldType.equals(FieldType.TIME)) { throw new IllegalArgumentException("timeQuantum option is valid only for time fields"); } TimeQuantum timeQuantum = TimeQuantum.fromString((String)value); builder.setTimeQuantum(timeQuantum); continue; case "min": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("min option is valid only for int fields"); } builder.setMin(((Number) value).longValue()); continue; case "max": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("max option is valid only for int fields"); } builder.setMax(((Number) value).longValue()); continue; default: throw new IllegalArgumentException(String.format("Unknown field option: '%s'", entry.getKey())); } } return builder.build(); } private  FieldOptions(final TimeQuantum timeQuantum,
                         final CacheType cacheType,
                         final Integer cacheSize,
                         final FieldType fieldType,
                         final long min,
                         final long max,
                         final Boolean keys); @SuppressWarnings("WeakerAccess") static FieldOptions withDefaults(); static FieldOptions fromMap(final Map<String, Object> map); static Builder builder(); TimeQuantum getTimeQuantum(); CacheType getCacheType(); int getCacheSize(); FieldType getFieldType(); long getMin(); long getMax(); boolean isKeys(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); }
FieldOptions { public static FieldOptions fromMap(final Map<String, Object> map) { String fieldTypeStr = (String)map.get("type"); if (fieldTypeStr == null) { fieldTypeStr = FieldType.SET.toString(); } FieldType fieldType = FieldType.fromString(fieldTypeStr); Builder builder = builder(); builder.setFieldType(fieldType); for (Map.Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); switch (entry.getKey()) { case "type": continue; case "keys": builder.setKeys((Boolean)entry.getValue()); continue; case "cacheType": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheType option is valid only for set and mutex fields"); } CacheType cacheType = CacheType.fromString((String)value); builder.setCacheType(cacheType); continue; case "cacheSize": if (!fieldType.equals(FieldType.SET) && !fieldType.equals(FieldType.MUTEX)) { throw new IllegalArgumentException("cacheSize option is valid only for set and mutex fields"); } builder.setCacheSize(((Number) value).intValue()); continue; case "timeQuantum": if (!fieldType.equals(FieldType.TIME)) { throw new IllegalArgumentException("timeQuantum option is valid only for time fields"); } TimeQuantum timeQuantum = TimeQuantum.fromString((String)value); builder.setTimeQuantum(timeQuantum); continue; case "min": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("min option is valid only for int fields"); } builder.setMin(((Number) value).longValue()); continue; case "max": if (!fieldType.equals(FieldType.INT)) { throw new IllegalArgumentException("max option is valid only for int fields"); } builder.setMax(((Number) value).longValue()); continue; default: throw new IllegalArgumentException(String.format("Unknown field option: '%s'", entry.getKey())); } } return builder.build(); } private  FieldOptions(final TimeQuantum timeQuantum,
                         final CacheType cacheType,
                         final Integer cacheSize,
                         final FieldType fieldType,
                         final long min,
                         final long max,
                         final Boolean keys); @SuppressWarnings("WeakerAccess") static FieldOptions withDefaults(); static FieldOptions fromMap(final Map<String, Object> map); static Builder builder(); TimeQuantum getTimeQuantum(); CacheType getCacheType(); int getCacheSize(); FieldType getFieldType(); long getMin(); long getMax(); boolean isKeys(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }