Add filter: VersionInRange, VersionOutOfRange

This commit is contained in:
Matthias Beyer 2016-03-15 23:18:11 +01:00
parent 21013dd76f
commit 98dde5d0d1
2 changed files with 52 additions and 1 deletions

View file

@ -1,3 +1,4 @@
pub mod eq; pub mod eq;
pub mod lt;
pub mod gt; pub mod gt;
pub mod lt;
pub mod range;

View file

@ -0,0 +1,50 @@
use semver::Version;
use libimagstore::store::Entry;
use builtin::header::version::gt::VersionGt;
use builtin::header::version::lt::VersionLt;
use filter::Filter;
use ops::and::And;
use ops::not::Not;
pub struct VersionInRange {
and: And,
}
impl VersionInRange {
pub fn new(lowerbound: Version, upperbound: Version) -> VersionInRange {
VersionInRange { and: VersionGt::new(lowerbound).and(Box::new(VersionLt::new(upperbound))) }
}
}
impl Filter for VersionInRange {
fn filter(&self, e: &Entry) -> bool {
self.and.filter(e)
}
}
pub struct VersionOutOfRange {
not: Not
}
impl VersionOutOfRange {
pub fn new(lowerbound: Version, upperbound: Version) -> VersionOutOfRange {
VersionOutOfRange { not: VersionInRange::new(lowerbound, upperbound).not() }
}
}
impl Filter for VersionOutOfRange {
fn filter(&self, e: &Entry) -> bool {
self.not.filter(e)
}
}