/**************************************************************************************
* Copyright (C) 2008 EsperTech, Inc. All rights reserved. *
* http://esper.codehaus.org *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
**************************************************************************************/
package com.espertech.esper.epl.join.table;
import com.espertech.esper.client.EventType;
import com.espertech.esper.util.JavaClassHelper;
import com.espertech.esper.util.SimpleNumberCoercer;
import com.espertech.esper.util.SimpleNumberCoercerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Index that organizes events by the event property values into hash buckets. Based on a HashMap
* with {@link com.espertech.esper.collection.MultiKeyUntyped} keys that store the property values.
* <p>
* Performs coercion of the index keys before storing the keys.
* <p>
* Takes a list of property names as parameter. Doesn't care which event type the events have as long as the properties
* exist. If the same event is added twice, the class throws an exception on add.
*/
public class PropertyIndexedEventTableCoerceAddFactory extends PropertyIndexedEventTableFactory
{
private static Log log = LogFactory.getLog(PropertyIndexedEventTableCoerceAddFactory.class);
protected final SimpleNumberCoercer[] coercers;
protected final Class[] coercionType;
/**
* Ctor.
* @param streamNum is the stream number of the indexed stream
* @param eventType is the event type of the indexed stream
* @param propertyNames are the property names to get property values
* @param coercionType are the classes to coerce indexed values to
*/
public PropertyIndexedEventTableCoerceAddFactory(int streamNum, EventType eventType, String[] propertyNames, Class[] coercionType)
{
super(streamNum, eventType, propertyNames, false, null);
this.coercionType = coercionType;
coercers = new SimpleNumberCoercer[coercionType.length];
for (int i = 0; i < coercionType.length; i++)
{
if (JavaClassHelper.isNumeric(coercionType[i])) {
coercers[i] = SimpleNumberCoercerFactory.getCoercer(null, coercionType[i]);
}
}
}
public EventTable makeEventTable() {
return new PropertyIndexedEventTableCoerceAdd(streamNum, propertyGetters, coercers, coercionType);
}
}