DimChangeSet.java from gzz at Krugle
Show DimChangeSet.java syntax highlighted
/*
DimChangeSet.java
*
* Copyright (c) 2002, Ted Nelson and Tuomas Lukka
*
* This file is part of Gzz.
*
* Gzz is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Gzz is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with Gzz; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
*/
/*
* Written by Tuomas Lukka
*/
package gzz.impl;
import gzz.*;
import java.util.*;
/** A set of changes to a single dimension.
*/
public class DimChangeSet implements java.io.Serializable {
public static final int NONE = 41;
public static final int CONNECT = 42;
public static final int DISCONNECT = 43;
/** The type of change - NONE, CONNECT, DISCONNECT.
*/
public int[] changeType = new int[10] ;
/** The first parameter of the operation.
*/
public String[] p1 = new String[10];
/** The second parameter of the operation.
*/
public String[] p2 = new String[10];
public int nchanges;
public void addChange(int t, Cell o1, Cell o2) {
addChange(t, o1.getId(), o2.getId());
}
public void addChange(int t, String o1, String o2) {
if(nchanges >= changeType.length) {
int[] nchangeType = new int[changeType.length * 2];
System.arraycopy(changeType, 0, nchangeType, 0, nchanges);
changeType = nchangeType;
String[] np1 = new String[changeType.length];
System.arraycopy(p1, 0, np1, 0, nchanges);
p1 = np1;
String[] np2 = new String[changeType.length];
System.arraycopy(p2, 0, np2, 0, nchanges);
p2 = np2;
}
changeType[nchanges] = t;
p1[nchanges] = o1;
p2[nchanges] = o2;
nchanges++;
}
/** Create a new changeset which is the opposite of
* the current changeset.
*/
public DimChangeSet copy_reverse() {
DimChangeSet res = new DimChangeSet();
res.changeType = new int[nchanges];
res.p1 = new String[nchanges];
res.p2 = new String[nchanges];
res.nchanges = nchanges;
for(int i=0; i<nchanges; i++) {
int o = nchanges-1-i;
int t = changeType[i];
if(t == CONNECT) t = DISCONNECT;
else if(t == DISCONNECT) t = CONNECT;
else if(t != NONE) throw new Error("Invalid change "+t);
res.changeType[o] = t;
res.p1[o] = p1[i];
res.p2[o] = p2[i];
}
return res;
}
}
See more files for this project here