[gnome-calculator/wip/ricotz/gcalc: 6/11] gcalc: Clean up ExpressionContainer (API break)
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator/wip/ricotz/gcalc: 6/11] gcalc: Clean up ExpressionContainer (API break)
- Date: Mon, 14 Oct 2019 16:12:38 +0000 (UTC)
commit 21ffed714e2d10ae3bcd30a7be98f66b179db5cd
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Oct 7 19:59:00 2019 +0200
gcalc: Clean up ExpressionContainer (API break)
gcalc/gcalc-expression-container.vala | 54 +++++++++++++++++++++--------------
1 file changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/gcalc/gcalc-expression-container.vala b/gcalc/gcalc-expression-container.vala
index 2521b389..83336b3c 100644
--- a/gcalc/gcalc-expression-container.vala
+++ b/gcalc/gcalc-expression-container.vala
@@ -20,55 +20,67 @@
*/
public class GCalc.ExpressionContainer : Gee.ArrayList<Expression>, GLib.ListModel {
public weak Expression parent { get; set; }
- public new void add (Expression exp) {
- (this as Gee.ArrayList<Expression>).add (exp);
+
+ // Gee.AbstractCollection
+ public override bool add (Expression exp) {
+ var r = base.add (exp);
exp.parent = parent;
+ return r;
}
- public new Expression remove_at (int index) {
- var r = (this as Gee.ArrayList<Expression>).remove_at (index);
+
+ public override Expression remove_at (int index) {
+ var r = base.remove_at (index);
if (r != null) {
r.parent = null;
}
return r;
}
- public new Expression remove (Expression exp) {
- var i = (this as Gee.ArrayList<Expression>).index_of (exp);
- return remove_at (i);
+
+ public override bool remove (Expression exp) {
+ var r = base.remove (exp);
+ if (r) {
+ exp.parent = null;
+ }
+ return r;
}
+
// GLib.ListModel
public Object? get_item (uint position) {
- return (this as Gee.ArrayList<Expression>).@get ((int) position) as Object;
+ return base.@get ((int) position) as Object;
}
+
public Type get_item_type () {
return typeof (Expression);
}
+
public uint get_n_items () {
- return (this as Gee.ArrayList<Expression>).size;
+ return size;
}
+
public Object? get_object (uint position) {
return get_item (position);
}
+
public Expression? find (Expression exp) {
+ unowned Variable? variable = exp as Variable;
+ if (variable == null) {
+ return null;
+ }
foreach (Expression e in this) {
- if (exp is Variable && e is Variable) {
- if ((exp as Variable).name == (e as Variable).name) {
- return e;
- }
+ if (e is Variable && ((Variable) e).name == variable.name) {
+ return e;
}
}
return null;
}
+
public Expression? find_named (string name) {
foreach (Expression e in this) {
- if (e is Variable) {
- if ((e as Variable).name == name) {
- return e;
- }
+ if (e is Variable && ((Variable) e).name == name) {
+ return e;
}
- if (e is Function) {
- if ((e as Function).name == name) {
- return e;
- }
+ if (e is Function && ((Function) e).name == name) {
+ return e;
}
}
return null;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]