// Path: src/main/java/com/noctarius/castmapr/core/CollectorImpl.java
// public class CollectorImpl<Key, Value>
//     implements Collector<Key, Value>
// {
// 
//     public final Map<Key, List<Value>> emitted = new HashMap<Key, List<Value>>();
// 
//     @Override
//     public void emit( Key key, Value value )
//     {
//         List<Value> values = emitted.get( key );
//         if ( values == null )
//         {
//             values = new LinkedList<Value>();
//             emitted.put( key, values );
//         }
//         values.add( value );
//     }
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/IListAware.java
// public interface IListAware<Value>
// {
// 
//     /**
//      * This method is called after deserializing but before executing {@link Mapper#map(Object, Object, Collector)} or
//      * {@link Reducer#reduce(Object, java.util.Iterator)}.
//      * 
//      * @param list The list the implementing instance is executed against.
//      */
//     void setMultiMap( IList<Value> list );
// 
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/Mapper.java
// public abstract class Mapper<KeyIn, ValueIn, KeyOut, ValueOut>
//     implements Serializable
// {
// 
//     /**
//      * This method is called before the {@link #map(Object, Object, Collector)} method is executed for every value and
//      * can be used to initialize the internal state of the mapper or to emit a special value.
//      * 
//      * @param collector The {@link Collector} to be used for emitting values.
//      */
//     public void initialize( Collector<KeyOut, ValueOut> collector )
//     {
//     }
// 
//     /**
//      * The map method is called for every single key-value pair in the bound {@link IMap} instance on this cluster node
//      * and partition.<br>
//      * Due to it's nature of a DataGrid Hazelcast distributes values all over the cluster and so this method is executed
//      * on multiple servers at the same time.<br>
//      * If you want to know more about the implementation of MapReduce algorithms read the {@see <a
//      * href="http://research.google.com/archive/mapreduce-osdi04.pdf">Google Whitepaper on MapReduce</a>}.
//      * 
//      * @param key
//      * @param value
//      * @param collector
//      */
//     public abstract void map( KeyIn key, ValueIn value, Collector<KeyOut, ValueOut> collector );
// 
//     /**
//      * This method is called after the {@link #map(Object, Object, Collector)} method is executed for every value and
//      * can be used to finalize the internal state of the mapper or to emit a special value.
//      * 
//      * @param collector The {@link Collector} to be used for emitting values.
//      */
//     public void finalized( Collector<KeyOut, ValueOut> collector )
//     {
//     }
// 
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/PartitionIdAware.java
// public interface PartitionIdAware
// {
// 
//     /**
//      * This method is called after deserializing but before executing {@link Mapper#map(Object, Object, Collector)} or
//      * {@link Reducer#reduce(Object, java.util.Iterator)}.
//      * 
//      * @param partitionId The current partitionId
//      */
//     void setPartitionId( int partitionId );
// 
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/Reducer.java
// public interface Reducer<Key, Value>
//     extends Serializable
// {
// 
//     /**
//      * The reduce method is called either locally after of intermediate results are retrieved from mapping algorithms or
//      * (if the Reducer implementation is distributable - see {@link Distributable} or {@link DistributableReducer}) on
//      * the different cluster nodes.<br>
//      * <b>Caution: For distributable {@link Reducer}s you need to pay attention that the reducer is executed multiple
//      * times and only with intermediate results of one cluster node! This is totally ok for example for sum-algorithms
//      * but can be a problem for other kinds!</b><br>
//      * {@link Reducer} implementations are never distributed by default - they need to explicitly be marked using the
//      * {@link Distributable} annotation or by implementing the {@link DistributableReducer} interface.
//      * 
//      * @param key The reduced key
//      * @param values The values corresponding to the reduced key
//      * @return The reduced value
//      */
//     Value reduce( Key key, Iterator<Value> values );
// 
// }


import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.hazelcast.collection.CollectionContainer;
import com.hazelcast.collection.CollectionProxyId;
import com.hazelcast.collection.CollectionProxyType;
import com.hazelcast.collection.CollectionRecord;
import com.hazelcast.collection.CollectionService;
import com.hazelcast.collection.CollectionWrapper;
import com.hazelcast.collection.list.ObjectListProxy;
import com.hazelcast.core.IList;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.spi.ProxyService;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.noctarius.castmapr.core.CollectorImpl;
import com.noctarius.castmapr.spi.IListAware;
import com.noctarius.castmapr.spi.Mapper;
import com.noctarius.castmapr.spi.PartitionIdAware;
import com.noctarius.castmapr.spi.Reducer;
/*
 * 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.
 */

package com.noctarius.castmapr.core.operation;



public class IListMapReduceOperation<KeyIn, ValueIn, KeyOut, ValueOut>
    extends AbstractMapReduceOperation<KeyIn, ValueIn, KeyOut, ValueOut>
{

    public IListMapReduceOperation()
    {
    }

    public IListMapReduceOperation( String name, Mapper<KeyIn, ValueIn, KeyOut, ValueOut> mapper,
                                    Reducer<KeyOut, ValueOut> reducer )
    {
        super( name, mapper, reducer, null );
    }

    @Override
    public void run()
// Path: src/main/java/com/noctarius/castmapr/core/CollectorImpl.java
// public class CollectorImpl<Key, Value>
//     implements Collector<Key, Value>
// {
// 
//     public final Map<Key, List<Value>> emitted = new HashMap<Key, List<Value>>();
// 
//     @Override
//     public void emit( Key key, Value value )
//     {
//         List<Value> values = emitted.get( key );
//         if ( values == null )
//         {
//             values = new LinkedList<Value>();
//             emitted.put( key, values );
//         }
//         values.add( value );
//     }
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/IListAware.java
// public interface IListAware<Value>
// {
// 
//     /**
//      * This method is called after deserializing but before executing {@link Mapper#map(Object, Object, Collector)} or
//      * {@link Reducer#reduce(Object, java.util.Iterator)}.
//      * 
//      * @param list The list the implementing instance is executed against.
//      */
//     void setMultiMap( IList<Value> list );
// 
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/Mapper.java
// public abstract class Mapper<KeyIn, ValueIn, KeyOut, ValueOut>
//     implements Serializable
// {
// 
//     /**
//      * This method is called before the {@link #map(Object, Object, Collector)} method is executed for every value and
//      * can be used to initialize the internal state of the mapper or to emit a special value.
//      * 
//      * @param collector The {@link Collector} to be used for emitting values.
//      */
//     public void initialize( Collector<KeyOut, ValueOut> collector )
//     {
//     }
// 
//     /**
//      * The map method is called for every single key-value pair in the bound {@link IMap} instance on this cluster node
//      * and partition.<br>
//      * Due to it's nature of a DataGrid Hazelcast distributes values all over the cluster and so this method is executed
//      * on multiple servers at the same time.<br>
//      * If you want to know more about the implementation of MapReduce algorithms read the {@see <a
//      * href="http://research.google.com/archive/mapreduce-osdi04.pdf">Google Whitepaper on MapReduce</a>}.
//      * 
//      * @param key
//      * @param value
//      * @param collector
//      */
//     public abstract void map( KeyIn key, ValueIn value, Collector<KeyOut, ValueOut> collector );
// 
//     /**
//      * This method is called after the {@link #map(Object, Object, Collector)} method is executed for every value and
//      * can be used to finalize the internal state of the mapper or to emit a special value.
//      * 
//      * @param collector The {@link Collector} to be used for emitting values.
//      */
//     public void finalized( Collector<KeyOut, ValueOut> collector )
//     {
//     }
// 
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/PartitionIdAware.java
// public interface PartitionIdAware
// {
// 
//     /**
//      * This method is called after deserializing but before executing {@link Mapper#map(Object, Object, Collector)} or
//      * {@link Reducer#reduce(Object, java.util.Iterator)}.
//      * 
//      * @param partitionId The current partitionId
//      */
//     void setPartitionId( int partitionId );
// 
// }
// 
// Path: src/main/java/com/noctarius/castmapr/spi/Reducer.java
// public interface Reducer<Key, Value>
//     extends Serializable
// {
// 
//     /**
//      * The reduce method is called either locally after of intermediate results are retrieved from mapping algorithms or
//      * (if the Reducer implementation is distributable - see {@link Distributable} or {@link DistributableReducer}) on
//      * the different cluster nodes.<br>
//      * <b>Caution: For distributable {@link Reducer}s you need to pay attention that the reducer is executed multiple
//      * times and only with intermediate results of one cluster node! This is totally ok for example for sum-algorithms
//      * but can be a problem for other kinds!</b><br>
//      * {@link Reducer} implementations are never distributed by default - they need to explicitly be marked using the
//      * {@link Distributable} annotation or by implementing the {@link DistributableReducer} interface.
//      * 
//      * @param key The reduced key
//      * @param values The values corresponding to the reduced key
//      * @return The reduced value
//      */
//     Value reduce( Key key, Iterator<Value> values );
// 
// }


// Path: src/main/java/com/noctarius/castmapr/core/operation/IListMapReduceOperation.java
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.hazelcast.collection.CollectionContainer;
import com.hazelcast.collection.CollectionProxyId;
import com.hazelcast.collection.CollectionProxyType;
import com.hazelcast.collection.CollectionRecord;
import com.hazelcast.collection.CollectionService;
import com.hazelcast.collection.CollectionWrapper;
import com.hazelcast.collection.list.ObjectListProxy;
import com.hazelcast.core.IList;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.spi.ProxyService;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.noctarius.castmapr.core.CollectorImpl;
import com.noctarius.castmapr.spi.IListAware;
import com.noctarius.castmapr.spi.Mapper;
import com.noctarius.castmapr.spi.PartitionIdAware;
import com.noctarius.castmapr.spi.Reducer;

/*
 * 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.
 */

package com.noctarius.castmapr.core.operation;



public class IListMapReduceOperation<KeyIn, ValueIn, KeyOut, ValueOut>
    extends AbstractMapReduceOperation<KeyIn, ValueIn, KeyOut, ValueOut>
{

    public IListMapReduceOperation()
    {
    }

    public IListMapReduceOperation( String name, Mapper<KeyIn, ValueIn, KeyOut, ValueOut> mapper,
                                    Reducer<KeyOut, ValueOut> reducer )
    {
        super( name, mapper, reducer, null );
    }

    @Override
    public void run()
        throws Exception