use of org.apache.commons.lang.math.IntRange in project pinot by linkedin.
the class DataGenerator method init.
public void init(DataGeneratorSpec spec) throws IOException {
genSpec = spec;
outDir = new File(genSpec.getOutputDir());
if (outDir.exists() && !genSpec.isOverrideOutDir()) {
LOGGER.error("output directory already exists, and override is set to false");
throw new RuntimeException("output directory exists");
}
if (outDir.exists()) {
FileUtils.deleteDirectory(outDir);
}
outDir.mkdir();
for (final String column : genSpec.getColumns()) {
DataType dataType = genSpec.getDataTypesMap().get(column);
if (genSpec.getCardinalityMap().containsKey(column)) {
generators.put(column, GeneratorFactory.getGeneratorFor(dataType, genSpec.getCardinalityMap().get(column)));
} else if (genSpec.getRangeMap().containsKey(column)) {
IntRange range = genSpec.getRangeMap().get(column);
generators.put(column, GeneratorFactory.getGeneratorFor(dataType, range.getMinimumInteger(), range.getMaximumInteger()));
} else {
LOGGER.error("cardinality for this column does not exist : " + column);
throw new RuntimeException("cardinality for this column does not exist");
}
generators.get(column).init();
}
}
use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class GotoSymbolContributor method getItemsFromCallDefinitionClause.
private void getItemsFromCallDefinitionClause(@NotNull List<NavigationItem> items, @NotNull EnclosingModularByCall enclosingModularByCall, @NotNull Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple, @NotNull Call call) {
Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(call);
if (nameArityRange != null) {
String callName = nameArityRange.first;
IntRange arityRange = nameArityRange.second;
Timed.Time time = CallDefinitionClause.time(call);
Modular modular = enclosingModularByCall.putNew(call);
if (modular == null) {
// don't throw an error if really EEX, but has wrong extension
if (!call.getText().contains("<%=")) {
error("Cannot find enclosing Modular", call);
}
} else {
for (int arity = arityRange.getMinimumInteger(); arity <= arityRange.getMaximumInteger(); arity++) {
CallDefinition.Tuple tuple = new CallDefinition.Tuple(modular, time, callName, arity);
CallDefinition callDefinition = callDefinitionByTuple.get(tuple);
if (callDefinition == null) {
callDefinition = new CallDefinition(tuple.modular, tuple.time, tuple.name, tuple.arity);
items.add(callDefinition);
callDefinitionByTuple.put(tuple, callDefinition);
}
CallDefinitionClause callDefinitionClause = callDefinition.clause(call);
items.add(callDefinitionClause);
}
}
}
}
use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class ImportTest method testCallDefinitionClauseCallWhileImportModuleExceptNameArity.
public void testCallDefinitionClauseCallWhileImportModuleExceptNameArity() {
myFixture.configureByFiles("import_module_except_name_arity.ex", "imported.ex");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
PsiElement maybeCall = elementAtCaret.getParent().getParent();
assertInstanceOf(maybeCall, Call.class);
Call call = (Call) maybeCall;
assertTrue(Import.is(call));
final ArrayList<Call> importedCallList = new ArrayList<Call>();
Import.callDefinitionClauseCallWhile(call, new Function<Call, Boolean>() {
@Override
public Boolean fun(Call call) {
importedCallList.add(call);
return true;
}
});
assertEquals(2, importedCallList.size());
List<Pair<String, IntRange>> nameArityRangeList = ContainerUtil.map(importedCallList, new Function<Call, Pair<String, IntRange>>() {
@Override
public Pair<String, IntRange> fun(Call call) {
return nameArityRange(call);
}
});
assertContainsElements(Arrays.asList(pair("imported", new IntRange(1)), pair("imported", new IntRange(0))), nameArityRangeList);
}
use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class ImportTest method testCallDefinitionClauseCallWhileImportModuleOnlyNameArity.
public void testCallDefinitionClauseCallWhileImportModuleOnlyNameArity() {
myFixture.configureByFiles("import_module_only_name_arity.ex", "imported.ex");
PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
assertNotNull(elementAtCaret);
PsiElement maybeCall = elementAtCaret.getParent().getParent();
assertInstanceOf(maybeCall, Call.class);
Call call = (Call) maybeCall;
assertTrue(Import.is(call));
final ArrayList<Call> importedCallList = new ArrayList<Call>();
Import.callDefinitionClauseCallWhile(call, new Function<Call, Boolean>() {
@Override
public Boolean fun(Call call) {
importedCallList.add(call);
return true;
}
});
assertEquals(1, importedCallList.size());
Call importedCall = importedCallList.get(0);
assertEquals(pair("imported", new IntRange(0)), nameArityRange(importedCall));
}
use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class Import method onlyCallDefinitionClauseCallFilter.
@NotNull
private static Function<Call, Boolean> onlyCallDefinitionClauseCallFilter(PsiElement element) {
final Map<String, List<Integer>> aritiesByName = aritiesByNameFromNameByArityKeywordList(element);
return new Function<Call, Boolean>() {
@Override
public Boolean fun(Call call) {
Pair<String, IntRange> callNameArityRange = nameArityRange(call);
boolean include = false;
if (callNameArityRange != null) {
String callName = callNameArityRange.first;
if (callName != null) {
List<Integer> arities = aritiesByName.get(callName);
if (arities != null) {
IntRange callArityRange = callNameArityRange.second;
for (int arity : arities) {
if (callArityRange.containsInteger(arity)) {
include = true;
break;
}
}
}
}
}
return include;
}
};
}
Aggregations