
com.day.util.diff.Document Maven / Gradle / Ivy
/*
* $URL$
* $Id$
*
* Copyright 1997-2006 Day Management AG
* Barfuesserplatz 6, 4001 Basel, Switzerland
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Day Management AG, ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Day.
*/
package com.day.util.diff;
/**
* A document represents a list of elements and have a source.
*
* @author tripod
* @version $Rev$, $Date$
*/
public class Document {
/**
* The CVS/SVN id
*/
static final String CVS_ID = "$URL$ $Rev$ $Date$";
/**
* the source information of this document
*/
private final DocumentSource source;
/**
* the array of elements that form this document
*/
private final Element[] elements;
/**
* Create a new document with the given source and element factory
* @param source the source
* @param factory the element factory
*/
public Document(DocumentSource source, ElementsFactory factory) {
this.source = source;
this.elements = factory.getElements();
}
/**
* Return the source of this document
* @return the source.
*/
public DocumentSource getSource() {
return source;
}
/**
* Return the elements of this document
* @return the elements.
*/
public Element[] getElements() {
return elements;
}
/**
* Create a diff between this document and the given one.
*
* @param right the other document to diff to.
* @return a diff.
*/
public DocumentDiff diff(Document right) {
return new DocumentDiff(this, right);
}
/**
* Create a diff between the given document and this one.
* @param left the other document.
* @return a diff
*/
public DocumentDiff reverseDiff(Document left) {
return new DocumentDiff(left, this);
}
/**
* Create a tree-way-diff using this document as base.
*
* @param left the left document
* @param right the right document
* @return a diff3
*/
public DocumentDiff3 diff3(Document left, Document right) {
return new DocumentDiff3(this, left, right);
}
/**
* Elements form a document.
*/
public static interface Element {
/**
* Returns the string representation of this element. If the elements
* were generated originally from a string they should return the
* exact string again.
* @return the string of this element.
*/
String getString();
}
/**
* The annotated element include the document source. This can be used
* to create an annotated document.
*/
public static interface AnnotatedElement extends Element {
/**
* Returns the document source of this element.
* @return the source of this element.
*/
DocumentSource getDocumentSource();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy