Add collections documentation

This commit is contained in:
aNNiMON 2023-12-08 22:32:06 +02:00 committed by Victor Melnik
parent 02fd959e58
commit 73662814ca
3 changed files with 31 additions and 14 deletions

View File

@ -7,6 +7,7 @@ OUTPUT_PATH_FMT = OUTPUT_DIR_FMT + "/%s.md"
LANGS = ["en", "ru"] LANGS = ["en", "ru"]
MODULES = [ MODULES = [
"std", "std",
"collections",
"date", "date",
"downloader", "downloader",
"files", "files",

View File

@ -0,0 +1,26 @@
name: collections
scope: both
desc: Contains functions for working with collections
desc_ru: Содержит функции для работы с коллекциями
since: 2.0.0
functions:
- name: hashMap
args: "fromMap = {}"
desc: creates a new HashMap based on `fromMap` values
desc_ru: создаёт новый HashMap из значений `fromMap`
- name: linkedHashMap
args: "fromMap = {}"
desc: creates a new LinkedHashMap based on `fromMap` values
desc_ru: создаёт новый LinkedHashMap из значений `fromMap`
- name: concurrentHashMap
args: "fromMap = {}"
desc: creates a new ConcurrentHashMap based on `fromMap` values
desc_ru: создаёт новый ConcurrentHashMap из значений `fromMap`
- name: treeMap
args: "fromMap = {}, comparator = def(a, b) = 0"
desc: creates a new TreeMap based on `fromMap` values and `comparator`
desc_ru: создаёт новый TreeMap из значений `fromMap` и компаратора `comparator`
- name: concurrentSkipListMap
args: "fromMap = {}, comparator = def(a, b) = 0"
desc: creates a new ConcurrentSkipListMap based on `fromMap` values and `comparator`
desc_ru: создаёт новый ConcurrentSkipListMap из значений `fromMap` и компаратора `comparator`

View File

@ -53,24 +53,14 @@ public class collections implements Module {
case 0: // treeMap() case 0: // treeMap()
map = mapSupplier.get(); map = mapSupplier.get();
break; break;
case 1: // treeMap(map) || treeMap(comparator) case 1: // treeMap(map)
if (args[0].type() == Types.MAP) {
map = mapSupplier.get(); map = mapSupplier.get();
map.putAll(((MapValue) args[0]).getMap()); map.putAll(ValueUtils.consumeMap(args[0], 0).getMap());
} else if (args[0].type() == Types.FUNCTION) {
final Function comparator = ValueUtils.consumeFunction(args[0], 0);
map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt());
} else {
throw new TypeException("Map or comparator function expected in first argument");
}
break; break;
case 2: // treeMap(map, comparator) case 2: // treeMap(map, comparator)
if (args[0].type() != Types.MAP) {
throw new TypeException("Map expected in first argument");
}
final Function comparator = ValueUtils.consumeFunction(args[1], 1); final Function comparator = ValueUtils.consumeFunction(args[1], 1);
map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt()); map = comparatorToMapFunction.apply((o1, o2) -> comparator.execute(o1, o2).asInt());
map.putAll(((MapValue) args[0]).getMap()); map.putAll(ValueUtils.consumeMap(args[0], 0).getMap());
break; break;
default: default:
throw new IllegalStateException(); throw new IllegalStateException();