package Deadlock;

import java.io.*;

public class Convert {
    // This class implements some utility functions used for reading
    // a network description file.
    public static int Notrailingblankslength(String s) {
        int i = s.length();
        while (i>0 && s.substring(i-1,i).equals(" ")) {i--;};
        return i;
    }
    public static int StringtointArray(String s, int[] b) throws IOException{
        int pos = 0;
        int l = Notrailingblankslength(s);
        int i = 0;
        while (pos < l) {
            int newpos = s.indexOf(' ',pos);
            if (newpos <= pos) {newpos = l;};
            i++;
            if (i > b.length) throw new IOException("Array is too small");
            b[i-1] = Integer.parseInt(s.substring(pos,newpos));
            // note that first arg of substring method is inclusive
            // but second is exclusive
            pos = newpos + 1;
        }
        return i;
    }
    public static void CopyArray(int[] b1, int[] b2, int i) {
        for (int j = 0; j < i; j++) {
            b2[j] = b1[j];
        }
    }
    public static void CopyArray(Acceptance[] b1, Acceptance[] b2, int i) {
        for (int j = 0; j < i; j++) {
            b2[j] = b1[j];
        }
    }
    public static void CopyArray(Transition[] b1, Transition[] b2, int i) {
        for (int j = 0; j < i; j++) {
            b2[j] = b1[j];
        }
    }
    public static void CopyArray(State[] b1, State[] b2, int i) {
        for (int j = 0; j < i; j++) {
            b2[j] = b1[j];
        }
    }
}
