Skip to content

Commit

Permalink
Fix function key
Browse files Browse the repository at this point in the history
  • Loading branch information
ngallagher committed Aug 14, 2016
1 parent 395e91c commit efce31b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
17 changes: 6 additions & 11 deletions snap-core/src/main/java/org/snapscript/core/bind/FunctionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ public class FunctionKey {
private final Object[] types;
private final String function;
private final Object source;
private final String name;
private final int length;
private final String type;

public FunctionKey(Object source, String function, Object[] types) {
this.name = source.toString();
this.length = name.length();
public FunctionKey(Object source, String type, String function, Object[] types) {
this.function = function;
this.source = source;
this.types = types;
this.type = type;
}

@Override
Expand All @@ -31,29 +29,26 @@ public boolean equals(FunctionKey key) {
if(key.types.length != types.length) {
return false;
}
if(key.length != length) {
return false;
}
for(int i = 0; i < types.length; i++) {
if(types[i] != key.types[i]) {
return false;
}
}
return key.name.equals(name);
return key.type.equals(type);
}

@Override
public int hashCode() {
int hash = types.length;

hash = hash *31 + name.hashCode();
hash = hash *31 + type.hashCode();
hash = hash *31 + function.hashCode();

return hash;
}

@Override
public String toString() {
return name;
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,46 @@
public class FunctionKeyBuilder {

private final TypeExtractor extractor;
private final Object[] empty;

public FunctionKeyBuilder(TypeExtractor extractor) {
this.empty = new Object[]{};
this.extractor = extractor;
}

public Object create(Type source, String name, Object... list) throws Exception {
Object[] types = new Object[list.length];
public Object create(Type source, String function, Object... list) throws Exception {
String name = source.getName();

for(int i = 0; i < list.length; i++) {
Object value = list[i];
if(list.length > 0) {
Object[] types = new Object[list.length];

if(value != null) {
types[i] = extractor.getType(value);
for(int i = 0; i < list.length; i++) {
Object value = list[i];

if(value != null) {
types[i] = extractor.getType(value);
}
}
return new FunctionKey(source, name, function, types);
}
return new FunctionKey(source, name, types);
return new FunctionKey(source, name, function, empty);
}

public Object create(Module source, String name, Object... list) throws Exception {
Object[] types = new Object[list.length];
public Object create(Module source, String function, Object... list) throws Exception {
String name = source.getName();

for(int i = 0; i < list.length; i++) {
Object value = list[i];
if(list.length > 0) {
Object[] types = new Object[list.length];

if(value != null) {
types[i] = extractor.getType(value);
for(int i = 0; i < list.length; i++) {
Object value = list[i];

if(value != null) {
types[i] = extractor.getType(value);
}
}
return new FunctionKey(source, name, function, types);
}
return new FunctionKey(source, name, types);
return new FunctionKey(source, name, function, empty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Type getEntry() {

@Override
public String getName() {
return null;
return METHOD_CLOSURE; // poor name for hash?
}

@Override
Expand Down

0 comments on commit efce31b

Please sign in to comment.