Arrangement

public final class Arrangement


A class that holds data about a combination of large, medium, and small items, knows how to alter an arrangement to fit within an available space, and can assess the arrangement's desirability according to a priority heuristic.

Summary

Public constructors

Arrangement(
    int priority,
    float targetSmallSize,
    float minSmallSize,
    float maxSmallSize,
    int smallCount,
    float targetMediumSize,
    int mediumCount,
    float targetLargeSize,
    int largeCount,
    float availableSpace
)

Creates a new arrangement by taking in a number of small, medium, and large items and the size each would like to be and then fitting the sizes to work within the availableSpace.

Public methods

static Arrangement
findLowestCostArrangement(
    float availableSpace,
    float targetSmallSize,
    float minSmallSize,
    float maxSmallSize,
    int[] smallCounts,
    float targetMediumSize,
    int[] mediumCounts,
    float targetLargeSize,
    int[] largeCounts
)

Create an arrangement for all possible permutations for smallCounts and largeCounts, fit each into the available space, and return the arrangement with the lowest cost.

String

Public constructors

Arrangement

public Arrangement(
    int priority,
    float targetSmallSize,
    float minSmallSize,
    float maxSmallSize,
    int smallCount,
    float targetMediumSize,
    int mediumCount,
    float targetLargeSize,
    int largeCount,
    float availableSpace
)

Creates a new arrangement by taking in a number of small, medium, and large items and the size each would like to be and then fitting the sizes to work within the availableSpace.

Note: The values for each item size after construction will likely differ from the target values passed to the constructor since the constructor handles altering the sizes until the total count is able to fit within the space see fit for more details.

Parameters
int priority

the order in which this arrangement should be preferred against other arrangements that fit

float targetSmallSize

the size of a small item in this arrangement

float minSmallSize

the minimum size a small item is allowed to be

float maxSmallSize

the maximum size a small item is allowed to be

int smallCount

the number of small items in this arrangement

float targetMediumSize

the size of medium items in this arrangement

int mediumCount

the number of medium items in this arrangement

float targetLargeSize

the size of large items in this arrangement

int largeCount

the number of large items in this arrangement

float availableSpace

the space this arrangement needs to fit within

Public methods

findLowestCostArrangement

public static Arrangement findLowestCostArrangement(
    float availableSpace,
    float targetSmallSize,
    float minSmallSize,
    float maxSmallSize,
    int[] smallCounts,
    float targetMediumSize,
    int[] mediumCounts,
    float targetLargeSize,
    int[] largeCounts
)

Create an arrangement for all possible permutations for smallCounts and largeCounts, fit each into the available space, and return the arrangement with the lowest cost.

Keep in mind that the returned arrangements do not take into account the available space from the carousel. They will all occupy varying degrees of more or less space. The caller needs to handle sorting the returned list, picking the most desirable arrangement, and fitting the arrangement to the size of the carousel.

Parameters
float availableSpace

the space the arrangement needs to fit

float targetSmallSize

the size small items would like to be

float minSmallSize

the minimum size small items are allowed to be

float maxSmallSize

the maximum size small items are allowed to be

int[] smallCounts

an array of small item counts for a valid arrangement ordered by priority

float targetMediumSize

the size medium items would like to be

int[] mediumCounts

an array of medium item counts for a valid arrangement ordered by priority

float targetLargeSize

the size large items would like to be

int[] largeCounts

an array of large item counts for a valid arrangement ordered by priority

Returns
Arrangement

the arrangement that is considered the most desirable and has been adjusted to fit within the available space

toString

public String toString()