1/*
2 *  RopeBuilder.java
3 *  Copyright (C) 2007 Amin Ahmad.
4 *
5 *  This file is part of Java Ropes.
6 *
7 *  Java Ropes is free software: you can redistribute it and/or modify
8 *  it under the terms of the GNU General Public License as published by
9 *  the Free Software Foundation, either version 3 of the License, or
10 *  (at your option) any later version.
11 *
12 *  Java Ropes is distributed in the hope that it will be useful,
13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *  GNU General Public License for more details.
16 *
17 *  You should have received a copy of the GNU General Public License
18 *  along with Java Ropes.  If not, see <http://www.gnu.org/licenses/>.
19 *
20 *  Amin Ahmad can be contacted at amin.ahmad@gmail.com or on the web at
21 *  www.ahmadsoft.org.
22 */
23package org.ahmadsoft.ropes;
24
25import org.ahmadsoft.ropes.impl.FlatCharArrayRope;
26import org.ahmadsoft.ropes.impl.FlatCharSequenceRope;
27
28/**
29 * A factory for building ropes.
30 * @author Amin Ahmad
31 */
32public final class RopeBuilder {
33
34	/**
35	 * Construct a rope from a character array.
36	 * @param sequence a character array
37	 * @return a rope representing the underlying character array.
38	 */
39	public Rope build(final char[] sequence) {
40		return new FlatCharArrayRope(sequence);
41	}
42
43	/**
44	 * Construct a rope from an underlying character sequence.
45	 * @param sequence the underlying character sequence.
46	 * @return a rope representing the underlying character sequnce.
47	 */
48	public Rope build(final CharSequence sequence) {
49		if (sequence instanceof Rope)
50			return (Rope) sequence;
51		return new FlatCharSequenceRope(sequence);
52	}
53}
54