Code Search for Developers
 
 
  

WootIns.java from PeerWriter at Krugle


Show WootIns.java syntax highlighted

package fr.loria.ecoo.wooki.woot.op;

import java.io.Serializable;

import fr.loria.ecoo.wooki.woot.core.WootId;
import fr.loria.ecoo.wooki.woot.core.WootPage;
import fr.loria.ecoo.wooki.woot.core.WootRow;

/**
 * @author molli
 */
public class WootIns extends WootOp implements Serializable {
	private WootRow r;

	// private WootRow rp = null;
	// private WootRow rn = null;
	private WootId idRp = null;

	private WootId idRn = null;

	// private int degree;

	/*
	 * public WootIns(WootPage wootPage, WootRow r, WootId widP, WootId widN,
	 * int degree) { this.setWootPage(wootPage); this.setNewRow(r); this.rp =
	 * getWootPage().elementAt(getWootPage().indexOfId(widP)); this.rn =
	 * getWootPage().elementAt(getWootPage().indexOfId(widN));
	 * this.setDegree(degree); }
	 */

	/*
	 * public WootIns(WootRow r, WootRow wrP, WootRow wrN, int degree) {
	 * //this.setWootPage(wootPage); this.setNewRow(r); this.rp = wrP; this.rn =
	 * wrN; }
	 */

	public WootIns(WootRow r, WootId idP, WootId idN) {
		this.setIdRp(idP);
		this.setIdRn(idN);
		this.setNewRow(r);
	}

	public void execute(int iprev, int inext, WootPage page) {
		WootId id = r.getWootId();
		while (iprev < inext - 1) {
			int degree = page.elementAt(iprev + 1).getDegree(), ipos;
			for (int i = iprev + 2; i < inext; ++i) {
				int d = page.elementAt(i).getDegree();
				if (d < degree)
					degree = d;
			}
			for (int i = iprev + 1; i < inext; ++i)
				if (page.elementAt(i).getDegree() == degree) {
					int c = page.elementAt(i).getWootId().compareTo(id);
					if (c < 0)
						iprev = i;
					else
						inext = i;
				}
		}
		page.insert(r, iprev);
	}

	public void execute(WootPage page) {
		// execute(page.indexOfId(this.getIdRp()),
		// page.indexOfId(this.getIdRn()), page);
		int iprev = page.indexOfId(idRp);
		execute(iprev, page.indexOfIdFrom(iprev, idRn), page);
	}

	// List sub = getWootPage().subSeq(getPreviousRow(), getNextRow());
	// if (sub.size() == 0) {
	// getWootPage().insert(getNewRow(), getWootPage().indexOf(getNextRow()));
	// } else {
	// Vector l = new Vector();
	// l.add(getPreviousRow());
	// for (Iterator i = sub.iterator(); i.hasNext();) {
	// WootRow wr = (WootRow) i.next();
	// if (wr.getDegree() == this.getDegree()) {
	// l.add(wr);
	// }
	// }
	// l.add(getNextRow());
	// int i = 1;
	// while (i < l.size() - 1 && getNewRow().getWootId().compareTo(((WootRow)
	// l.elementAt(i)).getWootId()) > 0) {
	// i++;
	// }
	// WootRow a, b;
	// a = (WootRow) l.elementAt(i - 1);
	// b = (WootRow) l.elementAt(i);
	// this.setDegree(this.getDegree() + 1);
	// this.setPreviousRow(a);
	// this.setNextRow(b);
	// this.execute();
	// }
	// }

	public boolean precond(WootPage page) {
		// boolean b = (page.containsById(getNextRow().getWootId()) &&
		// page.containsById(getPreviousRow().getWootId()) &&
		// !(page.containsById(getNewRow().getWootId())));
		return (page.containsById(idRp) && page.containsById(idRn) && !(page.containsById(r.getWootId())));
	}

	public int[] precond_v2(WootPage page) {
		// boolean b = (page.containsById(getNextRow().getWootId()) &&
		// page.containsById(getPreviousRow().getWootId()) &&
		// !(page.containsById(getNewRow().getWootId())));
		int p, n;
		p = page.indexOfId(this.getIdRp());
		if (p < 0) {
			return null;
		}
		n = page.indexOfIdFrom(p, this.getIdRn());
		if (n < 0) {
			return null;
		}
		if (page.indexOfId(getNewRow().getWootId()) >= 0) {// row already exist
			return null;
		} else {
			int[] indexs = new int[2];
			indexs[0] = p;
			indexs[1] = n;
			return indexs;
		}
	}

	public String toString() {
		return super.toString() + "ins(" + getNewRow() + "," + this.getIdRp() + "," + this.getIdRp() + ")";
	}

	/*
	 * public int getDegree() { return degree; }
	 * 
	 * public void setDegree(int degree) { this.degree = degree; }
	 */
	public WootRow getNewRow() {
		return r;
	}

	public void setNewRow(WootRow r) {
		this.r = r;
	}

	/*
	 * public WootRow getPreviousRow() { return rp; }
	 * 
	 * public void setPreviousRow(WootRow rp) { this.rp = rp; }
	 * 
	 * public WootRow getNextRow() { return rn; }
	 * 
	 * public void setNextRow(WootRow rn) { this.rn = rn; }
	 */
	// Not used now
	/*
	 * public void setPreviousRowFromWootId(WootId widP) { this.rp =
	 * getWootPage().elementAt(getWootPage().indexOfId(widP)); }
	 * 
	 * public void setNextRowFromWootId(WootId widN) { this.rn =
	 * getWootPage().elementAt(getWootPage().indexOfId(widN)); }
	 */

	public WootId getIdRp() {
		return idRp;
	}

	public void setIdRp(WootId idRp) {
		this.idRp = idRp;
	}

	public WootId getIdRn() {
		return idRn;
	}

	public void setIdRn(WootId idRn) {
		this.idRn = idRn;
	}
}




See more files for this project here

PeerWriter

PeerWriter is a collaborative text editor. Multiple peers can edit the same document while they see overall changes in real-time. PeerWriter is based on a decentralized infrastructure, using a non-locking concurrency protocol ensuring global consistency.

Project homepage: http://sourceforge.net/projects/peerwriter
Programming language(s): Java,XML
License: gpl2

  WootDel.java
  WootIns.java
  WootOp.java