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

com.anrisoftware.prefdialog.csvimportdialog.panelproperties.advancedproperties.LineEnd Maven / Gradle / Ivy

/*
 * Copyright 2013-2015 Erwin Müller 
 *
 * This file is part of prefdialog-csvimportdialog.
 *
 * prefdialog-csvimportdialog is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * prefdialog-csvimportdialog is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with prefdialog-csvimportdialog. If not, see .
 */
package com.anrisoftware.prefdialog.csvimportdialog.panelproperties.advancedproperties;

import static java.lang.String.format;

/**
 * Possible line end symbols.
 * 
 * @author Erwin Mueller, [email protected]
 * @since 3.0
 */
public enum LineEnd {

	/**
	 * Unix like symbols.
	 */
	UNIX("\n"),

	/**
	 * Windows like symbols.
	 */
	WINDOWS("\r\n"),

	/**
	 * System default symbols.
	 */
	DEFAULT(null);

	private static final String UNKNOWN = "Unknown line symbol '%s'";

	private static final String LINE_SEP = System.getProperty("line.separator");

	private String symbols;

	private LineEnd(String symbols) {
		this.symbols = symbols;
	}

	/**
	 * Returns the line end symbols.
	 * 
	 * @return the symbols {@link String}.
	 */
	public String getSymbols() {
		if (this == DEFAULT) {
			return LINE_SEP;
		}
		return symbols;
	}

	/**
	 * Parses the string symbols to a line end symbol.
	 * 
	 * @param symbols
	 *            the symbols to parse.
	 * 
	 * @return the {@link LineEnd}.
	 * 
	 * @throws IllegalArgumentException
	 *             if the specified symbols string is unknown.
	 */
	public static LineEnd parse(String symbols) {
		if (symbols.equals(LINE_SEP)) {
			return LineEnd.DEFAULT;
		} else {
			for (LineEnd symbol : values()) {
				if (symbol.getSymbols().equals(symbols)) {
					return symbol;
				}
			}
		}
		throw new IllegalArgumentException(format(UNKNOWN, symbols));
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy