package com.github.druidgreeneyes.rivet.adapt;

import java.util.Collection;
import java.util.Iterator;

import org.apache.commons.lang3.ArrayUtils;

import com.github.druidgreeneyes.rivet.core.labels.ArrayRIV;
import com.github.druidgreeneyes.rivet.core.labels.ColtRIV;
import com.github.druidgreeneyes.rivet.core.labels.DenseRIV;
import com.github.druidgreeneyes.rivet.core.labels.HPPCRIV;
import com.github.druidgreeneyes.rivet.core.labels.MapRIV;

public class SOLR {
  public static MapRIV mapRIVFromCollections(final Collection<Object> indices,
                                             final Collection<Object> values,
                                             final int size) {
    final MapRIV res = MapRIV.empty(size);
    final Iterator<Object> is = indices.iterator();
    final Iterator<Object> vs = values.iterator();
    while (is.hasNext() && vs.hasNext())
      res.put((int) is.next(), (double) vs.next());
    return res;
  }

  public static ColtRIV coltRIVFromCollections(
                                               final Collection<Object> indices,
                                               final Collection<Object> values,
                                               final int size) {
    final ColtRIV res = ColtRIV.empty(size);
    final Iterator<Object> is = indices.iterator();
    final Iterator<Object> vs = values.iterator();
    while (is.hasNext() && vs.hasNext())
      res.put((int) is.next(), (double) vs.next());
    return res;
  }

  public static HPPCRIV hppcRIVFromCollections(
                                               final Collection<Object> indices,
                                               final Collection<Object> values,
                                               final int size) {
    final HPPCRIV res = HPPCRIV.empty(size);
    final Iterator<Object> is = indices.iterator();
    final Iterator<Object> vs = values.iterator();
    while (is.hasNext() && vs.hasNext())
      res.put((int) is.next(), (double) vs.next());
    return res;
  }

  public static DenseRIV denseRIVFromCollections(
                                                 final Collection<Object> indices,
                                                 final Collection<Object> values,
                                                 final int size) {
    final DenseRIV res = DenseRIV.empty(size);
    final Iterator<Object> is = indices.iterator();
    final Iterator<Object> vs = values.iterator();
    while (is.hasNext() && vs.hasNext())
      res.put((int) is.next(), (double) vs.next());
    return res;
  }

  public static ArrayRIV arrayRIVFromCollections(
                                                 final Collection<Object> indices,
                                                 final Collection<Object> values,
                                                 final int size) {
    final Integer[] is = indices.toArray(new Integer[indices.size()]);
    final Double[] vs = values.toArray(new Double[values.size()]);
    return new ArrayRIV(ArrayUtils.toPrimitive(is),
                        ArrayUtils.toPrimitive(vs), size);
  }
}

@@ -441,35 +441,576 @@
 ls.M
-apRIV;%0A%0Apublic class SOLR %7B
+TJRIV;%0Aimport com.github.druidgreeneyes.rivet.core.labels.MapRIV;%0A%0Apublic class SOLR %7B%0A  public static MTJRIV mtjRIVFromCollections(final Collection%3CObject%3E indices,%0A                                             final Collection%3CObject%3E values,%0A                                             final int size) %7B%0A    final MTJRIV res = MTJRIV.empty(size);%0A    final Iterator%3CObject%3E is = indices.iterator();%0A    final Iterator%3CObject%3E vs = values.iterator();%0A    while (is.hasNext() && vs.hasNext())%0A      res.put((int) is.next(), (double) vs.next());%0A    return res;%0A  %7D%0A  
 %0A  p

add MTJRIV