001/* 002 * ==================================================================== 003 * 004 * The Apache Software License, Version 1.1 005 * 006 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions are met: 010 * 011 * 1. Redistributions of source code must retain the above copyright notice, 012 * this list of conditions and the following disclaimer. 013 * 014 * 2. Redistributions in binary form must reproduce the above copyright notice, 015 * this list of conditions and the following disclaimer in the documentation 016 * and/or other materials provided with the distribution. 017 * 018 * 3. The end-user documentation included with the redistribution, if any, must 019 * include the following acknowledgement: "This product includes software 020 * developed by the Apache Software Foundation (http://www.apache.org/)." 021 * Alternately, this acknowledgement may appear in the software itself, if and 022 * wherever such third-party acknowledgements normally appear. 023 * 024 * 4. The names "The Jakarta Project", "Commons", and "Apache Software 025 * Foundation" must not be used to endorse or promote products derived from this 026 * software without prior written permission. For written permission, please 027 * contact apache@apache.org. 028 * 029 * 5. Products derived from this software may not be called "Apache" nor may 030 * "Apache" appear in their names without prior written permission of the Apache 031 * Software Foundation. 032 * 033 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 034 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 035 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE 036 * SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 037 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 038 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 039 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 040 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 041 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 042 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 043 * ==================================================================== 044 * 045 * This software consists of voluntary contributions made by many individuals on 046 * behalf of the Apache Software Foundation. For more information on the Apache 047 * Software Foundation, please see <http://www.apache.org/>. 048 * 049 */ 050 051package org.apache.wicket.util.diff; 052 053import java.util.List; 054 055/** 056 * Holds an add-delta between to revisions of a text. 057 * 058 * @version $Id: AddDelta.java,v 1.1 2006/03/12 00:24:21 juanca Exp $ 059 * @author <a href="mailto:juanco@suigeneris.org">Juanco Anez</a> 060 * @see Delta 061 * @see Diff 062 * @see Chunk 063 */ 064public class AddDelta extends Delta 065{ 066 /** 067 * Construct. 068 */ 069 AddDelta() 070 { 071 } 072 073 /** 074 * Construct. 075 * 076 * @param origpos 077 * @param rev 078 */ 079 public AddDelta(final int origpos, final Chunk rev) 080 { 081 init(new Chunk(origpos, 0), rev); 082 } 083 084 @Override 085 public void verify(final List<Object> target) throws PatchFailedException 086 { 087 if (original.first() > target.size()) 088 { 089 throw new PatchFailedException("original.first() > target.size()"); 090 } 091 } 092 093 @Override 094 public void applyTo(final List<Object> target) 095 { 096 revised.applyAdd(original.first(), target); 097 } 098 099 @Override 100 public void toString(final StringBuilder s) 101 { 102 s.append(original.anchor()); 103 s.append("a"); 104 s.append(revised.rangeString()); 105 s.append(Diff.NL); 106 revised.toString(s, "> ", Diff.NL); 107 } 108 109 @Override 110 public void toRCSString(final StringBuilder s, final String EOL) 111 { 112 s.append("a"); 113 s.append(original.anchor()); 114 s.append(" "); 115 s.append(revised.size()); 116 s.append(EOL); 117 revised.toString(s, "", EOL); 118 } 119 120 @Override 121 public void accept(final RevisionVisitor visitor) 122 { 123 visitor.visit(this); 124 } 125}