LibreOffice Module xmerge (master)  1
Difference.java
Go to the documentation of this file.
1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  * Licensed to the Apache Software Foundation (ASF) under one or more
11  * contributor license agreements. See the NOTICE file distributed
12  * with this work for additional information regarding copyright
13  * ownership. The ASF licenses this file to you under the Apache
14  * License, Version 2.0 (the "License"); you may not use this file
15  * except in compliance with the License. You may obtain a copy of
16  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 package org.openoffice.xmerge.merger;
20 
27 public final class Difference {
28 
30  public static final int ADD = 1;
31 
33  public static final int DELETE = 2;
34 
36  public static final int CHANGE = 3;
37 
39  public static final int UNCHANGE = 4;
40 
42  private final int operation;
43 
102  private final int orgPosition;
103 
109  private final int modPosition;
110 
120  public Difference(int operation, int orgPosition,
121  int modPosition) {
122  this.operation = operation;
123  this.orgPosition = orgPosition;
124  this.modPosition = modPosition;
125  }
126 
133  public int getOperation() {
134  return operation;
135  }
136 
142  public int getOrgPosition() {
143  return orgPosition;
144  }
145 
151  public int getModPosition() {
152  return modPosition;
153  }
154 
164  @Override
165  public boolean equals(Object obj) {
166  if (obj instanceof Difference) {
167  Difference diff = (Difference) obj;
168  if ((operation == diff.operation) &&
169  (orgPosition == diff.orgPosition) &&
170  (modPosition == diff.modPosition)) {
171  return true;
172  }
173  }
174 
175  return false;
176  }
177 
178  @Override
179  public int hashCode() {
180  return 0;
181  }
182 
188  public String debug() {
189 
190  String opStr = "";
191 
192  switch (operation) {
193  case ADD:
194  opStr = "add";
195  break;
196  case DELETE:
197  opStr = "del";
198  break;
199  case CHANGE:
200  opStr = "chg";
201  break;
202  case UNCHANGE:
203  opStr = "uch";
204  break;
205  default:
206  break;
207  }
208  return "<diff orgPos=" + orgPosition + " modPos=" + modPosition +
209  " op=" + opStr + ">";
210  }
211 
218  @Override
219  public String toString() {
220 
221  return orgPosition + " " + modPosition + " " + operation;
222  }
223 }
int getOrgPosition()
Get the original.
static final int DELETE
Delete operation.
Definition: Difference.java:33
int getModPosition()
Get the modified.
final int modPosition
The position of the content that should be operated (modified iterator).
static final int CHANGE
Change operation.
Definition: Difference.java:36
Difference(int operation, int orgPosition, int modPosition)
Constructor.
int getOperation()
Get the operation of the.
String debug()
Display debug information.
static final int UNCHANGE
Unchange operation (i.e.
Definition: Difference.java:39
final int orgPosition
The position of the content that should be operated on (original.
static final int ADD
Add operation.
Definition: Difference.java:30
final int operation
The action of the diff - either ADD or DELETE.
Definition: Difference.java:42
String toString()
Returns position and operation values as a single string.