Skip to content

Commit efce31b

Browse files
committed
Fix function key
1 parent 395e91c commit efce31b

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

snap-core/src/main/java/org/snapscript/core/bind/FunctionKey.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ public class FunctionKey {
55
private final Object[] types;
66
private final String function;
77
private final Object source;
8-
private final String name;
9-
private final int length;
8+
private final String type;
109

11-
public FunctionKey(Object source, String function, Object[] types) {
12-
this.name = source.toString();
13-
this.length = name.length();
10+
public FunctionKey(Object source, String type, String function, Object[] types) {
1411
this.function = function;
1512
this.source = source;
1613
this.types = types;
14+
this.type = type;
1715
}
1816

1917
@Override
@@ -31,29 +29,26 @@ public boolean equals(FunctionKey key) {
3129
if(key.types.length != types.length) {
3230
return false;
3331
}
34-
if(key.length != length) {
35-
return false;
36-
}
3732
for(int i = 0; i < types.length; i++) {
3833
if(types[i] != key.types[i]) {
3934
return false;
4035
}
4136
}
42-
return key.name.equals(name);
37+
return key.type.equals(type);
4338
}
4439

4540
@Override
4641
public int hashCode() {
4742
int hash = types.length;
4843

49-
hash = hash *31 + name.hashCode();
44+
hash = hash *31 + type.hashCode();
5045
hash = hash *31 + function.hashCode();
5146

5247
return hash;
5348
}
5449

5550
@Override
5651
public String toString() {
57-
return name;
52+
return type;
5853
}
5954
}

snap-core/src/main/java/org/snapscript/core/bind/FunctionKeyBuilder.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,46 @@
77
public class FunctionKeyBuilder {
88

99
private final TypeExtractor extractor;
10+
private final Object[] empty;
1011

1112
public FunctionKeyBuilder(TypeExtractor extractor) {
13+
this.empty = new Object[]{};
1214
this.extractor = extractor;
1315
}
1416

15-
public Object create(Type source, String name, Object... list) throws Exception {
16-
Object[] types = new Object[list.length];
17+
public Object create(Type source, String function, Object... list) throws Exception {
18+
String name = source.getName();
1719

18-
for(int i = 0; i < list.length; i++) {
19-
Object value = list[i];
20+
if(list.length > 0) {
21+
Object[] types = new Object[list.length];
2022

21-
if(value != null) {
22-
types[i] = extractor.getType(value);
23+
for(int i = 0; i < list.length; i++) {
24+
Object value = list[i];
25+
26+
if(value != null) {
27+
types[i] = extractor.getType(value);
28+
}
2329
}
30+
return new FunctionKey(source, name, function, types);
2431
}
25-
return new FunctionKey(source, name, types);
32+
return new FunctionKey(source, name, function, empty);
2633
}
2734

28-
public Object create(Module source, String name, Object... list) throws Exception {
29-
Object[] types = new Object[list.length];
35+
public Object create(Module source, String function, Object... list) throws Exception {
36+
String name = source.getName();
3037

31-
for(int i = 0; i < list.length; i++) {
32-
Object value = list[i];
38+
if(list.length > 0) {
39+
Object[] types = new Object[list.length];
3340

34-
if(value != null) {
35-
types[i] = extractor.getType(value);
41+
for(int i = 0; i < list.length; i++) {
42+
Object value = list[i];
43+
44+
if(value != null) {
45+
types[i] = extractor.getType(value);
46+
}
3647
}
48+
return new FunctionKey(source, name, function, types);
3749
}
38-
return new FunctionKey(source, name, types);
50+
return new FunctionKey(source, name, function, empty);
3951
}
4052
}

snap-core/src/main/java/org/snapscript/core/function/FunctionType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Type getEntry() {
6969

7070
@Override
7171
public String getName() {
72-
return null;
72+
return METHOD_CLOSURE; // poor name for hash?
7373
}
7474

7575
@Override

0 commit comments

Comments
 (0)