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

org.dmg.pmml.ComplexArray Maven / Gradle / Ivy

There is a newer version: 1.6.6
Show newest version
/*
 * Copyright (c) 2019 Villu Ruusmann
 */
package org.dmg.pmml;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.jpmml.model.ArrayUtil;
import org.jpmml.model.annotations.Property;
import org.jpmml.model.annotations.ValueConstructor;

public class ComplexArray extends Array {

	public ComplexArray(){
	}

	@ValueConstructor
	public ComplexArray(@Property("type") Array.Type type, @Property("value") Collection value){
		super(type, requireComplexValue(value));
	}

	@Override
	public ComplexArray setN(@Property("n") Integer n){
		return (ComplexArray)super.setN(n);
	}

	@Override
	public ComplexArray setType(@Property("type") Array.Type type){
		return (ComplexArray)super.setType(type);
	}

	@Override
	public Collection getValue(){
		return (Collection)super.getValue();
	}

	public ComplexArray setValue(List values){
		return (ComplexArray)super.setValue(new ListValue(values));
	}

	public ComplexArray setValue(Set values){
		return (ComplexArray)super.setValue(new SetValue(values));
	}

	@Override
	public ComplexArray setValue(@Property("value") Object value){
		return (ComplexArray)super.setValue(requireComplexValue(value));
	}

	static
	public  & ComplexValue> V requireComplexValue(Object value){

		if(value == null){
			return null;
		} // End if

		if((value instanceof Collection) && (value instanceof ComplexValue)){
			return (V)value;
		}

		throw new IllegalArgumentException();
	}

	private class ListValue extends ArrayList implements ComplexValue {

		private ListValue(Collection values){
			super(values);
		}

		@Override
		public Object toSimpleValue(){
			return ArrayUtil.format(getType(), this);
		}
	}

	private class SetValue extends LinkedHashSet implements ComplexValue {

		private SetValue(Collection values){
			super(values);
		}

		@Override
		public Object toSimpleValue(){
			return ArrayUtil.format(getType(), this);
		}
	}
}