# Class PatchBuilder

java.lang.Object
org.eclipse.compare.patch.PatchBuilder

public class PatchBuilder extends Object
Builder for creating IFilePatch2 and IHunk objects as well as building relationship between them.

Since:
  org.eclipse.compare.core 3.5
Restriction:
  This class is not intended to be subclassed by clients.
Restriction:
  This class is not intended to be instantiated by clients.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final char`
`ADDITION_PREFIX`
Line prefix used to mark an added lines.
`static final char`
`CONTEXT_PREFIX`
Line prefix used to mark context lines.
`static final char`
`REMOVAL_PREFIX`
Line prefix used to mark an removed lines.

## Constructor Summary

Constructors
Constructor
Description
`PatchBuilder()`

## Method Summary

Modifier and Type
Method
Description
`static IFilePatch2`
`addHunks(IFilePatch2 filePatch, IHunk[] toAdd)`
Adds IHunks to a given IFilePatch2 and performs recalculation of all hunks' after positions.
`static IFilePatch2`
`createFilePatch(IPath oldPath, long oldDate, IPath newPath, long newDate, IHunk[] hunks)`
Creates an IFilePatch2 instance and performs recalculation of all hunks' after positions.
`static IHunk`
`createHunk(int start, String[] lines)`
Creates an IHunk instance.
`static IFilePatch2`
`removeHunks(IFilePatch2 filePatch, IHunk[] toRemove)`
Removes IHunks from a given IFilePatch2 and performs recalculation of all hunks' after positions.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### CONTEXT_PREFIX

public static final char CONTEXT_PREFIX
Line prefix used to mark context lines.

See Also:
  - Constant Field Values

### ADDITION_PREFIX

public static final char ADDITION_PREFIX
Line prefix used to mark an added lines.

See Also:
  - Constant Field Values

### REMOVAL_PREFIX

public static final char REMOVAL_PREFIX
Line prefix used to mark an removed lines.

See Also:
  - Constant Field Values

## Constructor Details

### PatchBuilder

public PatchBuilder()

## Method Details

### createHunk

public static IHunk createHunk(int start, String[] lines)
Creates an IHunk instance.

Parameters:
  `start` - the start position in the before file
  `lines` - content of the hunk. Each line starts with a control character. Their meaning is as follows:
  - '+': add the line
  - '-': delete the line
  - ' ': no change, context line
Returns:
  IHunk instance

### createFilePatch

public static IFilePatch2 createFilePatch(IPath oldPath, long oldDate, IPath newPath, long newDate, IHunk[] hunks)
Creates an IFilePatch2 instance and performs recalculation of all hunks' after positions. Hunk's after position is position in the file state after applying a patch. It is affected by all the hunks that are to be applied before a given one. This recalculation is necessary to keep IFilePatch2's state coherent.

Parameters:
  `oldPath` - the path of the before state of the file
  `oldDate` - the timestamp of the before state of the file, see also `IFilePatch2.DATE_UNKNOWN`
  `newPath` - the path of the after state of the file
  `newDate` - the timestamp of the after state of the file, see also `IFilePatch2.DATE_UNKNOWN`
  `hunks` - a set of hunks to insert into IFilePatch2
Returns:
  IFilePatch2 instance

### addHunks

public static IFilePatch2 addHunks(IFilePatch2 filePatch, IHunk[] toAdd)
Adds IHunks to a given IFilePatch2 and performs recalculation of all hunks' after positions. Hunk's after position is position in the file state after applying a patch. It is affected by all the hunks that are to be applied before a given one. This recalculation is necessary to keep IFilePatch2's state coherent.

Parameters:
  `filePatch` - a file patch to add hunks to
  `toAdd` - a set of IHunks to add
Returns:
  newly created file patch with added hunks

### removeHunks

public static IFilePatch2 removeHunks(IFilePatch2 filePatch, IHunk[] toRemove)
Removes IHunks from a given IFilePatch2 and performs recalculation of all hunks' after positions. Hunk's after position is position in the file state after applying a patch. It is affected by all the hunks that are to be applied before a given one. This recalculation is necessary to keep IFilePatch2's state coherent.

Parameters:
  `filePatch` - a file patch to add hunks to
  `toRemove` - a set of IHunks to add
Returns:
  newly created file patch with removed hunks