What's new? | Help | Directory | Sign in
Google
heron-language
Heron is an object-oriented programming language for model driven architecture
  
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

import java.util.ArrayList;

public class Collection<T> extends ArrayList<T> {
public T min(AnonymousFunction f) {
Comparable c = null;
T ret = null;
Collection<Object> args = new Collection<Object>();
args.add(null);
for (T tmp : this) {
args.set(0, tmp);
Comparable cTmp = (Comparable)f.apply(args);
if (ret == null) {
ret = tmp;
c = cTmp;
}
else {
if (cTmp.compareTo(c) < 0) {
c = cTmp;
ret = tmp;
}
}
}
return ret;
}

Collection<T> filter(AnonymousFunction f) {
Collection<T> ret = new Collection<T>();
Collection<Object> args = new Collection<Object>();
args.add(null);
for (int i=size() - 1; i >= 0; --i) {
args.set(0, get(i));
boolean bTmp = (Boolean)f.apply(args);
if (bTmp) {
ret.add(get(i));
}
}
return ret;
}

Collection<T> map(AnonymousFunction f) {
Collection<T> ret = new Collection<T>();
Collection<Object> args = new Collection<Object>();
args.add(null);
for (int i=size() - 1; i >= 0; --i) {
args.set(0, get(i));
ret.add((T)f.apply(args));
}
return ret;
}

public void concat(Collection<T> coll) {
addAll(coll);
}
}
Show details Hide details

Change log

r46 by cdiggins on Apr 08, 2008   Diff

 
Go to: 
Project members, sign in to write a code review

Older revisions

r41 by cdiggins on Feb 23, 2008   Diff

 
All revisions of this file

File info

Size: 1222 bytes, 55 lines