All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.persistence.jpa.jpql.DefaultTextEdit Maven / Gradle / Ivy

There is a newer version: 5.0.0-B05
Show newest version
/*******************************************************************************
 * Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
 * which accompanies this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *     Oracle - initial API and implementation
 *
 ******************************************************************************/
package org.eclipse.persistence.jpa.jpql;

/**
 * The default implementation of a {@link Text}, which contains the location of the change within
 * the JPQL query (offset) and the old and new values.
 *
 * @version 2.4
 * @since 2.4
 * @author Pascal Filion
 */
@SuppressWarnings("nls")
public class DefaultTextEdit implements TextEdit {

	/**
	 * The new value that should replace the old value.
	 */
	private String newValue;

	/**
	 * The location of the old value within the text.
	 */
	private int offset;

	/**
	 * The value that was found within the text that should be replaced by the new value.
	 */
	private String oldValue;

	/**
	 * Creates a new DefaultTextEdit.
	 *
	 * @param offset The location of the old value within the text
	 * @param oldValue the value that was found within the text that should be replaced by the new value
	 * @param newValue The new value that should replace the old value
	 */
	public DefaultTextEdit(int offset, String oldValue, String newValue) {
		super();
		this.offset   = offset;
		this.oldValue = oldValue;
		this.newValue = newValue;
	}

	/**
	 * {@inheritDoc}
	 */
	public int getLength() {
		return oldValue.length();
	}

	/**
	 * {@inheritDoc}
	 */
	public String getNewValue() {
		return newValue;
	}

	/**
	 * {@inheritDoc}
	 */
	public int getOffset() {
		return offset;
	}

	/**
	 * {@inheritDoc}
	 */
	public String getOldValue() {
		return oldValue;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("[");
		sb.append(offset);
		sb.append("] ");
		sb.append(oldValue);
		sb.append(" -> ");
		sb.append(newValue);
		return sb.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy