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
e895a6df
Commit
e895a6df
authored
Sep 26, 2013
by
Lukas Jelonek
Browse files
Added new operations to intervaloperations, contains, beginsWith and endsWith
parent
21df6fad
Changes
6
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
e895a6df
...
...
@@ -49,7 +49,7 @@
<dependencies>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
-dep
</artifactId>
<artifactId>
junit
</artifactId>
<version>
4.11
</version>
<scope>
test
</scope>
</dependency>
...
...
src/main/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalOperations.java
View file @
e895a6df
...
...
@@ -22,6 +22,27 @@ package de.cebitec.common.sequencetools.intervals;
*/
public
class
IntegerIntervalOperations
implements
IntervalOperations
<
Integer
>
{
@Override
public
boolean
beginsWith
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
)
{
return
fst
.
as
(
Interval
.
Type
.
ZeroOpen
).
getStart
()
==
snd
.
as
(
Interval
.
Type
.
ZeroOpen
).
getStart
();
}
@Override
public
boolean
endsWith
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
)
{
return
fst
.
as
(
Interval
.
Type
.
ZeroOpen
).
getEnd
()
==
snd
.
as
(
Interval
.
Type
.
ZeroOpen
).
getEnd
();
}
@Override
public
boolean
contains
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
)
{
fst
=
fst
.
as
(
Interval
.
Type
.
ZeroOpen
);
snd
=
snd
.
as
(
Interval
.
Type
.
ZeroOpen
);
return
fst
.
getStart
()
<=
snd
.
getStart
()
&&
fst
.
getEnd
()
>=
snd
.
getEnd
();
}
@Override
public
boolean
overlap
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
)
{
if
(
fst
.
isEmpty
()
||
snd
.
isEmpty
())
{
...
...
src/main/java/de/cebitec/common/sequencetools/intervals/IntervalOperations.java
View file @
e895a6df
...
...
@@ -102,4 +102,31 @@ public interface IntervalOperations<L extends Number> {
* @return
*/
public
Interval
<
L
>
complement
(
Interval
<
L
>
fst
,
Interval
<
L
>
snd
);
/**
* Checks if the fst interval starts at the same position as the snd interval.
*
* @param fst
* @param snd
* @return
*/
boolean
beginsWith
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
);
/**
* Checks if the fst interval completely contains the snd interval.
*
* @param fst
* @param snd
* @return
*/
boolean
contains
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
);
/**
* Checks if the fst interval ends at the same position as the snd interval.
*
* @param fst
* @param snd
* @return
*/
boolean
endsWith
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
);
}
src/test/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalBeginsWithOperationTest.java
0 → 100644
View file @
e895a6df
/*
* 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
IntegerIntervalBeginsWithOperationTest
{
private
IntegerIntervalOperations
ops
=
new
IntegerIntervalOperations
();
private
Interval
<
Integer
>
fst
;
private
Interval
<
Integer
>
snd
;
private
boolean
beginsWith
;
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
return
Arrays
.
asList
(
new
Object
[][]{
// ZeroOpen intervals
// does not begin with
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
2
,
10
),
false
},
// same
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
0
,
10
),
true
},
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
2
,
10
,
Interval
.
Type
.
OneClosed
),
false
},
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
1
,
10
,
Interval
.
Type
.
OneClosed
),
true
},
});
}
public
IntegerIntervalBeginsWithOperationTest
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
,
boolean
beginsWith
)
{
this
.
fst
=
fst
;
this
.
snd
=
snd
;
this
.
beginsWith
=
beginsWith
;
}
@Test
public
void
testContains
()
{
assertThat
(
ops
.
beginsWith
(
fst
,
snd
),
is
(
beginsWith
));
}
}
\ No newline at end of file
src/test/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalContainsOperationTest.java
0 → 100644
View file @
e895a6df
/*
* 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
IntegerIntervalContainsOperationTest
{
private
IntegerIntervalOperations
ops
=
new
IntegerIntervalOperations
();
private
Interval
<
Integer
>
fst
;
private
Interval
<
Integer
>
snd
;
private
boolean
contains
;
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
return
Arrays
.
asList
(
new
Object
[][]{
// ZeroOpen intervals
// same intervals
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
0
,
10
),
true
},
// not contained
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
2
,
11
),
false
}
});
}
public
IntegerIntervalContainsOperationTest
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
,
boolean
contains
)
{
this
.
fst
=
fst
;
this
.
snd
=
snd
;
this
.
contains
=
contains
;
}
@Test
public
void
testContains
()
{
assertThat
(
ops
.
contains
(
fst
,
snd
),
is
(
contains
));
}
}
\ No newline at end of file
src/test/java/de/cebitec/common/sequencetools/intervals/IntegerIntervalEndsWithOperationTest.java
0 → 100644
View file @
e895a6df
/*
* 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
IntegerIntervalEndsWithOperationTest
{
private
IntegerIntervalOperations
ops
=
new
IntegerIntervalOperations
();
private
Interval
<
Integer
>
fst
;
private
Interval
<
Integer
>
snd
;
private
boolean
endsWith
;
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
return
Arrays
.
asList
(
new
Object
[][]{
// ZeroOpen intervals
// does not end with
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
2
,
9
),
false
},
// ends with
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
2
,
10
),
true
},
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
2
,
9
,
Interval
.
Type
.
OneClosed
),
false
},
{
Intervals
.
createInterval
(
0
,
10
),
Intervals
.
createInterval
(
1
,
10
,
Interval
.
Type
.
OneClosed
),
true
},});
}
public
IntegerIntervalEndsWithOperationTest
(
Interval
<
Integer
>
fst
,
Interval
<
Integer
>
snd
,
boolean
endsWith
)
{
this
.
fst
=
fst
;
this
.
snd
=
snd
;
this
.
endsWith
=
endsWith
;
}
@Test
public
void
testEndsWith
()
{
assertThat
(
ops
.
endsWith
(
fst
,
snd
),
is
(
endsWith
));
}
}
\ No newline at end of file
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