001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright 2005-2011 The ConQAT Project                                   |
004|                                                                          |
005| Licensed under the Apache License, Version 2.0 (the "License");          |
006| you may not use this file except in compliance with the License.         |
007| You may obtain a copy of the License at                                  |
008|                                                                          |
009|    http://www.apache.org/licenses/LICENSE-2.0                            |
010|                                                                          |
011| Unless required by applicable law or agreed to in writing, software      |
012| distributed under the License is distributed on an "AS IS" BASIS,        |
013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
014| See the License for the specific language governing permissions and      |
015| limitations under the License.                                           |
016+-------------------------------------------------------------------------*/
017package org.conqat.lib.commons.region;
018
019/**
020 * Regions represent intervals. Both the start and the end position are
021 * considered to be part of the region. Regions can i.e. be used to represent
022 * fragments of files.
023 * <p>
024 * This class is immutable.
025 */
026public final class Region extends SimpleRegion {
027
028        /** Version for serialization. */
029        private static final long serialVersionUID = 1;
030
031        /** Name that is used if region is created without name */
032        public static final String UNKNOWN_ORIGIN = "Unknown origin";
033
034        /**
035         * Origin of the region. Can be used to store information about who created the
036         * region.
037         */
038        private final String origin;
039
040        /**
041         * Creates a region with an origin. An empty region can be denoted with and end
042         * position smaller than start.
043         * 
044         * @param start
045         *            Inclusive start position of the region
046         * @param end
047         *            Inclusive end position of the region
048         * @param origin
049         *            Region origin. (i.e. region producer)
050         */
051        public Region(int start, int end, String origin) {
052                super(start, end);
053                this.origin = origin;
054        }
055
056        /**
057         * Creates a region with an unknown origin
058         * 
059         * @param start
060         *            Inclusive start position of the region
061         * @param end
062         *            Inclusive end position of the region
063         */
064        public Region(int start, int end) {
065                this(start, end, UNKNOWN_ORIGIN);
066        }
067
068        /** Get origin. */
069        public String getOrigin() {
070                return origin;
071        }
072}