|
@@ -1,7 +1,18 @@
|
|
|
|
|
|
namespace Invercargill {
|
|
namespace Invercargill {
|
|
|
|
|
|
- public abstract class Enumerable<T> : Object {
|
|
|
|
|
|
+ public abstract class UntypedEnumerable : Object {
|
|
|
|
+ public abstract Type element_type { get; }
|
|
|
|
+
|
|
|
|
+ public abstract int count();
|
|
|
|
+ public abstract TPromotion try_promote_to<TPromotion>() throws PromotionError;
|
|
|
|
+ public abstract TPromotion promote_to<TPromotion>();
|
|
|
|
+ public abstract Object[] to_object_array() throws SequenceError;
|
|
|
|
+ public abstract Elements to_elements();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public abstract class Enumerable<T> : UntypedEnumerable {
|
|
|
|
|
|
public abstract Tracker<T> get_tracker();
|
|
public abstract Tracker<T> get_tracker();
|
|
|
|
|
|
@@ -54,7 +65,7 @@ namespace Invercargill {
|
|
return array;
|
|
return array;
|
|
}
|
|
}
|
|
|
|
|
|
- public virtual int count() {
|
|
|
|
|
|
+ public override int count() {
|
|
var count = 0;
|
|
var count = 0;
|
|
iterate(i => count++);
|
|
iterate(i => count++);
|
|
return count;
|
|
return count;
|
|
@@ -233,7 +244,7 @@ namespace Invercargill {
|
|
return keys.select<Grouping<TKey, T>>(g => new Grouping<TKey, T>(g, this.where(i => key_equality(g, key_selector(i)))));
|
|
return keys.select<Grouping<TKey, T>>(g => new Grouping<TKey, T>(g, this.where(i => key_equality(g, key_selector(i)))));
|
|
}
|
|
}
|
|
|
|
|
|
- public virtual Enumerable<T> with(T item) {
|
|
|
|
|
|
+ public virtual Enumerable<T> @with(T item) {
|
|
var seq = new Series<T>();
|
|
var seq = new Series<T>();
|
|
seq.add(item);
|
|
seq.add(item);
|
|
return concat(seq);
|
|
return concat(seq);
|
|
@@ -316,7 +327,7 @@ namespace Invercargill {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- public virtual Object[] to_object_array() throws SequenceError {
|
|
|
|
|
|
+ public override Object[] to_object_array() throws SequenceError {
|
|
if(!typeof(T).is_object()) {
|
|
if(!typeof(T).is_object()) {
|
|
throw new SequenceError.INVALID_TYPE("Can only make an object array of an Enumerable<T> where T is derrived from GLib.Object");
|
|
throw new SequenceError.INVALID_TYPE("Can only make an object array of an Enumerable<T> where T is derrived from GLib.Object");
|
|
}
|
|
}
|
|
@@ -329,24 +340,27 @@ namespace Invercargill {
|
|
return vector;
|
|
return vector;
|
|
}
|
|
}
|
|
|
|
|
|
- public virtual Type element_type { get {
|
|
|
|
|
|
+ public override Type element_type { get {
|
|
return typeof(T);
|
|
return typeof(T);
|
|
}}
|
|
}}
|
|
|
|
|
|
- public virtual TPromotion try_promote_to<TPromotion>() throws PromotionError {
|
|
|
|
|
|
+ public override TPromotion try_promote_to<TPromotion>() throws PromotionError {
|
|
var type = typeof(TPromotion);
|
|
var type = typeof(TPromotion);
|
|
if(get_type().is_a(type)) {
|
|
if(get_type().is_a(type)) {
|
|
// Don't promote if we are already target type
|
|
// Don't promote if we are already target type
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ resolve_promotion<TPromotion>(ref type);
|
|
|
|
+
|
|
if(!type.is_instantiatable()) {
|
|
if(!type.is_instantiatable()) {
|
|
- throw new PromotionError.INVALID_PROMOTION_TYPE(@"Provided promotion type $(type.name()) is not instansiatable.");
|
|
|
|
|
|
+ throw new PromotionError.INVALID_PROMOTION_TYPE(@"Promotion type $(type.name()) is not instansiatable.");
|
|
}
|
|
}
|
|
if(!type.is_a(typeof(Promotion))) {
|
|
if(!type.is_a(typeof(Promotion))) {
|
|
- throw new PromotionError.INVALID_PROMOTION_TYPE(@"Provided promotion type $(type.name()) does not implement Invercargill.Promotion.");
|
|
|
|
|
|
+ throw new PromotionError.INVALID_PROMOTION_TYPE(@"Promotion type $(type.name()) does not implement Invercargill.Promotion.");
|
|
}
|
|
}
|
|
if(!type.is_a(typeof(Enumerable))) {
|
|
if(!type.is_a(typeof(Enumerable))) {
|
|
- throw new PromotionError.INVALID_PROMOTION_TYPE(@"Provided promotion type $(type.name()) does not implement Invercargill.Enumerable.");
|
|
|
|
|
|
+ throw new PromotionError.INVALID_PROMOTION_TYPE(@"Promotion type $(type.name()) does not inherit from Invercargill.Enumerable.");
|
|
}
|
|
}
|
|
|
|
|
|
var promotion = Object.new(type);
|
|
var promotion = Object.new(type);
|
|
@@ -357,7 +371,7 @@ namespace Invercargill {
|
|
return ((Promotion)promotion).wrap(this);
|
|
return ((Promotion)promotion).wrap(this);
|
|
}
|
|
}
|
|
|
|
|
|
- public virtual TPromotion promote_to<TPromotion>() {
|
|
|
|
|
|
+ public override TPromotion promote_to<TPromotion>() {
|
|
try {
|
|
try {
|
|
return try_promote_to<TPromotion>();
|
|
return try_promote_to<TPromotion>();
|
|
}
|
|
}
|
|
@@ -398,6 +412,12 @@ namespace Invercargill {
|
|
return new PositionQuery<T>(this);
|
|
return new PositionQuery<T>(this);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public override Elements to_elements() {
|
|
|
|
+ var series = new ElementSeries();
|
|
|
|
+ series.add_all(select<Element>(i => new NativeElement<T>(i)));
|
|
|
|
+ return series;
|
|
|
|
+ }
|
|
|
|
+
|
|
private PredicateDelegate<T> resolve_nullable_predicate(PredicateDelegate<T>? predicate) {
|
|
private PredicateDelegate<T> resolve_nullable_predicate(PredicateDelegate<T>? predicate) {
|
|
if(predicate == null) {
|
|
if(predicate == null) {
|
|
return (p) => true;
|
|
return (p) => true;
|