Example usage for com.badlogic.gdx.utils IntArray shrink

List of usage examples for com.badlogic.gdx.utils IntArray shrink

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils IntArray shrink.

Prototype

public int[] shrink() 

Source Link

Document

Reduces the size of the backing array to the size of the actual items.

Usage

From source file:com.weimingtom.iteye.simplerpg.tiled.TileMapRenderer.java

License:Apache License

private static IntArray createFromCSV(String values) {
    IntArray list = new IntArray(false, (values.length() + 1) / 2);
    StringTokenizer st = new StringTokenizer(values, ",");
    while (st.hasMoreTokens()) {
        list.add(Integer.parseInt(st.nextToken()));
    }/*from  w  w w.  j  a  va2  s  .com*/
    list.shrink();
    return list;
}

From source file:se.toxbee.sleepfighter.model.AlarmList.java

License:Open Source License

/**
 * <p>Finds the lowest unnamed placement number.</p>
 *
 * <p>Time complexity: O(n),<br/>
 * Space complexity: O(n).</p>//from  ww  w  .ja  v a 2s.co  m
 *
 * @see Alarm#getUnnamedPlacement()
 * @return the lowest unnamed placement number.
 */
public int findLowestUnnamedPlacement() {
    // Bail early if we can.
    if (this.size() == 0) {
        return 1;
    }

    // First extract the unnamed placements defined.
    IntArray arr = new IntArray();
    arr.ordered = false;
    for (Alarm alarm : this) {
        if (alarm.isUnnamed()) {
            int place = alarm.getUnnamedPlacement();
            if (place > 0) {
                arr.add(place);
            }
        }
    }

    // Another opportunity to bail.
    if (arr.size == 0) {
        return 1;
    }

    arr.shrink();

    // Set all bits < N
    BitSet bits = new BitSet(arr.size);
    for (int i = 0; i < arr.size; ++i) {
        int v = arr.get(i) - 1;
        if (v < arr.size) {
            bits.set(v);
        }
    }

    // Find first false bit.
    return bits.nextClearBit(0) + 1;
}