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

prerna.algorithm.impl.MinReactor Maven / Gradle / Ivy

There is a newer version: 4.2.2
Show newest version
package prerna.algorithm.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import prerna.util.ArrayUtilityMethods;

public class MinReactor extends BaseReducerReactor {
	
	public MinReactor() {
		setMathRoutine("Min");
	}
	
	@Override
	public Object reduce() {
		double output = 0.0;
		if(inputIterator.hasNext() && !errored) {
			ArrayList row = (ArrayList)getNextValue();
			if(row.get(0) instanceof Number) {
				output = ((Number)row.get(0)).doubleValue();
			}
			while(inputIterator.hasNext()) {
				ArrayList dec = (ArrayList)getNextValue();
				if(dec.get(0) instanceof Number) {
					double value = ((Number)dec.get(0)).doubleValue();
					if(value < output) {
						output = value;
					}
				}
			}
		}
		System.out.println(output);
		return output;
	}
	
	@Override
	public HashMap,Object> reduceGroupBy(Vector groupBys, Vector processedColumns, String[] columnsArray, Iterator it) {
		HashMap, Object> groupByHash = new HashMap,Object>();
		
		while(it.hasNext()){
			Object[] row = (Object[]) it.next();
			HashMap key = new HashMap();
			for(String groupBy : groupBys) {
				int groupByIndex = ArrayUtilityMethods.arrayContainsValueAtIndexIgnoreCase(columnsArray, groupBy);
				Object instance = row[groupByIndex];
				key.put(groupBy, instance);
			}
			int processedIndex = ArrayUtilityMethods.arrayContainsValueAtIndexIgnoreCase(columnsArray, processedColumns.get(0));
			if (row[processedIndex] instanceof Number) {
				double value = ((Number)row[processedIndex]).doubleValue();
				if(!groupByHash.containsKey(key)) {
					groupByHash.put(key, value);
				} else if(((Double)groupByHash.get(key)) > value){
					groupByHash.put(key, value);
				}
			}
		}
		
		return groupByHash;
	}
	
	public Map getColumnDataMap() {
		return getBaseColumnDataMap();
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy