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

org.unlaxer.tinyexpression.model.EditAction Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.unlaxer.tinyexpression.model;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.unlaxer.Range;

public class EditAction{
	
	public final ActionType actionType;
	public final Optional input;
	public final Optional effectedRange;
	public EditAction(ActionType actionType) {
		super();
		this.actionType = actionType;
		this.input = Optional.empty();
		this.effectedRange = Optional.empty();
	}
	
	public EditAction(String input) {
		super();
		this.actionType = ActionType.insert;
		this.input = Optional.of(input);
		effectedRange = Optional.empty();
	}
	
	public EditAction(String input , Range range) {
		super();
		this.actionType = ActionType.insert;
		this.input = Optional.of(input);
		effectedRange = Optional.of(range);
	}

	
	public EditAction(ActionType actionType , Range range) {
		super();
		this.actionType = ActionType.insert;
		effectedRange = Optional.of(range);
		this.input = Optional.empty();
	}
	
	static final Map editActionByActionType = new HashMap();
	
	public static EditAction of(ActionType actionType){
		if(actionType == ActionType.insert){
			throw new UnsupportedOperationException("you have to specify inputString. create with constructor!");
		}
		synchronized (actionType) {
			EditAction editAction = editActionByActionType.get(actionType);
			if(editAction == null){
				editAction = new EditAction(actionType);
				editActionByActionType.put(actionType, editAction);
			}
			return editAction;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy