Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
GenDB3
lib.intervals
Commits
0b735b09
Commit
0b735b09
authored
Nov 27, 2013
by
Lukas Jelonek
Browse files
Added leftOf and rightOf interval operations
parent
7604d175
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalOperations.java
View file @
0b735b09
...
...
@@ -174,4 +174,28 @@ public class IntegerIntervalOperations implements IntervalOperations<Integer> {
Interval
<
Integer
>
as
=
i
.
as
(
Interval
.
Type
.
ZeroOpen
);
return
Intervals
.
createInterval
(
as
.
getStart
()
+
by
,
as
.
getEnd
()
+
by
);
}
@Override
public
boolean
leftOf
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
)
{
// normalize
fst
=
fst
.
as
(
Interval
.
Type
.
OneClosed
);
snd
=
snd
.
as
(
Interval
.
Type
.
OneClosed
);
if
(
overlap
(
fst
,
snd
))
{
return
false
;
}
else
{
return
fst
.
getEnd
()
<
snd
.
getStart
();
}
}
@Override
public
boolean
rightOf
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
)
{
// normalize
fst
=
fst
.
as
(
Interval
.
Type
.
OneClosed
);
snd
=
snd
.
as
(
Interval
.
Type
.
OneClosed
);
if
(
overlap
(
fst
,
snd
))
{
return
false
;
}
else
{
return
snd
.
getEnd
()
<
fst
.
getStart
();
}
}
}
src/main/java/de/cebitec/common/sequencetools/intervals/IntervalOperations.java
View file @
0b735b09
...
...
@@ -129,4 +129,23 @@ public interface IntervalOperations<L extends Number> {
* @return
*/
boolean
endsWith
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
);
/**
* Checks if the fst interval does not overlap with the snd interval and is left of it.
*
* @param fst
* @param snd
* @return
*/
boolean
leftOf
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
);
/**
* Checks if the fst interval does not overlap with the snd interval and is right of it
*
* @param fst
* @param snd
* @return
*/
boolean
rightOf
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
);
}
src/test/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalLeftOfOperationTest.java
0 → 100644
View file @
0b735b09
/*
* Copyright (C) 2013 Lukas Jelonek <ljelonek at cebitec.uni-bielefeld.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
de.cebitec.common.sequencetools.intervals
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
hamcrest
.
Matchers
.*;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
/**
*
* @author Lukas Jelonek <ljelonek at cebitec.uni-bielefeld.de>
*/
@RunWith
(
Parameterized
.
class
)
public
class
IntegerIntervalLeftOfOperationTest
{
private
IntegerIntervalOperations
ops
=
new
IntegerIntervalOperations
();
private
Interval
<
Integer
>
fst
;
private
Interval
<
Integer
>
snd
;
private
boolean
result
;
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
return
Arrays
.
asList
(
new
Object
[][]{
// ZeroOpen intervals
{
Intervals
.
createInterval
(
0
,
2
),
Intervals
.
createInterval
(
2
,
3
),
true
},
{
Intervals
.
createInterval
(
0
,
1
),
Intervals
.
createInterval
(
2
,
3
),
true
},
{
Intervals
.
createInterval
(
0
,
3
),
Intervals
.
createInterval
(
2
,
3
),
false
},
// OneClosed intervals
{
Intervals
.
createInterval
(
0
,
1
,
Interval
.
Type
.
OneClosed
),
Intervals
.
createInterval
(
2
,
3
,
Interval
.
Type
.
OneClosed
),
true
},
{
Intervals
.
createInterval
(
0
,
0
,
Interval
.
Type
.
OneClosed
),
Intervals
.
createInterval
(
2
,
3
,
Interval
.
Type
.
OneClosed
),
true
},
{
Intervals
.
createInterval
(
0
,
2
,
Interval
.
Type
.
OneClosed
),
Intervals
.
createInterval
(
2
,
3
,
Interval
.
Type
.
OneClosed
),
false
}
}
);
}
public
IntegerIntervalLeftOfOperationTest
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
,
boolean
result
)
{
this
.
fst
=
fst
;
this
.
snd
=
snd
;
this
.
result
=
result
;
}
@Test
public
void
testLeftOf
()
{
assertThat
(
ops
.
leftOf
(
fst
,
snd
),
is
(
result
));
}
}
src/test/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalRightOfOperationTest.java
0 → 100644
View file @
0b735b09
/*
* Copyright (C) 2013 Lukas Jelonek <ljelonek at cebitec.uni-bielefeld.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package
de.cebitec.common.sequencetools.intervals
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
hamcrest
.
Matchers
.*;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
/**
*
* @author Lukas Jelonek <ljelonek at cebitec.uni-bielefeld.de>
*/
@RunWith
(
Parameterized
.
class
)
public
class
IntegerIntervalRightOfOperationTest
{
private
IntegerIntervalOperations
ops
=
new
IntegerIntervalOperations
();
private
Interval
<
Integer
>
fst
;
private
Interval
<
Integer
>
snd
;
private
boolean
result
;
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
return
Arrays
.
asList
(
new
Object
[][]{
// ZeroOpen intervals
{
Intervals
.
createInterval
(
2
,
3
),
Intervals
.
createInterval
(
0
,
2
),
true
},
{
Intervals
.
createInterval
(
2
,
3
),
Intervals
.
createInterval
(
0
,
1
),
true
},
{
Intervals
.
createInterval
(
2
,
3
),
Intervals
.
createInterval
(
0
,
3
),
false
},
{
Intervals
.
createInterval
(
0
,
1
),
Intervals
.
createInterval
(
2
,
3
),
false
},
// OneClosed intervals
{
Intervals
.
createInterval
(
2
,
3
,
Interval
.
Type
.
OneClosed
),
Intervals
.
createInterval
(
0
,
1
,
Interval
.
Type
.
OneClosed
),
true
},
{
Intervals
.
createInterval
(
2
,
3
,
Interval
.
Type
.
OneClosed
),
Intervals
.
createInterval
(
0
,
0
,
Interval
.
Type
.
OneClosed
),
true
},
{
Intervals
.
createInterval
(
2
,
3
,
Interval
.
Type
.
OneClosed
),
Intervals
.
createInterval
(
0
,
2
,
Interval
.
Type
.
OneClosed
),
false
}
}
);
}
public
IntegerIntervalRightOfOperationTest
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
,
boolean
result
)
{
this
.
fst
=
fst
;
this
.
snd
=
snd
;
this
.
result
=
result
;
}
@Test
public
void
testRightOf
()
{
assertThat
(
ops
.
rightOf
(
fst
,
snd
),
is
(
result
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment