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

com.alwa.spread.IntegerFunctionResolver Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package com.alwa.spread;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;

public class IntegerFunctionResolver extends StepFunctionResolver {

    @Override
    public Object[] initialiseValuesMap(
        String valuesMapKey,
        int totalSteps,
        Object example,
        RoundingMode roundingMode,
        BigDecimal fractionalAtom) {

            Object[] values = new Object[totalSteps];
            Integer seed = (Integer) example;
            int baseValue = seed / totalSteps;
            Arrays.fill(values, baseValue);
            int step = baseValue * totalSteps;
            for (int i = 0; i < (int) example - step; i++) {
                values[i] = (int) values[i] + 1;
            }
            valuesMap.put(valuesMapKey, values);
            return valuesMap.get(valuesMapKey);
    }

    @Override
    protected boolean validateSeed(Object seed) {
        return seed != null && (Integer) seed > 0;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy