lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r712922 [9/9] - in /lucene/java/trunk: contrib/analyzers/src/java/org/apache/lucene/analysis/el/ contrib/analyzers/src/java/org/apache/lucene/analysis/fr/ contrib/analyzers/src/java/org/apache/lucene/analysis/miscellaneous/ contrib/analyzer...
Date Tue, 11 Nov 2008 02:35:52 GMT
Modified: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsQueryBuilder.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsQueryBuilder.java (original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsQueryBuilder.java Mon Nov 10 18:35:46 2008
@@ -1,85 +1,85 @@
-package org.apache.lucene.xmlparser.builders;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.Token;
-import org.apache.lucene.analysis.TokenStream;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.xmlparser.DOMUtils;
-import org.apache.lucene.xmlparser.ParserException;
-import org.apache.lucene.xmlparser.QueryBuilder;
-import org.w3c.dom.Element;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * Builds a BooleanQuery from all of the terms found in the XML element using the choice of analyzer
- */
-public class TermsQueryBuilder implements QueryBuilder {
-
-	Analyzer analyzer;
-
-		
-	public TermsQueryBuilder(Analyzer analyzer)
-	{
-		this.analyzer = analyzer;
-	}
-
-
-
-	public Query getQuery(Element e) throws ParserException {
-		
-        String fieldName=DOMUtils.getAttributeWithInheritanceOrFail(e,"fieldName");
- 		String text=DOMUtils.getNonBlankTextOrFail(e);
- 		
-		BooleanQuery bq=new BooleanQuery(DOMUtils.getAttribute(e,"disableCoord",false));
-		bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e,"minimumNumberShouldMatch",0));
-		TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
-		try
-		{
-                  final Token reusableToken = new Token();
-			Term term = null;
-	                for (Token nextToken = ts.next(reusableToken); nextToken != null; nextToken = ts.next(reusableToken)) {
-				if (term == null)
-				{
-					term = new Term(fieldName, nextToken.term());
-				} else
-				{
-//					 create from previous to save fieldName.intern overhead
-					term = term.createTerm(nextToken.term()); 
-				}
-				bq.add(new BooleanClause(new TermQuery(term),BooleanClause.Occur.SHOULD));
-			}
-		} 
-		catch (IOException ioe)
-		{
-			throw new RuntimeException("Error constructing terms from index:"
-					+ ioe);
-		}
-  		bq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
-
-  		return bq;
-		
-	}
-
-}
+package org.apache.lucene.xmlparser.builders;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Builds a BooleanQuery from all of the terms found in the XML element using the choice of analyzer
+ */
+public class TermsQueryBuilder implements QueryBuilder {
+
+	Analyzer analyzer;
+
+		
+	public TermsQueryBuilder(Analyzer analyzer)
+	{
+		this.analyzer = analyzer;
+	}
+
+
+
+	public Query getQuery(Element e) throws ParserException {
+		
+        String fieldName=DOMUtils.getAttributeWithInheritanceOrFail(e,"fieldName");
+ 		String text=DOMUtils.getNonBlankTextOrFail(e);
+ 		
+		BooleanQuery bq=new BooleanQuery(DOMUtils.getAttribute(e,"disableCoord",false));
+		bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e,"minimumNumberShouldMatch",0));
+		TokenStream ts = analyzer.tokenStream(fieldName, new StringReader(text));
+		try
+		{
+                  final Token reusableToken = new Token();
+			Term term = null;
+	                for (Token nextToken = ts.next(reusableToken); nextToken != null; nextToken = ts.next(reusableToken)) {
+				if (term == null)
+				{
+					term = new Term(fieldName, nextToken.term());
+				} else
+				{
+//					 create from previous to save fieldName.intern overhead
+					term = term.createTerm(nextToken.term()); 
+				}
+				bq.add(new BooleanClause(new TermQuery(term),BooleanClause.Occur.SHOULD));
+			}
+		} 
+		catch (IOException ioe)
+		{
+			throw new RuntimeException("Error constructing terms from index:"
+					+ ioe);
+		}
+  		bq.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+
+  		return bq;
+		
+	}
+
+}

Propchange: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/TermsQueryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java (original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java Mon Nov 10 18:35:46 2008
@@ -1,94 +1,94 @@
-package org.apache.lucene.xmlparser.builders;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.xmlparser.DOMUtils;
-import org.apache.lucene.xmlparser.ParserException;
-import org.apache.lucene.xmlparser.QueryBuilder;
-import org.w3c.dom.Element;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * UserInputQueryBuilder uses 1 of 2 strategies for thread-safe parsing:
- * 1) Synchronizing access to "parse" calls on a previously supplied QueryParser
- * or..
- * 2) creating a new QueryParser object for each parse request
- */
-public class UserInputQueryBuilder implements QueryBuilder {
-
-	QueryParser unSafeParser;
-	private Analyzer analyzer;
-	private String defaultField;
-	
-	/**
-	 * This constructor has the disadvantage of not being able to change choice of default field name
-	 * @param parser thread un-safe query parser
-	 */
-	public UserInputQueryBuilder(QueryParser parser) {
-		this.unSafeParser = parser;
-	}
-
-	public UserInputQueryBuilder(String defaultField, Analyzer analyzer) {
-		this.analyzer = analyzer;
-		this.defaultField = defaultField;
-	}
-	
-	/* (non-Javadoc)
-	 * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
-	 */
-	public Query getQuery(Element e) throws ParserException {
-		String text=DOMUtils.getText(e);
-		try {
-			Query q = null;
-			if(unSafeParser!=null)
-			{
-				//synchronize on unsafe parser
-				synchronized (unSafeParser)
-				{
-					q = unSafeParser.parse(text);
-				}
-			}
-			else
-			{
-				String fieldName=DOMUtils.getAttribute(e, "fieldName", defaultField);
-				//Create new parser
-				QueryParser parser=createQueryParser(fieldName, analyzer);
-				q = parser.parse(text);				
-			}
-			q.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
-			return q;
-		} catch (ParseException e1) {
-			throw new ParserException(e1.getMessage());
-		}
-	}
-	
-	/**
-	 * Method to create a QueryParser - designed to be overridden
-	 * @param fieldName
-	 * @param analyzer
-	 * @return
-	 */
-	protected QueryParser createQueryParser(String fieldName, Analyzer analyzer)
-	{
-		return new QueryParser(fieldName,analyzer);
-	}
-
-}
+package org.apache.lucene.xmlparser.builders;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.xmlparser.DOMUtils;
+import org.apache.lucene.xmlparser.ParserException;
+import org.apache.lucene.xmlparser.QueryBuilder;
+import org.w3c.dom.Element;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * UserInputQueryBuilder uses 1 of 2 strategies for thread-safe parsing:
+ * 1) Synchronizing access to "parse" calls on a previously supplied QueryParser
+ * or..
+ * 2) creating a new QueryParser object for each parse request
+ */
+public class UserInputQueryBuilder implements QueryBuilder {
+
+	QueryParser unSafeParser;
+	private Analyzer analyzer;
+	private String defaultField;
+	
+	/**
+	 * This constructor has the disadvantage of not being able to change choice of default field name
+	 * @param parser thread un-safe query parser
+	 */
+	public UserInputQueryBuilder(QueryParser parser) {
+		this.unSafeParser = parser;
+	}
+
+	public UserInputQueryBuilder(String defaultField, Analyzer analyzer) {
+		this.analyzer = analyzer;
+		this.defaultField = defaultField;
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
+	 */
+	public Query getQuery(Element e) throws ParserException {
+		String text=DOMUtils.getText(e);
+		try {
+			Query q = null;
+			if(unSafeParser!=null)
+			{
+				//synchronize on unsafe parser
+				synchronized (unSafeParser)
+				{
+					q = unSafeParser.parse(text);
+				}
+			}
+			else
+			{
+				String fieldName=DOMUtils.getAttribute(e, "fieldName", defaultField);
+				//Create new parser
+				QueryParser parser=createQueryParser(fieldName, analyzer);
+				q = parser.parse(text);				
+			}
+			q.setBoost(DOMUtils.getAttribute(e,"boost",1.0f));
+			return q;
+		} catch (ParseException e1) {
+			throw new ParserException(e1.getMessage());
+		}
+	}
+	
+	/**
+	 * Method to create a QueryParser - designed to be overridden
+	 * @param fieldName
+	 * @param analyzer
+	 * @return
+	 */
+	protected QueryParser createQueryParser(String fieldName, Analyzer analyzer)
+	{
+		return new QueryParser(fieldName,analyzer);
+	}
+
+}

Propchange: lucene/java/trunk/contrib/xml-query-parser/src/java/org/apache/lucene/xmlparser/builders/UserInputQueryBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java (original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java Mon Nov 10 18:35:46 2008
@@ -1,215 +1,215 @@
-package org.apache.lucene.xmlparser;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import junit.framework.TestCase;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.RAMDirectory;
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-public class TestParser extends TestCase {
-
-	CoreParser builder;
-	static Directory dir;
-	Analyzer analyzer=new StandardAnalyzer();
-	IndexReader reader;
-	private IndexSearcher searcher;
-	
-	//CHANGE THIS TO SEE OUTPUT
-	boolean printResults=false;
-	
-	
-	/*
-	 * @see TestCase#setUp()
-	 */
-	protected void setUp() throws Exception {
-		super.setUp();
-		
-		//initialize the parser
-		builder=new CorePlusExtensionsParser("contents",analyzer);
-		
-		//initialize the index (done once, then cached in static data for use with ALL tests)		
-		if(dir==null)
-		{
-			BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt"))); 
-			dir=new RAMDirectory();
-			IndexWriter writer=new IndexWriter(dir,analyzer,true);
-			String line = d.readLine();		
-			while(line!=null)
-			{
-				int endOfDate=line.indexOf('\t');
-				String date=line.substring(0,endOfDate).trim();
-				String content=line.substring(endOfDate).trim();
-				org.apache.lucene.document.Document doc =new org.apache.lucene.document.Document();
-				doc.add(new Field("date",date,Field.Store.YES,Field.Index.ANALYZED));
-				doc.add(new Field("contents",content,Field.Store.YES,Field.Index.ANALYZED));
-				writer.addDocument(doc);
-				line=d.readLine();
-			}			
-			d.close();
-                        writer.close();
-		}
-		reader=IndexReader.open(dir);
-		searcher=new IndexSearcher(reader);
-		
-	}
-	
-	
-	
-	
-	protected void tearDown() throws Exception {
-		reader.close();
-		searcher.close();
-//		dir.close();
-		
-	}
-	public void testSimpleXML() throws ParserException, IOException
-	{
-			Query q=parse("TermQuery.xml");
-			dumpResults("TermQuery", q, 5);
-	}
-	public void testSimpleTermsQueryXML() throws ParserException, IOException
-	{
-			Query q=parse("TermsQuery.xml");
-			dumpResults("TermsQuery", q, 5);
-	}
-	public void testBooleanQueryXML() throws ParserException, IOException
-	{
-			Query q=parse("BooleanQuery.xml");
-			dumpResults("BooleanQuery", q, 5);
-	}
-	public void testRangeFilterQueryXML() throws ParserException, IOException
-	{
-			Query q=parse("RangeFilterQuery.xml");
-			dumpResults("RangeFilter", q, 5);
-	}
-	public void testUserQueryXML() throws ParserException, IOException
-	{
-			Query q=parse("UserInputQuery.xml");
-			dumpResults("UserInput with Filter", q, 5);
-	}
-	
-	public void testCustomFieldUserQueryXML() throws ParserException, IOException
-	{
-			Query q=parse("UserInputQueryCustomField.xml");
-			Hits h = searcher.search(q);
-			assertEquals("UserInputQueryCustomField should produce 0 result ", 0,h.length());
-	}
-	
-	public void testLikeThisQueryXML() throws Exception
-	{
-			Query q=parse("LikeThisQuery.xml");
-			dumpResults("like this", q, 5);
-	}
-	public void testBoostingQueryXML() throws Exception
-	{
-			Query q=parse("BoostingQuery.xml");
-			dumpResults("boosting ",q, 5);
-	}
-	public void testFuzzyLikeThisQueryXML() throws Exception
-	{
-			Query q=parse("FuzzyLikeThisQuery.xml");
-			//show rewritten fuzzyLikeThisQuery - see what is being matched on
-			if(printResults)
-			{
-				System.out.println(q.rewrite(reader));
-			}
-			dumpResults("FuzzyLikeThis", q, 5);
-	}
-	public void testTermsFilterXML() throws Exception
-	{
-			Query q=parse("TermsFilterQuery.xml");
-			dumpResults("Terms Filter",q, 5);
-	}
-	public void testSpanTermXML() throws Exception
-	{
-			Query q=parse("SpanQuery.xml");
-			dumpResults("Span Query",q, 5);
-	}
-	public void testConstantScoreQueryXML() throws Exception
-	{
-			Query q=parse("ConstantScoreQuery.xml");
-			dumpResults("ConstantScoreQuery",q, 5);
-	}
-	public void testMatchAllDocsPlusFilterXML() throws ParserException, IOException
-	{
-			Query q=parse("MatchAllDocsQuery.xml");
-			dumpResults("MatchAllDocsQuery with range filter", q, 5);
-	}
-	public void testBooleanFilterXML() throws ParserException, IOException
-	{
-			Query q=parse("BooleanFilter.xml");
-			dumpResults("Boolean filter", q, 5);
-	}
-	public void testNestedBooleanQuery() throws ParserException, IOException
-	{
-			Query q=parse("NestedBooleanQuery.xml");
-			dumpResults("Nested Boolean query", q, 5);
-	}
-	public void testCachedFilterXML() throws ParserException, IOException
-	{
-			Query q=parse("CachedFilter.xml");
-			dumpResults("Cached filter", q, 5);
-	}
-	public void testDuplicateFilterQueryXML() throws ParserException, IOException
-	{
-			Query q=parse("DuplicateFilterQuery.xml");
-			Hits h = searcher.search(q);
-			assertEquals("DuplicateFilterQuery should produce 1 result ", 1,h.length());
-	}
-	
-
-
-	//================= Helper methods ===================================
-	private Query parse(String xmlFileName) throws ParserException, IOException
-	{
-		InputStream xmlStream=TestParser.class.getResourceAsStream(xmlFileName);
-		Query result=builder.parse(xmlStream);
-		xmlStream.close();
-		return result;
-	}
-	private void dumpResults(String qType,Query q, int numDocs) throws IOException
-	{
-		Hits h = searcher.search(q);
-		assertTrue(qType +" should produce results ", h.length()>0);
-		if(printResults)
-		{
-			System.out.println("========="+qType+"============");
-			for(int i=0;i<Math.min(numDocs,h.length());i++)
-			{
-				org.apache.lucene.document.Document ldoc=h.doc(i);
-				System.out.println("["+ldoc.get("date")+"]"+ldoc.get("contents"));
-			}
-			System.out.println();
-		}
-	}
-	
-
-}
+package org.apache.lucene.xmlparser;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class TestParser extends TestCase {
+
+	CoreParser builder;
+	static Directory dir;
+	Analyzer analyzer=new StandardAnalyzer();
+	IndexReader reader;
+	private IndexSearcher searcher;
+	
+	//CHANGE THIS TO SEE OUTPUT
+	boolean printResults=false;
+	
+	
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		
+		//initialize the parser
+		builder=new CorePlusExtensionsParser("contents",analyzer);
+		
+		//initialize the index (done once, then cached in static data for use with ALL tests)		
+		if(dir==null)
+		{
+			BufferedReader d = new BufferedReader(new InputStreamReader(TestParser.class.getResourceAsStream("reuters21578.txt"))); 
+			dir=new RAMDirectory();
+			IndexWriter writer=new IndexWriter(dir,analyzer,true);
+			String line = d.readLine();		
+			while(line!=null)
+			{
+				int endOfDate=line.indexOf('\t');
+				String date=line.substring(0,endOfDate).trim();
+				String content=line.substring(endOfDate).trim();
+				org.apache.lucene.document.Document doc =new org.apache.lucene.document.Document();
+				doc.add(new Field("date",date,Field.Store.YES,Field.Index.ANALYZED));
+				doc.add(new Field("contents",content,Field.Store.YES,Field.Index.ANALYZED));
+				writer.addDocument(doc);
+				line=d.readLine();
+			}			
+			d.close();
+                        writer.close();
+		}
+		reader=IndexReader.open(dir);
+		searcher=new IndexSearcher(reader);
+		
+	}
+	
+	
+	
+	
+	protected void tearDown() throws Exception {
+		reader.close();
+		searcher.close();
+//		dir.close();
+		
+	}
+	public void testSimpleXML() throws ParserException, IOException
+	{
+			Query q=parse("TermQuery.xml");
+			dumpResults("TermQuery", q, 5);
+	}
+	public void testSimpleTermsQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("TermsQuery.xml");
+			dumpResults("TermsQuery", q, 5);
+	}
+	public void testBooleanQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("BooleanQuery.xml");
+			dumpResults("BooleanQuery", q, 5);
+	}
+	public void testRangeFilterQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("RangeFilterQuery.xml");
+			dumpResults("RangeFilter", q, 5);
+	}
+	public void testUserQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("UserInputQuery.xml");
+			dumpResults("UserInput with Filter", q, 5);
+	}
+	
+	public void testCustomFieldUserQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("UserInputQueryCustomField.xml");
+			Hits h = searcher.search(q);
+			assertEquals("UserInputQueryCustomField should produce 0 result ", 0,h.length());
+	}
+	
+	public void testLikeThisQueryXML() throws Exception
+	{
+			Query q=parse("LikeThisQuery.xml");
+			dumpResults("like this", q, 5);
+	}
+	public void testBoostingQueryXML() throws Exception
+	{
+			Query q=parse("BoostingQuery.xml");
+			dumpResults("boosting ",q, 5);
+	}
+	public void testFuzzyLikeThisQueryXML() throws Exception
+	{
+			Query q=parse("FuzzyLikeThisQuery.xml");
+			//show rewritten fuzzyLikeThisQuery - see what is being matched on
+			if(printResults)
+			{
+				System.out.println(q.rewrite(reader));
+			}
+			dumpResults("FuzzyLikeThis", q, 5);
+	}
+	public void testTermsFilterXML() throws Exception
+	{
+			Query q=parse("TermsFilterQuery.xml");
+			dumpResults("Terms Filter",q, 5);
+	}
+	public void testSpanTermXML() throws Exception
+	{
+			Query q=parse("SpanQuery.xml");
+			dumpResults("Span Query",q, 5);
+	}
+	public void testConstantScoreQueryXML() throws Exception
+	{
+			Query q=parse("ConstantScoreQuery.xml");
+			dumpResults("ConstantScoreQuery",q, 5);
+	}
+	public void testMatchAllDocsPlusFilterXML() throws ParserException, IOException
+	{
+			Query q=parse("MatchAllDocsQuery.xml");
+			dumpResults("MatchAllDocsQuery with range filter", q, 5);
+	}
+	public void testBooleanFilterXML() throws ParserException, IOException
+	{
+			Query q=parse("BooleanFilter.xml");
+			dumpResults("Boolean filter", q, 5);
+	}
+	public void testNestedBooleanQuery() throws ParserException, IOException
+	{
+			Query q=parse("NestedBooleanQuery.xml");
+			dumpResults("Nested Boolean query", q, 5);
+	}
+	public void testCachedFilterXML() throws ParserException, IOException
+	{
+			Query q=parse("CachedFilter.xml");
+			dumpResults("Cached filter", q, 5);
+	}
+	public void testDuplicateFilterQueryXML() throws ParserException, IOException
+	{
+			Query q=parse("DuplicateFilterQuery.xml");
+			Hits h = searcher.search(q);
+			assertEquals("DuplicateFilterQuery should produce 1 result ", 1,h.length());
+	}
+	
+
+
+	//================= Helper methods ===================================
+	private Query parse(String xmlFileName) throws ParserException, IOException
+	{
+		InputStream xmlStream=TestParser.class.getResourceAsStream(xmlFileName);
+		Query result=builder.parse(xmlStream);
+		xmlStream.close();
+		return result;
+	}
+	private void dumpResults(String qType,Query q, int numDocs) throws IOException
+	{
+		Hits h = searcher.search(q);
+		assertTrue(qType +" should produce results ", h.length()>0);
+		if(printResults)
+		{
+			System.out.println("========="+qType+"============");
+			for(int i=0;i<Math.min(numDocs,h.length());i++)
+			{
+				org.apache.lucene.document.Document ldoc=h.doc(i);
+				System.out.println("["+ldoc.get("date")+"]"+ldoc.get("contents"));
+			}
+			System.out.println();
+		}
+	}
+	
+
+}

Propchange: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java (original)
+++ lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java Mon Nov 10 18:35:46 2008
@@ -1,163 +1,163 @@
-package org.apache.lucene.xmlparser;
-
-import java.io.IOException;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-
-import junit.framework.TestCase;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Field;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.store.RAMDirectory;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * This class illustrates how form input (such as from a web page or Swing gui) can be
- * turned into Lucene queries using a choice of XSL templates for different styles of queries.
- */
-public class TestQueryTemplateManager extends TestCase {
-
-	CoreParser builder;
-	Analyzer analyzer=new StandardAnalyzer();
-	private IndexSearcher searcher;
-	
-	//A collection of documents' field values for use in our tests
-	String docFieldValues []=
-	{
-			"artist=Jeff Buckley \talbum=Grace \treleaseDate=1999 \tgenre=rock",
-			"artist=Fugazi \talbum=Repeater \treleaseDate=1990 \tgenre=alternative",
-			"artist=Fugazi \talbum=Red Medicine \treleaseDate=1995 \tgenre=alternative",
-			"artist=Peeping Tom \talbum=Peeping Tom \treleaseDate=2006 \tgenre=rock",
-			"artist=Red Snapper \talbum=Prince Blimey \treleaseDate=1996 \tgenre=electronic"
-	};
-	
-	//A collection of example queries, consisting of name/value pairs representing form content plus 
-	// a choice of query style template to use in the test, with expected number of hits
-	String queryForms[]=
-	{
-			"artist=Fugazi \texpectedMatches=2 \ttemplate=albumBooleanQuery",
-			"artist=Fugazi \treleaseDate=1990 \texpectedMatches=1 \ttemplate=albumBooleanQuery",
-			"artist=Buckley \tgenre=rock \texpectedMatches=1 \ttemplate=albumFilteredQuery",
-			"artist=Buckley \tgenre=electronic \texpectedMatches=0 \ttemplate=albumFilteredQuery",
-			"queryString=artist:buckly~ NOT genre:electronic \texpectedMatches=1 \ttemplate=albumLuceneClassicQuery"
-	};
-	
-	
-	public void testFormTransforms() throws SAXException, IOException, ParserConfigurationException, TransformerException, ParserException 
-	{
-		//Cache all the query templates we will be referring to.
-		QueryTemplateManager qtm=new QueryTemplateManager();
-		qtm.addQueryTemplate("albumBooleanQuery", getClass().getResourceAsStream("albumBooleanQuery.xsl"));
-		qtm.addQueryTemplate("albumFilteredQuery", getClass().getResourceAsStream("albumFilteredQuery.xsl"));
-		qtm.addQueryTemplate("albumLuceneClassicQuery", getClass().getResourceAsStream("albumLuceneClassicQuery.xsl"));
-		//Run all of our test queries
-		for (int i = 0; i < queryForms.length; i++)
-		{
-			Properties queryFormProperties=getPropsFromString(queryForms[i]);
-			
-			//Get the required query XSL template for this test
-//			Templates template=getTemplate(queryFormProperties.getProperty("template"));
-			
-			//Transform the queryFormProperties into a Lucene XML query
-			Document doc=qtm.getQueryAsDOM(queryFormProperties,queryFormProperties.getProperty("template"));
-			
-			//Parse the XML query using the XML parser
-			Query q=builder.getQuery(doc.getDocumentElement());
-			
-			//Run the query
-			Hits h=searcher.search(q);
-			
-			//Check we have the expected number of results
-			int expectedHits=Integer.parseInt(queryFormProperties.getProperty("expectedMatches"));
-			assertEquals("Number of results should match for query "+queryForms[i],expectedHits,h.length());
-			
-		}
-	}
-	
-	//Helper method to construct Lucene query forms used in our test
-	Properties getPropsFromString(String nameValuePairs)
-	{
-		Properties result=new Properties();
-		StringTokenizer st=new StringTokenizer(nameValuePairs,"\t=");
-		while(st.hasMoreTokens())
-		{
-			String name=st.nextToken().trim();
-			if(st.hasMoreTokens())
-			{
-				String value=st.nextToken().trim();
-				result.setProperty(name,value);
-			}
-		}
-		return result;
-	}
-	
-	//Helper method to construct Lucene documents used in our tests
-	org.apache.lucene.document.Document getDocumentFromString(String nameValuePairs)
-	{
-		org.apache.lucene.document.Document result=new org.apache.lucene.document.Document();
-		StringTokenizer st=new StringTokenizer(nameValuePairs,"\t=");
-		while(st.hasMoreTokens())
-		{
-			String name=st.nextToken().trim();
-			if(st.hasMoreTokens())
-			{
-				String value=st.nextToken().trim();
-				result.add(new Field(name,value,Field.Store.YES,Field.Index.ANALYZED));
-			}
-		}
-		return result;
-	}
-	
-	/*
-	 * @see TestCase#setUp()
-	 */
-	protected void setUp() throws Exception {
-		super.setUp();
-		
-		
-		//Create an index
-		RAMDirectory dir=new RAMDirectory();
-		IndexWriter w=new IndexWriter(dir,analyzer,true);
-		for (int i = 0; i < docFieldValues.length; i++)
-		{
-			w.addDocument(getDocumentFromString(docFieldValues[i]));
-		}
-		w.optimize();
-		w.close();
-		searcher=new IndexSearcher(dir);
-		
-		//initialize the parser
-		builder=new CorePlusExtensionsParser("artist", analyzer);
-		
-	}
-	
-	
-	protected void tearDown() throws Exception {
-		searcher.close();
-	}
-}
+package org.apache.lucene.xmlparser;
+
+import java.io.IOException;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.store.RAMDirectory;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This class illustrates how form input (such as from a web page or Swing gui) can be
+ * turned into Lucene queries using a choice of XSL templates for different styles of queries.
+ */
+public class TestQueryTemplateManager extends TestCase {
+
+	CoreParser builder;
+	Analyzer analyzer=new StandardAnalyzer();
+	private IndexSearcher searcher;
+	
+	//A collection of documents' field values for use in our tests
+	String docFieldValues []=
+	{
+			"artist=Jeff Buckley \talbum=Grace \treleaseDate=1999 \tgenre=rock",
+			"artist=Fugazi \talbum=Repeater \treleaseDate=1990 \tgenre=alternative",
+			"artist=Fugazi \talbum=Red Medicine \treleaseDate=1995 \tgenre=alternative",
+			"artist=Peeping Tom \talbum=Peeping Tom \treleaseDate=2006 \tgenre=rock",
+			"artist=Red Snapper \talbum=Prince Blimey \treleaseDate=1996 \tgenre=electronic"
+	};
+	
+	//A collection of example queries, consisting of name/value pairs representing form content plus 
+	// a choice of query style template to use in the test, with expected number of hits
+	String queryForms[]=
+	{
+			"artist=Fugazi \texpectedMatches=2 \ttemplate=albumBooleanQuery",
+			"artist=Fugazi \treleaseDate=1990 \texpectedMatches=1 \ttemplate=albumBooleanQuery",
+			"artist=Buckley \tgenre=rock \texpectedMatches=1 \ttemplate=albumFilteredQuery",
+			"artist=Buckley \tgenre=electronic \texpectedMatches=0 \ttemplate=albumFilteredQuery",
+			"queryString=artist:buckly~ NOT genre:electronic \texpectedMatches=1 \ttemplate=albumLuceneClassicQuery"
+	};
+	
+	
+	public void testFormTransforms() throws SAXException, IOException, ParserConfigurationException, TransformerException, ParserException 
+	{
+		//Cache all the query templates we will be referring to.
+		QueryTemplateManager qtm=new QueryTemplateManager();
+		qtm.addQueryTemplate("albumBooleanQuery", getClass().getResourceAsStream("albumBooleanQuery.xsl"));
+		qtm.addQueryTemplate("albumFilteredQuery", getClass().getResourceAsStream("albumFilteredQuery.xsl"));
+		qtm.addQueryTemplate("albumLuceneClassicQuery", getClass().getResourceAsStream("albumLuceneClassicQuery.xsl"));
+		//Run all of our test queries
+		for (int i = 0; i < queryForms.length; i++)
+		{
+			Properties queryFormProperties=getPropsFromString(queryForms[i]);
+			
+			//Get the required query XSL template for this test
+//			Templates template=getTemplate(queryFormProperties.getProperty("template"));
+			
+			//Transform the queryFormProperties into a Lucene XML query
+			Document doc=qtm.getQueryAsDOM(queryFormProperties,queryFormProperties.getProperty("template"));
+			
+			//Parse the XML query using the XML parser
+			Query q=builder.getQuery(doc.getDocumentElement());
+			
+			//Run the query
+			Hits h=searcher.search(q);
+			
+			//Check we have the expected number of results
+			int expectedHits=Integer.parseInt(queryFormProperties.getProperty("expectedMatches"));
+			assertEquals("Number of results should match for query "+queryForms[i],expectedHits,h.length());
+			
+		}
+	}
+	
+	//Helper method to construct Lucene query forms used in our test
+	Properties getPropsFromString(String nameValuePairs)
+	{
+		Properties result=new Properties();
+		StringTokenizer st=new StringTokenizer(nameValuePairs,"\t=");
+		while(st.hasMoreTokens())
+		{
+			String name=st.nextToken().trim();
+			if(st.hasMoreTokens())
+			{
+				String value=st.nextToken().trim();
+				result.setProperty(name,value);
+			}
+		}
+		return result;
+	}
+	
+	//Helper method to construct Lucene documents used in our tests
+	org.apache.lucene.document.Document getDocumentFromString(String nameValuePairs)
+	{
+		org.apache.lucene.document.Document result=new org.apache.lucene.document.Document();
+		StringTokenizer st=new StringTokenizer(nameValuePairs,"\t=");
+		while(st.hasMoreTokens())
+		{
+			String name=st.nextToken().trim();
+			if(st.hasMoreTokens())
+			{
+				String value=st.nextToken().trim();
+				result.add(new Field(name,value,Field.Store.YES,Field.Index.ANALYZED));
+			}
+		}
+		return result;
+	}
+	
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		
+		
+		//Create an index
+		RAMDirectory dir=new RAMDirectory();
+		IndexWriter w=new IndexWriter(dir,analyzer,true);
+		for (int i = 0; i < docFieldValues.length; i++)
+		{
+			w.addDocument(getDocumentFromString(docFieldValues[i]));
+		}
+		w.optimize();
+		w.close();
+		searcher=new IndexSearcher(dir);
+		
+		//initialize the parser
+		builder=new CorePlusExtensionsParser("artist", analyzer);
+		
+	}
+	
+	
+	protected void tearDown() throws Exception {
+		searcher.close();
+	}
+}

Propchange: lucene/java/trunk/contrib/xml-query-parser/src/test/org/apache/lucene/xmlparser/TestQueryTemplateManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/java/org/apache/lucene/util/ArrayUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/cache/Cache.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/cache/Cache.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/cache/Cache.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/cache/Cache.java Mon Nov 10 18:35:46 2008
@@ -1,105 +1,105 @@
-package org.apache.lucene.util.cache;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/**
- * Base class for cache implementations.
- */
-public abstract class Cache {
-  
-  /**
-   * Simple Cache wrapper that synchronizes all
-   * calls that access the cache. 
-   */
-  static class SynchronizedCache extends Cache {
-    Object mutex;
-    Cache  cache;
-    
-    SynchronizedCache(Cache cache) {
-      this.cache = cache;
-      this.mutex = this;
-    }
-    
-    SynchronizedCache(Cache cache, Object mutex) {
-      this.cache = cache;
-      this.mutex = mutex;
-    }
-    
-    public void put(Object key, Object value) {
-      synchronized(mutex) {cache.put(key, value);}
-    }
-    
-    public Object get(Object key) {
-      synchronized(mutex) {return cache.get(key);}
-    }
-    
-    public boolean containsKey(Object key) {
-      synchronized(mutex) {return cache.containsKey(key);}
-    }
-    
-    public void close() {
-      synchronized(mutex) {cache.close();}
-    }
-    
-    Cache getSynchronizedCache() {
-      return this;
-    }
-  }
-  
-  /**
-   * Returns a thread-safe cache backed by the specified cache. 
-   * In order to guarantee thread-safety, all access to the backed cache must
-   * be accomplished through the returned cache.
-   */
-  public static Cache synchronizedCache(Cache cache) {
-    return cache.getSynchronizedCache();
-  }
-
-  /**
-   * Called by {@link #synchronizedCache(Cache)}. This method
-   * returns a {@link SynchronizedCache} instance that wraps
-   * this instance by default and can be overridden to return
-   * e. g. subclasses of {@link SynchronizedCache} or this
-   * in case this cache is already synchronized.
-   */
-  Cache getSynchronizedCache() {
-    return new SynchronizedCache(this);
-  }
-  
-  /**
-   * Puts a (key, value)-pair into the cache. 
-   */
-  public abstract void put(Object key, Object value);
-  
-  /**
-   * Returns the value for the given key. 
-   */
-  public abstract Object get(Object key);
-  
-  /**
-   * Returns whether the given key is in this cache. 
-   */
-  public abstract boolean containsKey(Object key);
-  
-  /**
-   * Closes the cache.
-   */
-  public abstract void close();
-  
-}
+package org.apache.lucene.util.cache;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * Base class for cache implementations.
+ */
+public abstract class Cache {
+  
+  /**
+   * Simple Cache wrapper that synchronizes all
+   * calls that access the cache. 
+   */
+  static class SynchronizedCache extends Cache {
+    Object mutex;
+    Cache  cache;
+    
+    SynchronizedCache(Cache cache) {
+      this.cache = cache;
+      this.mutex = this;
+    }
+    
+    SynchronizedCache(Cache cache, Object mutex) {
+      this.cache = cache;
+      this.mutex = mutex;
+    }
+    
+    public void put(Object key, Object value) {
+      synchronized(mutex) {cache.put(key, value);}
+    }
+    
+    public Object get(Object key) {
+      synchronized(mutex) {return cache.get(key);}
+    }
+    
+    public boolean containsKey(Object key) {
+      synchronized(mutex) {return cache.containsKey(key);}
+    }
+    
+    public void close() {
+      synchronized(mutex) {cache.close();}
+    }
+    
+    Cache getSynchronizedCache() {
+      return this;
+    }
+  }
+  
+  /**
+   * Returns a thread-safe cache backed by the specified cache. 
+   * In order to guarantee thread-safety, all access to the backed cache must
+   * be accomplished through the returned cache.
+   */
+  public static Cache synchronizedCache(Cache cache) {
+    return cache.getSynchronizedCache();
+  }
+
+  /**
+   * Called by {@link #synchronizedCache(Cache)}. This method
+   * returns a {@link SynchronizedCache} instance that wraps
+   * this instance by default and can be overridden to return
+   * e. g. subclasses of {@link SynchronizedCache} or this
+   * in case this cache is already synchronized.
+   */
+  Cache getSynchronizedCache() {
+    return new SynchronizedCache(this);
+  }
+  
+  /**
+   * Puts a (key, value)-pair into the cache. 
+   */
+  public abstract void put(Object key, Object value);
+  
+  /**
+   * Returns the value for the given key. 
+   */
+  public abstract Object get(Object key);
+  
+  /**
+   * Returns whether the given key is in this cache. 
+   */
+  public abstract boolean containsKey(Object key);
+  
+  /**
+   * Closes the cache.
+   */
+  public abstract void close();
+  
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/util/cache/Cache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleLRUCache.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleLRUCache.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleLRUCache.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleLRUCache.java Mon Nov 10 18:35:46 2008
@@ -1,49 +1,49 @@
-package org.apache.lucene.util.cache;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * Simple LRU cache implementation that uses a LinkedHashMap.
- * This cache is not synchronized, use {@link Cache#synchronizedCache(Cache)}
- * if needed.
- * 
- */
-public class SimpleLRUCache extends SimpleMapCache {
-  private final static float LOADFACTOR = 0.75f;
-
-  private int cacheSize;
-
-  /**
-   * Creates a last-recently-used cache with the specified size. 
-   */
-  public SimpleLRUCache(int cacheSize) {
-    super(null);
-    this.cacheSize = cacheSize;
-    int capacity = (int) Math.ceil(cacheSize / LOADFACTOR) + 1;
-
-    super.map = new LinkedHashMap(capacity, LOADFACTOR, true) {
-      protected boolean removeEldestEntry(Map.Entry eldest) {
-        return size() > SimpleLRUCache.this.cacheSize;
-      }
-    };
-  }
-
-}
+package org.apache.lucene.util.cache;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Simple LRU cache implementation that uses a LinkedHashMap.
+ * This cache is not synchronized, use {@link Cache#synchronizedCache(Cache)}
+ * if needed.
+ * 
+ */
+public class SimpleLRUCache extends SimpleMapCache {
+  private final static float LOADFACTOR = 0.75f;
+
+  private int cacheSize;
+
+  /**
+   * Creates a last-recently-used cache with the specified size. 
+   */
+  public SimpleLRUCache(int cacheSize) {
+    super(null);
+    this.cacheSize = cacheSize;
+    int capacity = (int) Math.ceil(cacheSize / LOADFACTOR) + 1;
+
+    super.map = new LinkedHashMap(capacity, LOADFACTOR, true) {
+      protected boolean removeEldestEntry(Map.Entry eldest) {
+        return size() > SimpleLRUCache.this.cacheSize;
+      }
+    };
+  }
+
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleLRUCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleMapCache.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleMapCache.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleMapCache.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleMapCache.java Mon Nov 10 18:35:46 2008
@@ -1,100 +1,100 @@
-package org.apache.lucene.util.cache;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Simple cache implementation that uses a HashMap to store (key, value) pairs.
- * This cache is not synchronized, use {@link Cache#synchronizedCache(Cache)}
- * if needed.
- */
-public class SimpleMapCache extends Cache {
-  Map map;
-  
-  public SimpleMapCache() {
-    this(new HashMap());
-  }
-
-  public SimpleMapCache(Map map) {
-    this.map = map;
-  }
-  
-  public Object get(Object key) {
-    return map.get(key);
-  }
-
-  public void put(Object key, Object value) {
-    map.put(key, value);
-  }
-
-  public void close() {
-    // NOOP
-  }
-
-  public boolean containsKey(Object key) {
-    return map.containsKey(key);
-  }
-  
-  /**
-   * Returns a Set containing all keys in this cache.
-   */
-  public Set keySet() {
-    return map.keySet();
-  }
-  
-  Cache getSynchronizedCache() {
-    return new SynchronizedSimpleMapCache(this);
-  }
-  
-  private static class SynchronizedSimpleMapCache extends SimpleMapCache {
-    Object mutex;
-    SimpleMapCache cache;
-    
-    SynchronizedSimpleMapCache(SimpleMapCache cache) {
-        this.cache = cache;
-        this.mutex = this;
-    }
-    
-    public void put(Object key, Object value) {
-        synchronized(mutex) {cache.put(key, value);}
-    }
-    
-    public Object get(Object key) {
-        synchronized(mutex) {return cache.get(key);}
-    }
-    
-    public boolean containsKey(Object key) {
-        synchronized(mutex) {return cache.containsKey(key);}
-    }
-    
-    public void close() {
-        synchronized(mutex) {cache.close();}
-    }
-    
-    public Set keySet() {
-      synchronized(mutex) {return cache.keySet();}
-    }
-    
-    Cache getSynchronizedCache() {
-      return this;
-    }
-  }
-}
+package org.apache.lucene.util.cache;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Simple cache implementation that uses a HashMap to store (key, value) pairs.
+ * This cache is not synchronized, use {@link Cache#synchronizedCache(Cache)}
+ * if needed.
+ */
+public class SimpleMapCache extends Cache {
+  Map map;
+  
+  public SimpleMapCache() {
+    this(new HashMap());
+  }
+
+  public SimpleMapCache(Map map) {
+    this.map = map;
+  }
+  
+  public Object get(Object key) {
+    return map.get(key);
+  }
+
+  public void put(Object key, Object value) {
+    map.put(key, value);
+  }
+
+  public void close() {
+    // NOOP
+  }
+
+  public boolean containsKey(Object key) {
+    return map.containsKey(key);
+  }
+  
+  /**
+   * Returns a Set containing all keys in this cache.
+   */
+  public Set keySet() {
+    return map.keySet();
+  }
+  
+  Cache getSynchronizedCache() {
+    return new SynchronizedSimpleMapCache(this);
+  }
+  
+  private static class SynchronizedSimpleMapCache extends SimpleMapCache {
+    Object mutex;
+    SimpleMapCache cache;
+    
+    SynchronizedSimpleMapCache(SimpleMapCache cache) {
+        this.cache = cache;
+        this.mutex = this;
+    }
+    
+    public void put(Object key, Object value) {
+        synchronized(mutex) {cache.put(key, value);}
+    }
+    
+    public Object get(Object key) {
+        synchronized(mutex) {return cache.get(key);}
+    }
+    
+    public boolean containsKey(Object key) {
+        synchronized(mutex) {return cache.containsKey(key);}
+    }
+    
+    public void close() {
+        synchronized(mutex) {cache.close();}
+    }
+    
+    public Set keySet() {
+      synchronized(mutex) {return cache.keySet();}
+    }
+    
+    Cache getSynchronizedCache() {
+      return this;
+    }
+  }
+}

Propchange: lucene/java/trunk/src/java/org/apache/lucene/util/cache/SimpleMapCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMDirectory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/store/MockRAMOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/store/TestLock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java Mon Nov 10 18:35:46 2008
@@ -1,113 +1,113 @@
-package org.apache.lucene.util;
-
-/**
- * Copyright 2005 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.lucene.util.LuceneTestCase;
-import java.util.Random;
-
-/**
- * @version $Id$
- */
-public class TestSmallFloat extends LuceneTestCase {
-
-  // original lucene byteToFloat
-  static float orig_byteToFloat(byte b) {
-    if (b == 0)                                   // zero is a special case
-      return 0.0f;
-    int mantissa = b & 7;
-    int exponent = (b >> 3) & 31;
-    int bits = ((exponent+(63-15)) << 24) | (mantissa << 21);
-    return Float.intBitsToFloat(bits);
-  }
-
-  // original lucene floatToByte
-  static byte orig_floatToByte(float f) {
-    if (f < 0.0f)                                 // round negatives up to zero
-      f = 0.0f;
-
-    if (f == 0.0f)                                // zero is a special case
-      return 0;
-
-    int bits = Float.floatToIntBits(f);           // parse float into parts
-    int mantissa = (bits & 0xffffff) >> 21;
-    int exponent = (((bits >> 24) & 0x7f) - 63) + 15;
-
-    if (exponent > 31) {                          // overflow: use max value
-      exponent = 31;
-      mantissa = 7;
-    }
-
-    if (exponent < 0) {                           // underflow: use min value
-      exponent = 0;
-      mantissa = 1;
-    }
-
-    return (byte)((exponent << 3) | mantissa);    // pack into a byte
-  }
-
-  public void testByteToFloat() {
-    for (int i=0; i<256; i++) {
-      float f1 = orig_byteToFloat((byte)i);
-      float f2 = SmallFloat.byteToFloat((byte)i, 3,15);
-      float f3 = SmallFloat.byte315ToFloat((byte)i);
-      assertEquals(f1,f2,0.0);
-      assertEquals(f2,f3,0.0);
-
-      float f4 = SmallFloat.byteToFloat((byte)i,5,2);
-      float f5 = SmallFloat.byte52ToFloat((byte)i);
-      assertEquals(f4,f5,0.0);
-    }
-  }
-
-  public void testFloatToByte() {
-    Random rand = new Random(0);
-    // up iterations for more exhaustive test after changing something
-    for (int i=0; i<100000; i++) {
-      float f = Float.intBitsToFloat(rand.nextInt());
-      if (f!=f) continue;    // skip NaN
-      byte b1 = orig_floatToByte(f);
-      byte b2 = SmallFloat.floatToByte(f,3,15);
-      byte b3 = SmallFloat.floatToByte315(f);
-      assertEquals(b1,b2);
-      assertEquals(b2,b3);
-
-      byte b4 = SmallFloat.floatToByte(f,5,2);
-      byte b5 = SmallFloat.floatToByte52(f);
-      assertEquals(b4,b5);
-    }
-  }
-
-  /***
-  // Do an exhaustive test of all possible floating point values
-  // for the 315 float against the original norm encoding in Similarity.
-  // Takes 75 seconds on my Pentium4 3GHz, with Java5 -server
-  public void testAllFloats() {
-    for(int i = Integer.MIN_VALUE;;i++) {
-      float f = Float.intBitsToFloat(i);
-      if (f==f) { // skip non-numbers
-        byte b1 = orig_floatToByte(f);
-        byte b2 = SmallFloat.floatToByte315(f);
-        if (b1!=b2) {
-          TestCase.fail("Failed floatToByte315 for float " + f);
-        }
-      }
-      if (i==Integer.MAX_VALUE) break;
-    }
-  }
-  ***/
-
-}
+package org.apache.lucene.util;
+
+/**
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.util.LuceneTestCase;
+import java.util.Random;
+
+/**
+ * @version $Id$
+ */
+public class TestSmallFloat extends LuceneTestCase {
+
+  // original lucene byteToFloat
+  static float orig_byteToFloat(byte b) {
+    if (b == 0)                                   // zero is a special case
+      return 0.0f;
+    int mantissa = b & 7;
+    int exponent = (b >> 3) & 31;
+    int bits = ((exponent+(63-15)) << 24) | (mantissa << 21);
+    return Float.intBitsToFloat(bits);
+  }
+
+  // original lucene floatToByte
+  static byte orig_floatToByte(float f) {
+    if (f < 0.0f)                                 // round negatives up to zero
+      f = 0.0f;
+
+    if (f == 0.0f)                                // zero is a special case
+      return 0;
+
+    int bits = Float.floatToIntBits(f);           // parse float into parts
+    int mantissa = (bits & 0xffffff) >> 21;
+    int exponent = (((bits >> 24) & 0x7f) - 63) + 15;
+
+    if (exponent > 31) {                          // overflow: use max value
+      exponent = 31;
+      mantissa = 7;
+    }
+
+    if (exponent < 0) {                           // underflow: use min value
+      exponent = 0;
+      mantissa = 1;
+    }
+
+    return (byte)((exponent << 3) | mantissa);    // pack into a byte
+  }
+
+  public void testByteToFloat() {
+    for (int i=0; i<256; i++) {
+      float f1 = orig_byteToFloat((byte)i);
+      float f2 = SmallFloat.byteToFloat((byte)i, 3,15);
+      float f3 = SmallFloat.byte315ToFloat((byte)i);
+      assertEquals(f1,f2,0.0);
+      assertEquals(f2,f3,0.0);
+
+      float f4 = SmallFloat.byteToFloat((byte)i,5,2);
+      float f5 = SmallFloat.byte52ToFloat((byte)i);
+      assertEquals(f4,f5,0.0);
+    }
+  }
+
+  public void testFloatToByte() {
+    Random rand = new Random(0);
+    // up iterations for more exhaustive test after changing something
+    for (int i=0; i<100000; i++) {
+      float f = Float.intBitsToFloat(rand.nextInt());
+      if (f!=f) continue;    // skip NaN
+      byte b1 = orig_floatToByte(f);
+      byte b2 = SmallFloat.floatToByte(f,3,15);
+      byte b3 = SmallFloat.floatToByte315(f);
+      assertEquals(b1,b2);
+      assertEquals(b2,b3);
+
+      byte b4 = SmallFloat.floatToByte(f,5,2);
+      byte b5 = SmallFloat.floatToByte52(f);
+      assertEquals(b4,b5);
+    }
+  }
+
+  /***
+  // Do an exhaustive test of all possible floating point values
+  // for the 315 float against the original norm encoding in Similarity.
+  // Takes 75 seconds on my Pentium4 3GHz, with Java5 -server
+  public void testAllFloats() {
+    for(int i = Integer.MIN_VALUE;;i++) {
+      float f = Float.intBitsToFloat(i);
+      if (f==f) { // skip non-numbers
+        byte b1 = orig_floatToByte(f);
+        byte b2 = SmallFloat.floatToByte315(f);
+        if (b1!=b2) {
+          TestCase.fail("Failed floatToByte315 for float " + f);
+        }
+      }
+      if (i==Integer.MAX_VALUE) break;
+    }
+  }
+  ***/
+
+}

Propchange: lucene/java/trunk/src/test/org/apache/lucene/util/TestSmallFloat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/util/TestStringHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/java/trunk/src/test/org/apache/lucene/util/cache/TestSimpleLRUCache.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/cache/TestSimpleLRUCache.java?rev=712922&r1=712921&r2=712922&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/cache/TestSimpleLRUCache.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/cache/TestSimpleLRUCache.java Mon Nov 10 18:35:46 2008
@@ -1,63 +1,63 @@
-package org.apache.lucene.util.cache;
-
-/**
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-import junit.framework.TestCase;
-
-public class TestSimpleLRUCache extends TestCase {
-
-  public void testLRUCache() throws Exception {
-    final int n = 100;
-    Object dummy = new Object();
-    
-    Cache cache = new SimpleLRUCache(n);
-    
-    for (int i = 0; i < n; i++) {
-      cache.put(new Integer(i), dummy);
-    }
-    
-    // access every 2nd item in cache
-    for (int i = 0; i < n; i+=2) {
-      assertNotNull(cache.get(new Integer(i)));
-    }
-    
-    // add n/2 elements to cache, the ones that weren't
-    // touched in the previous loop should now be thrown away
-    for (int i = n; i < n + (n / 2); i++) {
-      cache.put(new Integer(i), dummy);
-    }
-    
-    // access every 4th item in cache
-    for (int i = 0; i < n; i+=4) {
-      assertNotNull(cache.get(new Integer(i)));
-    }
-
-    // add 3/4n elements to cache, the ones that weren't
-    // touched in the previous loops should now be thrown away
-    for (int i = n; i < n + (n * 3 / 4); i++) {
-      cache.put(new Integer(i), dummy);
-    }
-    
-    // access every 4th item in cache
-    for (int i = 0; i < n; i+=4) {
-      assertNotNull(cache.get(new Integer(i)));
-    }
-    
-  }
-  
-}
+package org.apache.lucene.util.cache;
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import junit.framework.TestCase;
+
+public class TestSimpleLRUCache extends TestCase {
+
+  public void testLRUCache() throws Exception {
+    final int n = 100;
+    Object dummy = new Object();
+    
+    Cache cache = new SimpleLRUCache(n);
+    
+    for (int i = 0; i < n; i++) {
+      cache.put(new Integer(i), dummy);
+    }
+    
+    // access every 2nd item in cache
+    for (int i = 0; i < n; i+=2) {
+      assertNotNull(cache.get(new Integer(i)));
+    }
+    
+    // add n/2 elements to cache, the ones that weren't
+    // touched in the previous loop should now be thrown away
+    for (int i = n; i < n + (n / 2); i++) {
+      cache.put(new Integer(i), dummy);
+    }
+    
+    // access every 4th item in cache
+    for (int i = 0; i < n; i+=4) {
+      assertNotNull(cache.get(new Integer(i)));
+    }
+
+    // add 3/4n elements to cache, the ones that weren't
+    // touched in the previous loops should now be thrown away
+    for (int i = n; i < n + (n * 3 / 4); i++) {
+      cache.put(new Integer(i), dummy);
+    }
+    
+    // access every 4th item in cache
+    for (int i = 0; i < n; i+=4) {
+      assertNotNull(cache.get(new Integer(i)));
+    }
+    
+  }
+  
+}

Propchange: lucene/java/trunk/src/test/org/apache/lucene/util/cache/TestSimpleLRUCache.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message