Show WootDocument.java syntax highlighted
package de.peerwriter.woot;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @author nabil
*/
public class WootDocument implements Serializable {
private List<WootTag> tags = new ArrayList<WootTag>();
// private String directoryPath;
private String documentName;// file name
// private String id;
private String title;
// constructor
public WootDocument(boolean b) {
if (b) {
getTags().add(WootTag.RB);
getTags().add(WootTag.RE);
}
}
// methods
public int indexOf(WootTag wr) {
boolean b = this.contains(wr);
return getTags().indexOf(wr) - 1;
}
public int indexOfVisibleNext(int from) {
int n = tags.size();
if ((from < 0) || (from >= n))
return -1;
for (int i = from + 1; i < n; ++i)
if (tags.get(i).isVisible())
return i;
return -1;
}
public int indexOfVisible(int index) {
if (index >= getTags().size() || index < 0)
return -1;
int count = 0, j = 0;
for (WootTag r : tags) {
if (r.isVisible()) {
// count++;
if (count == index)
return j;
count++;
}
j++;
}
return -1;
}
public int indexOfIdFrom(int from, WootId id) {
for (int i = from + 1; i < tags.size(); ++i)
if (tags.get(i).getWootId().equals(id))
return i;
return -1;
}
public int indexOfId(WootId id) {
int i = 0;
for (WootTag r : tags)
if (r.getWootId().equals(id))
return i;
else
++i;
return -1;
}
public void insert(WootTag wr, int pos) {
tags.add(pos + 1, wr);
}
public boolean contains(WootTag wr) {
return tags.contains(wr);
}
public boolean containsById(WootId id) {
return indexOfId(id) >= 0;
}
public WootTag elementAt(int i) {
return tags.get(i);
}
public int size() {
return tags.size() - 2;
}
public boolean isEmpty() {
return size() == 0;
}
public boolean equals(Object o) {
// assert o instanceof WootDocument;
return (o instanceof WootDocument) && ((WootDocument) o).documentName.equals(this.documentName) && ((WootDocument) o).tags.equals(this.tags);
}
// public List subSeq(WootTag b, WootTag e) {
// if ((!getRows().contains(b)) || (!getRows().contains(e))) {
// return new ArrayList();
// }
// int ib = getRows().indexOf(b) + 1;
// int ie = getRows().indexOf(e);
// if (ib > ie)
// return new ArrayList();
// return getRows().subList(ib, ie);
// }
// public Vector getInterval(WootTag r, WootTag rp, WootTag rn) {
// Vector res = new Vector();
// if (!rp.getValue().equals(WootTag.RB.getValue())) {
// res.add(ObjectCloner.deepCopy(rp));
// }
// for (int i = this.indexOf(rp); i < this.indexOf(rn); i++) {
// WootTag wr = (WootTag) this.elementAt(i);
// if (wr.getWootId().compareTo(r.getWootId()) < 0) {
// res.add(ObjectCloner.deepCopy(wr));
// }
// }
// if (!rn.getValue().equals(WootTag.RE.getValue())) {
// res.add(ObjectCloner.deepCopy(rn));
// }
// return res;
// }
public String toString() {
StringBuffer sb = new StringBuffer();
Iterator i = getTags().iterator();
while (i.hasNext()) {
WootTag r = (WootTag) i.next();
sb.append(r.getValue());
}
return sb.toString();
}
/*
* public WootTag getR(int pos) { if (pos == 0) { return WootTag.RB; }
*
* int nb = 0; for (int i = 0; i < this.size(); i++) { WootTag res; if ((res =
* this.elementAt(i)).isVisible()) { nb++; } if (nb == pos) { return res; } }
* return WootTag.RE; }
*/
public String toHumanString() {
StringBuffer sb = new StringBuffer();
for (int i = 1; i < this.tags.size() - 1; i++) {
WootTag r = (WootTag) this.tags.get(i);
if (r.isVisible()) {
sb.append(r.getValue());
sb.append("\n");
}
}
return sb.toString();
}
public String toStringInternal() {
StringBuffer sbfull = new StringBuffer();
for (WootTag r : tags)
sbfull.append(r.toString());
return sbfull.toString();
}
public String getDocumentName() {
return documentName;
}
public void setDocumentName(String pageName) {
this.documentName = pageName;
}
/*
* public String getId() { return id; }
*
* public void setId(String id) { this.id = id; }
*/
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<WootTag> getTags() {
return tags;
}
public void setTags(List<WootTag> rows) {
this.tags = rows;
}
}
See more files for this project here