No effective change - simplify ManyType to be an enum

This commit is contained in:
Robin Bygrave
2015-08-02 09:34:11 +12:00
parent 58a110e109
commit 9239d61c74
4 changed files with 17 additions and 57 deletions
@@ -19,7 +19,7 @@ public class BeanCollectionHelpFactory {
public static <T> BeanCollectionHelp<T> create(BeanPropertyAssocMany<T> manyProperty) {
ManyType manyType = manyProperty.getManyType();
switch (manyType.getUnderlying()) {
switch (manyType) {
case LIST:
return new BeanListHelp<T>(manyProperty);
case SET:
@@ -14,13 +14,13 @@ public class DetermineManyType {
public ManyType getManyType(Class<?> type) {
if (type.equals(List.class)) {
return ManyType.JAVA_LIST;
return ManyType.LIST;
}
if (type.equals(Set.class)) {
return ManyType.JAVA_SET;
return ManyType.SET;
}
if (type.equals(Map.class)) {
return ManyType.JAVA_MAP;
return ManyType.MAP;
}
return null;
}
@@ -1,7 +1,5 @@
package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebeaninternal.api.SpiQuery;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -9,62 +7,24 @@ import java.util.Set;
/**
* Represents the type of a OneToMany or ManyToMany property.
*/
public class ManyType {
public enum ManyType {
public static final ManyType JAVA_LIST = new ManyType(Underlying.LIST);
public static final ManyType JAVA_SET = new ManyType(Underlying.SET);
public static final ManyType JAVA_MAP = new ManyType(Underlying.MAP);
public enum Underlying {
LIST(List.class),
SET(Set.class),
MAP(null);
final Class<? extends Collection> type;
Underlying(Class<? extends Collection> type) {
this.type = type;
}
}
private final SpiQuery.Type queryType;
private final Underlying underlying;
LIST(false, List.class),
SET(false, Set.class),
MAP(true, null);
public ManyType(Underlying underlying) {
this.underlying = underlying;
switch (underlying) {
case LIST:
queryType = SpiQuery.Type.LIST;
break;
case SET:
queryType = SpiQuery.Type.SET;
break;
private final boolean map;
default:
queryType = SpiQuery.Type.MAP;
break;
}
private final Class<? extends Collection> type;
ManyType(boolean map, Class<? extends Collection> type) {
this.map = map;
this.type = type;
}
public boolean isMap() {
return Underlying.MAP.equals(underlying);
}
/**
* Return the matching Query type.
*/
public SpiQuery.Type getQueryType() {
return queryType;
}
/**
* Return the underlying type.
*/
public Underlying getUnderlying() {
return underlying;
return map;
}
/**
@@ -72,6 +32,6 @@ public class ManyType {
* Not intended to be called for maps.
*/
public Class<? extends Collection> getCollectionType() {
return underlying.type;
return type;
}
}
@@ -746,7 +746,7 @@ public final class DefaultPersister implements Persister {
// if a map, then we get the key value and
// set it to the appropriate property on the
// detail bean before we save it
boolean isMap = ManyType.JAVA_MAP.equals(prop.getManyType());
boolean isMap = ManyType.MAP.equals(prop.getManyType());
EntityBean parentBean = saveMany.getParentBean();
Object mapKeyValue = null;