All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.browseengine.bobo.facets.data.PredefinedTermListFactory Maven / Gradle / Ivy

Go to download

Bobo is a Faceted Search implementation written purely in Java, an extension of Apache Lucene

The newest version!
package com.browseengine.bobo.facets.data;

import java.lang.reflect.Constructor;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Class supported:
 * 
    *
  • {@link Integer}
  • *
  • {@link Float}
  • *
  • {@link Character}
  • *
  • {@link Double}
  • *
  • {@link Short}
  • *
  • {@link Long}
  • *
  • {@link Date}
  • *
* * Autoboxing: primitive types corresponding classes above are supported. */ public class PredefinedTermListFactory implements TermListFactory { private static Map, Class>> supportedTypes = new HashMap, Class>>(); static { supportedTypes.put(int.class, TermIntList.class); supportedTypes.put(float.class, TermFloatList.class); supportedTypes.put(char.class, TermCharList.class); supportedTypes.put(double.class, TermDoubleList.class); supportedTypes.put(short.class, TermShortList.class); supportedTypes.put(long.class, TermLongList.class); supportedTypes.put(Integer.class, TermIntList.class); supportedTypes.put(Float.class, TermFloatList.class); supportedTypes.put(Character.class, TermCharList.class); supportedTypes.put(Double.class, TermDoubleList.class); supportedTypes.put(Short.class, TermShortList.class); supportedTypes.put(Long.class, TermLongList.class); supportedTypes.put(Date.class, TermDateList.class); } private final Class _cls; private final String _format; private final Class> _listClass; @SuppressWarnings("unchecked") public PredefinedTermListFactory(Class cls, String format) { if (supportedTypes.get(cls) == null) { throw new IllegalArgumentException("Class " + cls + " not defined."); } _cls = cls; _format = format; _listClass = (Class>) supportedTypes.get(_cls); } public PredefinedTermListFactory(Class cls) { this(cls, null); } @Override public TermValueList createTermList(int capacity) { if (TermCharList.class.equals(_listClass)) // we treat char type separate as // it does not have a format // string { @SuppressWarnings("unchecked") TermValueList retlist = (TermValueList) (new TermCharList(capacity)); ; return retlist; } else { try { Constructor> constructor = _listClass.getConstructor(int.class, String.class); // the constructor also takes the format String as parameter return constructor.newInstance(capacity, _format); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } } @Override public TermValueList createTermList() { return createTermList(-1); } @Override public Class getType() { // TODO Auto-generated method stub return _cls; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy