package com.hifiremote.jpsusbraw;

import java.util.Arrays;

import com.hifiremote.jpsusbraw.DevicePath;

class DevicePathBuilder {
    private byte[] path = new byte[7]; // the USB tree is limited depth
    private int level = 0;

    public void push() {
        if (level >= 7)
            throw new IllegalStateException("the USB supports only seven levels");

        level++;
    }

    public void pop() {
        if (level <= 0)
            throw new IllegalStateException("level may not be negative");

        level--;
    }

    public void set (byte value) {
        path[ level ] = value;
    }

    public DevicePath toDevicePath() {
        int last = level;

        if (path[ last ] == 0)
            last--;

        return new DevicePath( Arrays.copyOf( path, last + 1 ) );
    }

    public String toString() {
        return Arrays.toString( path );
    }
}

@@ -501,24 +501,51 @@
 egative%22);%0A%0A
+        path%5B level %5D = 0;%0A
         leve

Clear old path segment in DevicePathBuilder.pop().