001: package it.unimi.dsi.mg4j.search;
002:
003: /*
004: * MG4J: Managing Gigabytes for Java
005: *
006: * Copyright (C) 2003-2007 Paolo Boldi and Sebastiano Vigna
007: *
008: * This library is free software; you can redistribute it and/or modify it
009: * under the terms of the GNU Lesser General Public License as published by the Free
010: * Software Foundation; either version 2.1 of the License, or (at your option)
011: * any later version.
012: *
013: * This library is distributed in the hope that it will be useful, but
014: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
015: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
016: * for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023:
024: import java.util.Comparator;
025:
026: /** A class providing static methods and objects that do useful things with intervals.
027: *
028: * @see it.unimi.dsi.mg4j.search.Interval
029: * @deprecated Moved to <code>dsiutils</code>.
030: */
031:
032: @Deprecated
033: public class Intervals {
034:
035: private Intervals() {
036: }
037:
038: public final static Interval[] EMPTY_ARRAY = {};
039:
040: /** An empty (singleton) interval. */
041: public final static Interval EMPTY_INTERVAL = new Interval(1, 0);
042:
043: /** A singleton located at −&infty;. */
044: public final static Interval MINUS_INFINITY = new Interval(
045: Integer.MIN_VALUE, Integer.MIN_VALUE);
046:
047: /** A comparator between intervals defined as follows:
048: * [<var>a</var>..<var>b</var>] is less than [<var>a</var>'..<var>b</var>'] iff
049: * the first interval starts before or prolongs the second one, that is,
050: * iff <var>a</var> < <var>a</var>' or <var>a</var>=<var>a</var>' and <var>b</var>' < <var>b</var>.
051: */
052: public final static Comparator<Interval> STARTS_BEFORE_OR_PROLONGS = new Comparator<Interval>() {
053: public int compare(final Interval i1, final Interval i2) {
054: if (i1.left != i2.left)
055: return i1.left < i2.left ? -1 : 1;
056: if (i1.right != i2.right)
057: return i2.right < i1.right ? -1 : 1;
058: return 0;
059: }
060: };
061:
062: /** A comparator between intervals defined as follows:
063: * [<var>a</var>..<var>b</var>] is less than [<var>a</var>'..<var>b</var>'] iff
064: * the first interval ends before or is a suffix of the second one, that is,
065: * iff <var>b</var> < <var>b</var>' or <var>b</var>=<var>b</var>' and <var>a</var>' < <var>a</var>.
066: */
067: public final static Comparator<Interval> ENDS_BEFORE_OR_IS_SUFFIX = new Comparator<Interval>() {
068: public int compare(final Interval i1, final Interval i2) {
069: if (i1.right != i2.right)
070: return i1.right < i2.right ? -1 : 1;
071: if (i1.left != i2.left)
072: return i2.left < i1.left ? -1 : 1;
073: return 0;
074: }
075: };
076:
077: /** A comparator between intervals defined as follows:
078: * [<var>a</var>..<var>b</var>] is less than [<var>a</var>'..<var>b</var>']
079: * iff the first interval ends <em>after</em> the second one, that is,
080: * iff <var>b</var>' < <var>b</var>.
081: */
082: public final static Comparator<Interval> ENDS_AFTER = new Comparator<Interval>() {
083: public int compare(final Interval i1, final Interval i2) {
084: if (i1.right != i2.right)
085: return i2.right < i1.right ? -1 : 1;
086: return 0;
087: }
088: };
089:
090: /** A comparator between intervals defined as follows:
091: * [<var>a</var>..<var>b</var>] is less than [<var>a</var>'..<var>b</var>']
092: * iff the first interval ends <em>before</em> the second one, that is,
093: * iff <var>b</var>' > <var>b</var>.
094: */
095: public final static Comparator<Interval> ENDS_BEFORE = new Comparator<Interval>() {
096: public int compare(final Interval i1, final Interval i2) {
097: if (i1.right != i2.right)
098: return i2.right < i1.right ? 1 : -1;
099: return 0;
100: }
101: };
102:
103: /** A comparator between intervals based on their length. */
104: public final static Comparator<Interval> LENGTH_COMPARATOR = new Comparator<Interval>() {
105: public int compare(final Interval i1, final Interval i2) {
106: return i1.length() - i2.length();
107: }
108: };
109: }
|