package org.pfaa.chemica.processing;

import java.util.Arrays;
import java.util.function.Predicate;
import java.util.stream.Stream;

import org.pfaa.chemica.model.IndustrialMaterial;

public class Communition extends DegenerateConversion implements Sizing {
	protected Communition(IndustrialMaterial material) {
		super(material);
	}

	@Override
	public Direction getDirection() {
		return Direction.DECREASE;
	}

	@Override
	public Form getOutputForm(Form inputForm) {
		return inputForm.communite();
	}

	@Override
	public Stream<MaterialStoich<?>> getBonusOutputs(Form form) {
		// TODO Get components from mixture, scaling by output form
		return super.getBonusOutputs(form);
	}

	public static Communition of(IndustrialMaterial material) {
		return new Communition(material);
	}
	
	public static <T extends Enum<?> & IndustrialMaterial> Stream<Communition> of(Class<T> material, Predicate<T> predicate) {
		return Arrays.stream(material.getEnumConstants()).filter(predicate).map(Communition::of);
	}
	
	public static <T extends Enum<?> & IndustrialMaterial> Stream<Communition> of(Class<T> material) {
		return of(material, (x) -> true);
	}
}

@@ -56,16 +56,39 @@
 Arrays;%0A
+import java.util.List;%0A
 import j
@@ -198,16 +198,143 @@
 aterial;
+%0Aimport org.pfaa.chemica.model.Mixture;%0Aimport org.pfaa.chemica.processing.Form.Forms;%0A%0Aimport com.google.common.collect.Lists;
 %0A%0Apublic
@@ -401,16 +401,44 @@
 izing %7B%0A
+%09private boolean reduces;%0A%09%0A
 %09protect
@@ -502,24 +502,363 @@
 erial);%0A%09%7D%0A%0A
+%09private IndustrialMaterial getOutputMaterial() %7B%0A%09%09if (this.reduces && this.getMaterial() instanceof Mixture) %7B%0A%09%09%09Mixture mixture = (Mixture)this.getMaterial();%0A%09%09%09return mixture.getComponents().get(0).material;%0A%09%09%7D else %7B%0A%09%09%09return this.getMaterial();%0A%09%09%7D%0A%09%7D%0A%09%0A%09public Communition reduces() %7B%0A%09%09this.reduces = true;%0A%09%09return this;%0A%09%7D%0A%09%0A
 %09@Override%0A%09
@@ -976,24 +976,92 @@
 nputForm) %7B%0A
+%09%09if (this.getOutputMaterial().isGranular())%0A%09%09%09return Forms.BLOCK;%0A
 %09%09return inp
@@ -1103,22 +1103,20 @@
 %09public 
-Stream
+List
 %3CMateria
@@ -1130,29 +1130,24 @@
 %3C?%3E%3E get
-Bonus
 Outputs(
 Form for
@@ -1142,119 +1142,494 @@
 uts(
-Form form) %7B%0A%09%09// TODO Get components from mixture, scaling by output form%0A%09%09return super.getBonusOutputs(form)
+) %7B%0A%09%09List%3CMaterialStoich%3C?%3E%3E outputs = super.getOutputs();%0A%09%09if (this.getMaterial() instanceof Mixture) %7B %0A%09%09%09Mixture mixture = (Mixture)this.getMaterial();%0A%09%09%09if (this.reduces) %7B%0A%09%09%09%09outputs = Lists.newArrayList(MaterialStoich.of(mixture.getComponents().get(0)));%0A%09%09%09%7D else %7B%0A%09%09%09%09outputs = Lists.newArrayList(outputs);%0A%09%09%09%7D%0A%09%09%09mixture.getComponents().stream().%0A%09%09%09%09%09skip(1).%0A%09%09%09%09%09map(MaterialStoich::of).%0A%09%09%09%09%09map((s) -%3E s.scale(1/9)).%0A%09%09%09%09%09forEach(outputs::add);%0A%09%09%7D%0A%09%09return outputs
 ;%0A%09%7D

rework communition