mirror of https://github.com/apache/lucene.git
Implement readResolve, needed for serializable "enumerations"
PR:31174 Submitted by:Todd VanderVeen git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150503 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
515cf2153a
commit
3eeda4437d
|
@ -1,5 +1,8 @@
|
||||||
package org.apache.lucene.search;
|
package org.apache.lucene.search;
|
||||||
|
|
||||||
|
import java.io.ObjectStreamException;
|
||||||
|
import java.io.StreamCorruptedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2004 The Apache Software Foundation
|
* Copyright 2004 The Apache Software Foundation
|
||||||
*
|
*
|
||||||
|
@ -21,14 +24,19 @@ public class BooleanClause implements java.io.Serializable {
|
||||||
|
|
||||||
public static final class Occur implements java.io.Serializable {
|
public static final class Occur implements java.io.Serializable {
|
||||||
|
|
||||||
|
private int id;
|
||||||
private String name;
|
private String name;
|
||||||
|
private static final int MUST_ID = 0;
|
||||||
|
private static final int MUST_NOT_ID = 1;
|
||||||
|
private static final int SHOULD_ID = 2;
|
||||||
|
|
||||||
private Occur() {
|
private Occur() {
|
||||||
// typesafe enum pattern, no public constructor
|
// typesafe enum pattern, no public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
private Occur(String name) {
|
private Occur(int id, String name) {
|
||||||
// typesafe enum pattern, no public constructor
|
// typesafe enum pattern, no public constructor
|
||||||
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,15 +45,36 @@ public class BooleanClause implements java.io.Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Use this operator for terms that <i>must</i> appear in the matching documents. */
|
/** Use this operator for terms that <i>must</i> appear in the matching documents. */
|
||||||
public static final Occur MUST = new Occur("MUST");
|
public static final Occur MUST = new Occur(MUST_ID, "MUST");
|
||||||
/** Use this operator for terms of which <i>should</i> appear in the
|
/** Use this operator for terms of which <i>should</i> appear in the
|
||||||
* matching documents. For a BooleanQuery with two <code>SHOULD</code>
|
* matching documents. For a BooleanQuery with two <code>SHOULD</code>
|
||||||
* subqueries, at least one of the queries must appear in the matching documents. */
|
* subqueries, at least one of the queries must appear in the matching documents. */
|
||||||
public static final Occur SHOULD = new Occur("SHOULD");
|
public static final Occur SHOULD = new Occur(SHOULD_ID, "SHOULD");
|
||||||
/** Use this operator for terms that <i>must not</i> appear in the matching documents.
|
/** Use this operator for terms that <i>must not</i> appear in the matching documents.
|
||||||
* Note that it is not possible to search for queries that only consist
|
* Note that it is not possible to search for queries that only consist
|
||||||
* of a <code>MUST_NOT</code> query. */
|
* of a <code>MUST_NOT</code> query. */
|
||||||
public static final Occur MUST_NOT = new Occur("MUST_NOT");
|
public static final Occur MUST_NOT = new Occur(MUST_NOT_ID, "MUST_NOT");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the deserialized instance to the local reference for accurate
|
||||||
|
* equals() and == comparisons.
|
||||||
|
*
|
||||||
|
* @return a reference to Occur as resolved in the local VM
|
||||||
|
* @throws ObjectStreamException
|
||||||
|
*/
|
||||||
|
private Object readResolve() throws ObjectStreamException {
|
||||||
|
int id = ((Occur) this).id;
|
||||||
|
switch (id) {
|
||||||
|
case MUST_ID :
|
||||||
|
return Occur.MUST;
|
||||||
|
case MUST_NOT_ID :
|
||||||
|
return Occur.MUST_NOT;
|
||||||
|
case SHOULD_ID:
|
||||||
|
return Occur.SHOULD;
|
||||||
|
default :
|
||||||
|
throw new StreamCorruptedException("Unknown id " + id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue