add helper method to know if ObjectMappers have a nested mapping

This commit is contained in:
Shay Banon 2013-02-25 13:40:05 +01:00
parent 6e3300efd3
commit c7a05b1dda
1 changed files with 18 additions and 6 deletions

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import com.google.common.collect.UnmodifiableIterator; import com.google.common.collect.UnmodifiableIterator;
import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.index.mapper.object.ObjectMapper;
@ -30,9 +29,10 @@ import org.elasticsearch.index.mapper.object.ObjectMapper;
public class ObjectMappers implements Iterable<ObjectMapper> { public class ObjectMappers implements Iterable<ObjectMapper> {
private final ImmutableList<ObjectMapper> objectMappers; private final ImmutableList<ObjectMapper> objectMappers;
private final boolean hasNested;
public ObjectMappers() { public ObjectMappers() {
this.objectMappers = ImmutableList.of(); this(ImmutableList.<ObjectMapper>of());
} }
public ObjectMappers(ObjectMapper objectMapper) { public ObjectMappers(ObjectMapper objectMapper) {
@ -40,14 +40,26 @@ public class ObjectMappers implements Iterable<ObjectMapper> {
} }
public ObjectMappers(ObjectMapper[] objectMappers) { public ObjectMappers(ObjectMapper[] objectMappers) {
if (objectMappers == null) { this(ImmutableList.copyOf(objectMappers));
objectMappers = new ObjectMapper[0];
}
this.objectMappers = ImmutableList.copyOf(Iterators.forArray(objectMappers));
} }
public ObjectMappers(ImmutableList<ObjectMapper> objectMappers) { public ObjectMappers(ImmutableList<ObjectMapper> objectMappers) {
this.objectMappers = objectMappers; this.objectMappers = objectMappers;
boolean hasNested = false;
for (ObjectMapper objectMapper : objectMappers) {
if (objectMapper.nested().isNested()) {
hasNested = true;
break;
}
}
this.hasNested = hasNested;
}
/**
* Is one of the object mappers has a nested mapping set?
*/
public boolean hasNested() {
return this.hasNested;
} }
public ObjectMapper mapper() { public ObjectMapper mapper() {