-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.yinwang.yin.value; | ||
|
||
|
||
import org.yinwang.yin.Constants; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class UnionType extends Value { | ||
|
||
public Set<Value> values = new HashSet<>(); | ||
|
||
|
||
public UnionType() { | ||
|
||
} | ||
|
||
|
||
public static UnionType union(Value... values) { | ||
UnionType u = new UnionType(); | ||
for (Value v : values) { | ||
u.add(v); | ||
} | ||
return u; | ||
} | ||
|
||
|
||
public void add(Value value) { | ||
if (value instanceof UnionType) { | ||
values.addAll(((UnionType) value).values); | ||
} else { | ||
values.add(value); | ||
} | ||
} | ||
|
||
|
||
public int size() { | ||
return values.size(); | ||
} | ||
|
||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(Constants.TUPLE_BEGIN).append("U "); | ||
|
||
boolean first = true; | ||
for (Value v : values) { | ||
if (!first) { | ||
sb.append(" "); | ||
} | ||
sb.append(v); | ||
first = false; | ||
} | ||
|
||
sb.append(Constants.TUPLE_END); | ||
return sb.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
10 | ||
"ok" | ||
true | ||
|
||
(if true 10 "ok") |