From 1dc985a2c4dcb905ea4680338e71791dfce226ff Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 10 Sep 2015 11:17:16 +0200 Subject: [PATCH] Remove ordinal member from Operator enum Use the already available enum ordinal instead. Closes #13456 --- .../elasticsearch/index/query/Operator.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/Operator.java b/core/src/main/java/org/elasticsearch/index/query/Operator.java index d114946aee7..22b54690686 100644 --- a/core/src/main/java/org/elasticsearch/index/query/Operator.java +++ b/core/src/main/java/org/elasticsearch/index/query/Operator.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.BooleanClause; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -29,16 +28,10 @@ import org.elasticsearch.common.util.CollectionUtils; import java.io.IOException; public enum Operator implements Writeable { - OR(0), AND(1); - - private final int ordinal; + OR, AND; private static final Operator PROTOTYPE = OR; - Operator(int ordinal) { - this.ordinal = ordinal; - } - public BooleanClause.Occur toBooleanClauseOccur() { switch (this) { case OR: @@ -63,13 +56,7 @@ public enum Operator implements Writeable { @Override public Operator readFrom(StreamInput in) throws IOException { - int ord = in.readVInt(); - for (Operator operator : Operator.values()) { - if (operator.ordinal == ord) { - return operator; - } - } - throw new ElasticsearchException("unknown serialized operator [" + ord + "]"); + return Operator.values()[in.readVInt()]; } public static Operator readOperatorFrom(StreamInput in) throws IOException { @@ -78,7 +65,7 @@ public enum Operator implements Writeable { @Override public void writeTo(StreamOutput out) throws IOException { - out.writeVInt(this.ordinal); + out.writeVInt(this.ordinal()); } public static Operator fromString(String op) {