_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q17500 | MetricsCacheApi.compareMetricsCacheValuesByKey | train | public static synchronized boolean compareMetricsCacheValuesByKey(String deployment, String key, ArrayList<Object> valuesToCompare) {
boolean isEqual = true;
ArrayList<Object> cacheValues;
cacheValues = getMetricsCache(deployment).get(key);
for (Object valueComp : valuesToCompare) {
for (Object value : cacheValues) {
if (value.toString().compareTo(valueComp.toString()) == 0) {
isEqual = true;
break;
}
isEqual = false;
}
}
return isEqual;
} | java | {
"resource": ""
} |
q17501 | Casts.widen | train | public static <T, R> R widen(T value) {
return new Vary<T, R>().apply(value);
} | java | {
"resource": ""
} |
q17502 | Casts.narrow | train | public static <T extends R, R> R narrow(T value) {
return new Vary<T, R>().apply(value);
} | java | {
"resource": ""
} |
q17503 | Casts.vary | train | public static <T, R> R vary(T value) {
return new Vary<T, R>().apply(value);
} | java | {
"resource": ""
} |
q17504 | PLZ.validate | train | public static String validate(String code) {
String plz = normalize(code);
if (hasLandeskennung(plz)) {
validateNumberOf(plz);
} else {
plz = LengthValidator.validate(plz, 3, 10);
}
return plz;
} | java | {
"resource": ""
} |
q17505 | PLZ.getLand | train | public Locale getLand() {
String kennung = this.getLandeskennung();
switch (kennung) {
case "D": return new Locale("de", "DE");
case "A": return new Locale("de", "AT");
case "CH": return new Locale("de", "CH");
default: throw new UnsupportedOperationException("unbekannte Landeskennung '" + kennung + "'");
}
} | java | {
"resource": ""
} |
q17506 | KoPeMeMojo.getFiles | train | public List<File> getFiles(File dir, FileFilter filter) {
// System.out.println("Standardoutput: " + standardoutput);
List<File> files = new LinkedList<File>();
for (File f : dir.listFiles()) {
if (f.isFile()) {
if (filter.accept(f))
files.add(f);
} else {
files.addAll(getFiles(f, filter));
}
}
return files;
} | java | {
"resource": ""
} |
q17507 | KoPeMeMojo.execute | train | public void execute() throws MojoExecutionException {
getLog().info("Start, BS: " + System.getProperty("os.name"));
if (System.getProperty("os.name").contains("indows")){
CPPATHSEPERATOR = ";";
PATHSEPERATOR="\\";
}else{
CPPATHSEPERATOR=":";
PATHSEPERATOR="/";
}
System.out.println("Execute: " + standardoutput);
tests = 0;
failure = 0;
error = 0;
if (standardoutput != null){
File output = new File(standardoutput);
try {
bw = new BufferedWriter( new FileWriter(output));
} catch (IOException e1) {
// TODO Automatisch generierter Erfassungsblock
e1.printStackTrace();
}
}
else{
File output = new File("stdout.txt");
try {
bw = new BufferedWriter( new FileWriter(output));
} catch (IOException e1) {
// TODO Automatisch generierter Erfassungsblock
e1.printStackTrace();
}
}
File dir = new File("src/test/java/");
FileFilter fileFilter = new RegexFileFilter("[A-z/]*.java$");
project = project.getExecutionProject();
runTestFile(dir, fileFilter);
getLog().info("Tests: " + tests + " Fehlschläge: " + failure
+ " Fehler: " + error);
} | java | {
"resource": ""
} |
q17508 | WeightedIndexEvaluation.addEvaluation | train | public void addEvaluation(Objective obj, Evaluation eval, double weight){
evaluations.put(obj, eval);
// update weighted sum
weightedSum += weight * eval.getValue();
} | java | {
"resource": ""
} |
q17509 | XMLDataLoader.loadData | train | private void loadData() throws JAXBException {
if (file.exists()) {
final JAXBContext jc = JAXBContext.newInstance(Kopemedata.class);
final Unmarshaller unmarshaller = jc.createUnmarshaller();
data = (Kopemedata) unmarshaller.unmarshal(file);
LOG.trace("Daten geladen, Daten: " + data);
} else {
LOG.info("Datei {} existiert nicht", file.getAbsolutePath());
data = new Kopemedata();
data.setTestcases(new Testcases());
final Testcases tc = data.getTestcases();
LOG.trace("TC: " + tc);
tc.setClazz(file.getName());
}
} | java | {
"resource": ""
} |
q17510 | XMLDataLoader.getData | train | public Map<String, Map<Date, Long>> getData(final String collectorName) {
final Map<String, Map<Date, Long>> map = new HashMap<>();
final Testcases testcases = data.getTestcases();
for (final TestcaseType tct : testcases.getTestcase()) {
final Map<Date, Long> measures = new HashMap<>();
final List<Datacollector> collectorMap = tct.getDatacollector();
Datacollector collector = null;
for (final Datacollector dc : collectorMap) {
if (dc.getName().equals(collectorName)) {
collector = dc;
}
}
if (collector == null) {
LOG.error("Achtung: Datenkollektor " + collectorName + " nicht vorhanden");
} else {
for (final Result s : collector.getResult()) {
measures.put(new Date(s.getDate()), (long) s.getValue());
}
map.put(tct.getName(), measures);
}
}
return map;
} | java | {
"resource": ""
} |
q17511 | XMLDataLoader.getCollectors | train | public Set<String> getCollectors() {
final Set<String> collectors = new HashSet<String>();
final Testcases testcases = data.getTestcases();
for (final TestcaseType tct : testcases.getTestcase()) {
for (final Datacollector collector : tct.getDatacollector()) {
collectors.add(collector.getName());
}
}
return collectors;
} | java | {
"resource": ""
} |
q17512 | Comparing.max | train | public static <T> T max(T lhs, T rhs, Comparator<T> comparator) {
return BinaryOperator.maxBy(comparator).apply(lhs, rhs);
} | java | {
"resource": ""
} |
q17513 | Comparing.max | train | public static <T extends Comparable<T>> T max(T lhs, T rhs) {
return BinaryOperator.maxBy(new ComparableComparator<T>()).apply(lhs, rhs);
} | java | {
"resource": ""
} |
q17514 | Comparing.min | train | public static <T> T min(T lhs, T rhs, Comparator<T> comparator) {
return BinaryOperator.minBy(comparator).apply(lhs, rhs);
} | java | {
"resource": ""
} |
q17515 | Comparing.min | train | public static <T extends Comparable<T>> T min(T lhs, T rhs) {
return BinaryOperator.minBy(new ComparableComparator<T>()).apply(lhs, rhs);
} | java | {
"resource": ""
} |
q17516 | Comparing.ordered | train | public static <T> Pair<T, T> ordered(T lhs, T rhs, Comparator<T> comparator) {
return new MakeOrder<T>(comparator).apply(lhs, rhs);
} | java | {
"resource": ""
} |
q17517 | Comparing.ordered | train | public static <T extends Comparable<T>> Pair<T, T> ordered(T lhs, T rhs) {
return new MakeOrder<T>(new ComparableComparator<T>()).apply(lhs, rhs);
} | java | {
"resource": ""
} |
q17518 | PermutationSolution.swap | train | public void swap(int i, int j){
try{
// swap items
Collections.swap(order, i, j);
} catch (IndexOutOfBoundsException ex){
throw new SolutionModificationException("Error while modifying permutation solution: swapped positions should be positive "
+ "and smaller than the number of items in the permutation.", this);
}
} | java | {
"resource": ""
} |
q17519 | Postfach.validate | train | public static void validate(BigInteger nummer, Ort ort) {
if (nummer.compareTo(BigInteger.ONE) < 0) {
throw new InvalidValueException(nummer, "number");
}
validate(ort);
} | java | {
"resource": ""
} |
q17520 | TimeBoundExecution.execute | train | public final boolean execute() throws Exception {
boolean finished = false;
mainThread.start();
mainThread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(final Thread arg0, final Throwable arg1) {
LOG.error("Uncaught exception in {}: {}", arg0.getName(), arg1.getClass());
testError = arg1;
}
});
LOG.debug("Warte: " + timeout);
mainThread.join(timeout);
if (mainThread.isAlive()) {
mainThread.setFinished(true);
LOG.error("Test " + type + " " + mainThread.getName() + " timed out!");
for (int i = 0; i < 5; i++) {
mainThread.interrupt();
// asure, that the test does not catch the interrupt state itself
Thread.sleep(5);
}
}
else {
finished = true;
}
mainThread.join(1000); // TODO If this time is shortened, test
if (mainThread.isAlive()) {
LOG.error("Test timed out and was not able to save his data after 10 seconds - is killed hard now.");
mainThread.stop();
}
if (testError != null) {
LOG.trace("Test error != null");
if (testError instanceof Exception) {
throw (Exception) testError;
} else if (testError instanceof Error) {
throw (Error) testError;
} else {
LOG.error("Unexpected behaviour");
testError.printStackTrace();
}
}
return finished;
} | java | {
"resource": ""
} |
q17521 | Geldbetrag.parse | train | public static Geldbetrag parse(CharSequence text, MonetaryAmountFormat formatter) {
return from(formatter.parse(text));
} | java | {
"resource": ""
} |
q17522 | Geldbetrag.validate | train | public static String validate(String zahl) {
try {
return Geldbetrag.valueOf(zahl).toString();
} catch (IllegalArgumentException ex) {
throw new InvalidValueException(zahl, "money_amount", ex);
}
} | java | {
"resource": ""
} |
q17523 | Geldbetrag.validate | train | public static BigDecimal validate(BigDecimal zahl, CurrencyUnit currency) {
if (zahl.scale() == 0) {
return zahl.setScale(currency.getDefaultFractionDigits(), RoundingMode.HALF_UP);
}
return zahl;
} | java | {
"resource": ""
} |
q17524 | Geldbetrag.query | train | @Override
public <R> R query(MonetaryQuery<R> query) {
Objects.requireNonNull(query);
try {
return query.queryFrom(this);
} catch (MonetaryException ex) {
throw ex;
} catch (RuntimeException ex) {
throw new LocalizedMonetaryException("query failed", query, ex);
}
} | java | {
"resource": ""
} |
q17525 | Geldbetrag.toLongString | train | public String toLongString() {
NumberFormat formatter = DecimalFormat.getInstance();
formatter.setMinimumFractionDigits(context.getMaxScale());
formatter.setMinimumFractionDigits(context.getMaxScale());
return formatter.format(betrag) + " " + currency;
} | java | {
"resource": ""
} |
q17526 | Compositions.compose | train | public static <T2, T1, R> Function<T1, R> compose(Function<T2, R> f, Function<T1, T2> g) {
dbc.precondition(f != null, "cannot compose a null function");
dbc.precondition(g != null, "cannot compose a null function");
return f.compose(g);
} | java | {
"resource": ""
} |
q17527 | Compositions.compose | train | public static <T1, T2, T3, R> BiFunction<T1, T2, R> compose(Function<T3, R> unary, BiFunction<T1, T2, T3> binary) {
dbc.precondition(unary != null, "cannot compose a null unary function");
dbc.precondition(binary != null, "cannot compose a null binary function");
return binary.andThen(unary);
} | java | {
"resource": ""
} |
q17528 | Compositions.compose | train | public static <T1, T2, T3, T4, R> TriFunction<T1, T2, T3, R> compose(Function<T4, R> unary, TriFunction<T1, T2, T3, T4> ternary) {
dbc.precondition(unary != null, "cannot compose a null unary function");
dbc.precondition(ternary != null, "cannot compose a null ternary function");
return ternary.andThen(unary);
} | java | {
"resource": ""
} |
q17529 | Compositions.compose | train | public static <T> UnaryOperator<T> compose(Iterator<Function<T, T>> endodelegates) {
return new UnaryOperatorsComposer<T>().apply(endodelegates);
} | java | {
"resource": ""
} |
q17530 | Logic.or | train | public static <T1, T2> BiPredicate<T1, T2> or(BiPredicate<T1, T2> first, BiPredicate<T1, T2> second, BiPredicate<T1, T2> third) {
dbc.precondition(first != null, "first predicate is null");
dbc.precondition(second != null, "second predicate is null");
dbc.precondition(third != null, "third predicate is null");
return Logic.Binary.or(Iterations.iterable(first, second, third));
} | java | {
"resource": ""
} |
q17531 | CommandContext.parse | train | @SuppressWarnings("unchecked") // marshall from apache commons cli
private void parse() throws ParseException {
_argValues = new HashMap<Argument, String>();
_varargValues = new ArrayList<String>();
List<String> argList = _commandLine.getArgList();
int required = 0;
boolean hasOptional = false;
boolean hasVarargs = false;
for(Argument argument : _arguments.getArguments()) {
if(argument.isRequired()) {
required++;
} else {
hasOptional = true;
}
if(argument.isVararg()) {
hasVarargs = true;
}
}
int allowed = hasOptional? required+1 : required;
if(argList.size() < required) {
throw new ParseException("Not enough arguments provided. " + required + " required, but only " + argList.size() + " provided.");
}
if(!hasVarargs) {
if(argList.size() > allowed) {
throw new ParseException("Too many arguments provided. Only " + allowed + " allowed, but " + argList.size() + " provided.");
}
}
int index = 0;
boolean finalArgEncountered = false;
for(Argument argument : _arguments.getArguments()) {
if(finalArgEncountered) throw new IllegalStateException("Illegal arguments defined. No additional arguments may be defined after first optional or vararg argument.");
if(argument.isRequired() && !argument.isVararg()) { // the normal case
if(index <= argList.size()) {
_argValues.put(argument, argList.get(index));
} else {
throw new IllegalStateException("not enough arguments"); // should not happen given above size check
}
}
else { // it's the last argument, either it's optional or a vararg
finalArgEncountered = true;
if(argument.isVararg()) {
_varargValues = argList.subList(Math.min(index, argList.size()), argList.size());
if(argument.isRequired() && _varargValues.size() < 1) {
throw new IllegalStateException("not enough arguments"); // should not happen given above size check
}
}
else { // if it's a optional
if(index < argList.size()) {
_argValues.put(argument, argList.get(index));
}
}
}
index++;
}
} | java | {
"resource": ""
} |
q17532 | NumberValidator.normalize | train | public String normalize(String value) {
if (!value.matches("[\\d,.]+([eE]\\d+)?")) {
throw new InvalidValueException(value, NUMBER);
}
Locale locale = guessLocale(value);
DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(locale);
df.setParseBigDecimal(true);
try {
return df.parse(value).toString();
} catch (ParseException ex) {
throw new InvalidValueException(value, NUMBER, ex);
}
} | java | {
"resource": ""
} |
q17533 | Mod10Verfahren.isValid | train | @Override
public boolean isValid(String wert) {
if (StringUtils.length(wert) < 1) {
return false;
} else {
return getPruefziffer(wert).equals(berechnePruefziffer(wert.substring(0, wert.length() - 1)));
}
} | java | {
"resource": ""
} |
q17534 | PackedDecimal.isBruch | train | public boolean isBruch() {
String s = toString();
if (s.contains("/")) {
try {
Bruch.of(s);
return true;
} catch (IllegalArgumentException ex) {
LOG.fine(s + " is not a fraction: " + ex);
return false;
}
} else {
return false;
}
} | java | {
"resource": ""
} |
q17535 | PackedDecimal.movePointLeft | train | public PackedDecimal movePointLeft(int n) {
BigDecimal result = toBigDecimal().movePointLeft(n);
return PackedDecimal.valueOf(result);
} | java | {
"resource": ""
} |
q17536 | PackedDecimal.movePointRight | train | public PackedDecimal movePointRight(int n) {
BigDecimal result = toBigDecimal().movePointRight(n);
return PackedDecimal.valueOf(result);
} | java | {
"resource": ""
} |
q17537 | PackedDecimal.setScale | train | public PackedDecimal setScale(int n, RoundingMode mode) {
BigDecimal result = toBigDecimal().setScale(n, mode);
return PackedDecimal.valueOf(result);
} | java | {
"resource": ""
} |
q17538 | Dispatching.curry | train | public static <T> Runnable curry(Consumer<T> consumer, T value) {
dbc.precondition(consumer != null, "cannot bind parameter of a null consumer");
return () -> consumer.accept(value);
} | java | {
"resource": ""
} |
q17539 | Dispatching.curry | train | public static <T1, T2> Consumer<T2> curry(BiConsumer<T1, T2> consumer, T1 first) {
dbc.precondition(consumer != null, "cannot bind parameter of a null consumer");
return second -> consumer.accept(first, second);
} | java | {
"resource": ""
} |
q17540 | Dispatching.curry | train | public static <T> BooleanSupplier curry(Predicate<T> predicate, T value) {
dbc.precondition(predicate != null, "cannot bind parameter of a null predicate");
return () -> predicate.test(value);
} | java | {
"resource": ""
} |
q17541 | Dispatching.curry | train | public static <T1, T2, T3> BiPredicate<T2, T3> curry(TriPredicate<T1, T2, T3> predicate, T1 first) {
dbc.precondition(predicate != null, "cannot bind parameter of a null predicate");
return (second, third) -> predicate.test(first, second, third);
} | java | {
"resource": ""
} |
q17542 | Dispatching.curry | train | public static <T, R> Supplier<R> curry(Function<T, R> function, T value) {
dbc.precondition(function != null, "cannot bind parameter of a null function");
return () -> function.apply(value);
} | java | {
"resource": ""
} |
q17543 | Dispatching.curry | train | public static <T1, T2, R> Function<T2, R> curry(BiFunction<T1, T2, R> function, T1 first) {
dbc.precondition(function != null, "cannot bind parameter of a null function");
return second -> function.apply(first, second);
} | java | {
"resource": ""
} |
q17544 | Dispatching.curry | train | public static <T1, T2, T3, R> BiFunction<T2, T3, R> curry(TriFunction<T1, T2, T3, R> function, T1 first) {
dbc.precondition(function != null, "cannot bind parameter of a null function");
return (second, third) -> function.apply(first, second, third);
} | java | {
"resource": ""
} |
q17545 | Dispatching.ignore | train | public static <T> Predicate<T> ignore(BooleanSupplier proposition, Class<T> ignored) {
dbc.precondition(proposition != null, "cannot ignore parameter of a null proposition");
return t -> proposition.getAsBoolean();
} | java | {
"resource": ""
} |
q17546 | Dispatching.ignore2nd | train | public static <T1, T2> BiPredicate<T1, T2> ignore2nd(Predicate<T1> predicate, Class<T2> ignored) {
dbc.precondition(predicate != null, "cannot ignore parameter of a null predicate");
return (first, second) -> predicate.test(first);
} | java | {
"resource": ""
} |
q17547 | Dispatching.ignore2nd | train | public static <T1, T2, T3> TriPredicate<T1, T2, T3> ignore2nd(BiPredicate<T1, T3> predicate, Class<T2> ignored) {
dbc.precondition(predicate != null, "cannot ignore parameter of a null predicate");
return (first, second, third) -> predicate.test(first, third);
} | java | {
"resource": ""
} |
q17548 | Dispatching.ignore | train | public static <T> Consumer<T> ignore(Runnable runnable, Class<T> ignored) {
dbc.precondition(runnable != null, "cannot ignore parameter of a null runnable");
return first -> runnable.run();
} | java | {
"resource": ""
} |
q17549 | Dispatching.ignore1st | train | public static <T1, T2> BiConsumer<T1, T2> ignore1st(Consumer<T2> consumer, Class<T1> ignored) {
dbc.precondition(consumer != null, "cannot ignore parameter of a null consumer");
return (first, second) -> consumer.accept(second);
} | java | {
"resource": ""
} |
q17550 | Dispatching.ignore3rd | train | public static <T1, T2, T3> TriConsumer<T1, T2, T3> ignore3rd(BiConsumer<T1, T2> consumer, Class<T3> ignored) {
dbc.precondition(consumer != null, "cannot ignore parameter of a null consumer");
return (first, second, third) -> consumer.accept(first, second);
} | java | {
"resource": ""
} |
q17551 | Dispatching.ignore | train | public static <T, R> Function<T, R> ignore(Supplier<R> supplier, Class<T> ignored) {
dbc.precondition(supplier != null, "cannot ignore parameter of a null supplier");
return first -> supplier.get();
} | java | {
"resource": ""
} |
q17552 | Dispatching.ignore1st | train | public static <T1, T2, R> BiFunction<T1, T2, R> ignore1st(Function<T2, R> function, Class<T1> ignored) {
dbc.precondition(function != null, "cannot ignore parameter of a null function");
return (first, second) -> function.apply(second);
} | java | {
"resource": ""
} |
q17553 | Dispatching.ignore1st | train | public static <T1, T2, T3, R> TriFunction<T1, T2, T3, R> ignore1st(BiFunction<T2, T3, R> function, Class<T1> ignored) {
dbc.precondition(function != null, "cannot ignore parameter of a null function");
return (first, second, third) -> function.apply(second, third);
} | java | {
"resource": ""
} |
q17554 | Dispatching.supplier | train | public static <T> Supplier<Optional<T>> supplier(Iterator<T> adaptee) {
return new IteratingSupplier<T>(adaptee);
} | java | {
"resource": ""
} |
q17555 | Dispatching.supplier | train | public static Supplier<Void> supplier(Runnable adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null runnable");
return () -> {
adaptee.run();
return null;
};
} | java | {
"resource": ""
} |
q17556 | Dispatching.supplier | train | public static Supplier<Boolean> supplier(BooleanSupplier adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null boolean supplier");
return () -> adaptee.getAsBoolean();
} | java | {
"resource": ""
} |
q17557 | Dispatching.function | train | public static <T> Function<T, Void> function(Consumer<T> adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null consumer");
return first -> {
adaptee.accept(first);
return null;
};
} | java | {
"resource": ""
} |
q17558 | Dispatching.function | train | public static <T1, T2> BiFunction<T1, T2, Void> function(BiConsumer<T1, T2> adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null consumer");
return (first, second) -> {
adaptee.accept(first, second);
return null;
};
} | java | {
"resource": ""
} |
q17559 | Dispatching.function | train | public static <T1, T2, T3> TriFunction<T1, T2, T3, Void> function(TriConsumer<T1, T2, T3> adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null consumer");
return (first, second, third) -> {
adaptee.accept(first, second, third);
return null;
};
} | java | {
"resource": ""
} |
q17560 | Dispatching.function | train | public static <T> Function<T, Boolean> function(Predicate<T> adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null predicate");
return adaptee::test;
} | java | {
"resource": ""
} |
q17561 | Dispatching.function | train | public static <T1, T2> BiFunction<T1, T2, Boolean> function(BiPredicate<T1, T2> adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null predicate");
return adaptee::test;
} | java | {
"resource": ""
} |
q17562 | Dispatching.function | train | public static <T1, T2, T3> TriFunction<T1, T2, T3, Boolean> function(TriPredicate<T1, T2, T3> adaptee) {
dbc.precondition(adaptee != null, "cannot adapt a null predicate");
return adaptee::test;
} | java | {
"resource": ""
} |
q17563 | Dispatching.runnable | train | public static <T> Runnable runnable(Supplier<T> supplier) {
dbc.precondition(supplier != null, "cannot adapt a null supplier");
return supplier::get;
} | java | {
"resource": ""
} |
q17564 | Dispatching.consumer | train | public static <T, R> Consumer<T> consumer(Function<T, R> function) {
dbc.precondition(function != null, "cannot adapt a null function");
return function::apply;
} | java | {
"resource": ""
} |
q17565 | Dispatching.consumer | train | public static <T1, T2, R> BiConsumer<T1, T2> consumer(BiFunction<T1, T2, R> function) {
dbc.precondition(function != null, "cannot adapt a null function");
return function::apply;
} | java | {
"resource": ""
} |
q17566 | Dispatching.consumer | train | public static <T1, T2, T3, R> TriConsumer<T1, T2, T3> consumer(TriFunction<T1, T2, T3, R> function) {
dbc.precondition(function != null, "cannot adapt a null function");
return function::apply;
} | java | {
"resource": ""
} |
q17567 | Dispatching.proposition | train | public static BooleanSupplier proposition(Supplier<Boolean> supplier) {
dbc.precondition(supplier != null, "cannot adapt a null supplier");
return supplier::get;
} | java | {
"resource": ""
} |
q17568 | Dispatching.predicate | train | public static <T> Predicate<T> predicate(Function<T, Boolean> function) {
dbc.precondition(function != null, "cannot adapt a null function");
return function::apply;
} | java | {
"resource": ""
} |
q17569 | Dispatching.predicate | train | public static <T1, T2> BiPredicate<T1, T2> predicate(BiFunction<T1, T2, Boolean> function) {
dbc.precondition(function != null, "cannot adapt a null function");
return function::apply;
} | java | {
"resource": ""
} |
q17570 | Dispatching.predicate | train | public static <T1, T2, T3> TriPredicate<T1, T2, T3> predicate(TriFunction<T1, T2, T3, Boolean> function) {
dbc.precondition(function != null, "cannot adapt a null function");
return function::apply;
} | java | {
"resource": ""
} |
q17571 | KiekerTraceEntry.getFieldDescription | train | public static String[] getFieldDescription() {
if(FIELDS == null){
ArrayList<String> fields = new ArrayList<String>();
for(Field field : KiekerTraceEntry.class.getDeclaredFields()){
if(!Modifier.isStatic(field.getModifiers())){
fields.add(field.getName());
}
}
FIELDS = fields.toArray(new String[fields.size()]);
}
return FIELDS;
} | java | {
"resource": ""
} |
q17572 | KiekerTraceEntry.getCellProcessors | train | public static CellProcessor[] getCellProcessors(){
return new CellProcessor[] {
new ParseInt(){
@Override
public Object execute(Object value, CsvContext context) {
String content = value.toString();
String[] split = content.split("\\$");
return super.execute(split[1], context);
}
},
new ParseLong(),
null,
null,
new ParseLong(),
new ParseLong(),
new ParseLong(),
null,
new ParseInt(),
new ParseInt()
};
} | java | {
"resource": ""
} |
q17573 | Router.configureEndpoints | train | void configureEndpoints(Reflections reflections) {
// [Re]initialise the api:
api = new HashMap<>();
log.info("Scanning for endpoint classes..");
Set<Class<?>> endpoints = reflections.getTypesAnnotatedWith(Api.class);
// log.info(reflections.getConfiguration().getUrls());
log.info("Found {} endpoint classes.", endpoints.size());
log.info("Examining endpoint class methods:");
// Configure the classes:
for (Class<?> endpointClass : endpoints) {
Route route = getEndpoint(endpointClass);
route.endpointClass = endpointClass;
for (Method method : endpointClass.getMethods()) {
// Skip Object methods
if (method.getDeclaringClass() == Object.class) {
continue;
}
// Find public methods:
if (Modifier.isPublic(method.getModifiers())) {
// Which HTTP method(s) will this method respond to?
annotation:
for (Annotation annotation : method.getAnnotations()) {
HttpMethod httpMethod = HttpMethod.method(annotation);
if (httpMethod != null) {
log.info("Http method: {}", httpMethod);
RequestHandler requestHandler = new RequestHandler();
requestHandler.handlerMethod = method;
log.info("Java method: {}", method.getName());
// Look for an optional Json message type parameter:
for (Class<?> parameterType : method.getParameterTypes()) {
if (!HttpServletRequest.class.isAssignableFrom(parameterType)
&& !HttpServletResponse.class.isAssignableFrom(parameterType)) {
if (requestHandler.requestMessageType != null) {
log.error("Too many parameters on {} method {}. " +
"Message type already set to {} but also found a {} parameter.",
httpMethod, method.getName(),
requestHandler.requestMessageType.getSimpleName(), parameterType.getSimpleName());
break annotation;
}
requestHandler.requestMessageType = parameterType;
log.info("request Json: {}", requestHandler.requestMessageType.getSimpleName());
}
}
// Check the response Json message type:
if (method.getReturnType() != void.class) {
requestHandler.responseMessageType = method.getReturnType();
log.info("Response Json: {}", requestHandler.responseMessageType.getSimpleName());
}
route.requestHandlers.put(httpMethod, requestHandler);
}
}
}
}
}
} | java | {
"resource": ""
} |
q17574 | Router.configureNotFound | train | void configureNotFound(Reflections reflections) {
log.info("Checking for a not-found endpoint..");
NotFound notFound = getEndpoint(NotFound.class, "not-found", reflections);
if (notFound == null) notFound = new DefaultNotFound();
printEndpoint(notFound, "not-found");
this.notFound = notFound;
} | java | {
"resource": ""
} |
q17575 | Router.configureServerError | train | void configureServerError(Reflections reflections) {
log.info("Checking for an error endpoint..");
ServerError serverError = getEndpoint(ServerError.class, "error", reflections);
if (serverError == null) serverError = new DefaultServerError();
printEndpoint(serverError, "error");
this.serverError = serverError;
} | java | {
"resource": ""
} |
q17576 | Router.getEndpoint | train | private static <E> E getEndpoint(Class<E> type, String name, Reflections reflections) {
E result = null;
// Get concrete subclasses:
Set<Class<? extends E>> foundClasses = reflections.getSubTypesOf(type);
Set<Class<? extends E>> endpointClasses = new HashSet<>();
for (Class<? extends E> clazz : foundClasses) {
if (!Modifier.isAbstract(clazz.getModifiers())) {
endpointClasses.add(clazz);
}
}
// Filter out any default routes:
//log.info("Filtering " + type.getName());
Iterator<Class<? extends E>> iterator = endpointClasses.iterator();
while (iterator.hasNext()) {
Class<? extends E> next = iterator.next();
if (StringUtils.startsWithIgnoreCase(next.getName(), "com.github.davidcarboni.restolino.routes.")) {
//log.info("Filtered out " + next.getName());
iterator.remove();
} //else {
//log.info("Filtered in " + next.getName());
//}
}
//log.info("Filtered.");
if (endpointClasses.size() != 0) {
// Dump multiple endpoints:
if (endpointClasses.size() > 1) {
log.info("Warning: found multiple candidates for {} endpoint: {}", name, endpointClasses);
}
// Instantiate the endpoint if possible:
try {
result = endpointClasses.iterator().next().newInstance();
} catch (Exception e) {
log.info("Error: cannot instantiate {} endpoint class {}",name, endpointClasses.iterator().next());
e.printStackTrace();
}
}
return result;
} | java | {
"resource": ""
} |
q17577 | Router.mapRequestPath | train | public String mapRequestPath(HttpServletRequest request) {
String endpointName = Path.newInstance(request).firstSegment();
return StringUtils.lowerCase(endpointName);
} | java | {
"resource": ""
} |
q17578 | FirstElement.apply | train | @Override
public E apply(Iterator<E> consumable) {
dbc.precondition(consumable != null, "consuming a null iterator");
dbc.precondition(consumable.hasNext(), "no element to consume");
return consumable.next();
} | java | {
"resource": ""
} |
q17579 | Scanner.start | train | public static void start(Path root, WatchService watcher) {
Scanner.watcher = watcher;
Scanner.root = root;
log.info("Monitoring changes under {}", root);
Thread t = new Thread(new Scanner(), "Directory scanner");
t.setDaemon(true);
t.start();
} | java | {
"resource": ""
} |
q17580 | LastElement.apply | train | @Override
public E apply(Iterator<E> consumable) {
dbc.precondition(consumable != null, "consuming a null iterator");
dbc.precondition(consumable.hasNext(), "no element to consume");
E value = consumable.next();
while (consumable.hasNext()) {
value = consumable.next();
}
return value;
} | java | {
"resource": ""
} |
q17581 | Flipper.apply | train | @Override
public R apply(T former, U latter) {
return function.apply(latter, former);
} | java | {
"resource": ""
} |
q17582 | Serialiser.serialise | train | public static String serialise(Object object) {
Gson gson = getBuilder().create();
return gson.toJson(object);
} | java | {
"resource": ""
} |
q17583 | Serialiser.deserialise | train | public static <O> O deserialise(String json, Class<O> type) {
Gson gson = getBuilder().create();
return gson.fromJson(json, type);
} | java | {
"resource": ""
} |
q17584 | PomProjectNameReader.foundPomXml | train | public boolean foundPomXml(final File directory, final int depth) {
LOG.debug("Directory: {}", directory);
if (depth == -1 || directory == null || !directory.isDirectory()) {
return false;
} else {
File[] pomFiles = directory.listFiles(new FileFilter() {
@Override
public boolean accept(final File pathname) {
return "pom.xml".equals(pathname.getName());
}
});
if (pomFiles.length == 1) {
pathToPomXml = pomFiles[0];
return true;
} else {
return foundPomXml(directory.getParentFile(), depth - 1);
}
}
} | java | {
"resource": ""
} |
q17585 | GwtWidget.link | train | @Override
public void link(NGScope scope, JQElement element, JSON attrs) {
IsWidget widget = scope.get(getName());
String id = "gwt-widget-" + counter++;
element.attr("id", id);
RootPanel.get(id).add(widget);
} | java | {
"resource": ""
} |
q17586 | ZipLongestIterator.next | train | @Override
public Pair<Optional<E1>, Optional<E2>> next() {
return Pair.of(former.next(), latter.next());
} | java | {
"resource": ""
} |
q17587 | XMLDataStorer.createXMLData | train | public void createXMLData(final String classname) {
data = new Kopemedata();
data.setTestcases(new Testcases());
final Testcases tc = data.getTestcases();
tc.setClazz(classname);
storeData();
} | java | {
"resource": ""
} |
q17588 | JSONSummariser.parseFieldsMap | train | public static void parseFieldsMap(final Reader inputReader, final Map<String, String> defaultsMap,
final Map<String, Optional<JsonPointer>> pathsMap) throws IOException, CSVStreamException {
CSVStream.parse(inputReader, h -> {
// TODO: Validate the headers as expected
}, (h, l) -> {
defaultsMap.put(l.get(h.indexOf(FIELD)), l.get(h.indexOf(DEFAULT)));
String relativePath = l.get(h.indexOf(RELATIVE_PATH)).trim();
pathsMap.put(l.get(h.indexOf(FIELD)),
relativePath.isEmpty() ? Optional.empty() : Optional.of(JsonPointer.compile(relativePath)));
return l;
}, l -> {
}, null, CSVStream.DEFAULT_HEADER_COUNT);
} | java | {
"resource": ""
} |
q17589 | JSONSummariser.getSummaryFunctionWithStartTime | train | public static TriFunction<JsonNode, List<String>, List<String>, List<String>> getSummaryFunctionWithStartTime(
final JDefaultDict<String, AtomicInteger> emptyCounts,
final JDefaultDict<String, AtomicInteger> nonEmptyCounts,
final JDefaultDict<String, AtomicBoolean> possibleIntegerFields,
final JDefaultDict<String, AtomicBoolean> possibleDoubleFields,
final JDefaultDict<String, JDefaultDict<String, AtomicInteger>> valueCounts, final AtomicInteger rowCount,
final long startTime) {
return (node, header, line) -> {
int nextLineNumber = rowCount.incrementAndGet();
if (nextLineNumber % 10000 == 0) {
double secondsSinceStart = (System.currentTimeMillis() - startTime) / 1000.0d;
System.out.printf("%d\tSeconds since start: %f\tRecords per second: %f%n", nextLineNumber,
secondsSinceStart, nextLineNumber / secondsSinceStart);
}
for (int i = 0; i < header.size(); i++) {
if (line.get(i).trim().isEmpty()) {
emptyCounts.get(header.get(i)).incrementAndGet();
} else {
nonEmptyCounts.get(header.get(i)).incrementAndGet();
valueCounts.get(header.get(i)).get(line.get(i)).incrementAndGet();
try {
Integer.parseInt(line.get(i));
} catch (NumberFormatException nfe) {
possibleIntegerFields.get(header.get(i)).set(false);
}
try {
Double.parseDouble(line.get(i));
} catch (NumberFormatException nfe) {
possibleDoubleFields.get(header.get(i)).set(false);
}
}
}
return line;
};
} | java | {
"resource": ""
} |
q17590 | ChatAccount.toMap | train | @Override
public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>();
map.put("chatDienst", getChatDienst());
map.put("dienstName", getDienstName());
map.put("account", getAccount());
return map;
} | java | {
"resource": ""
} |
q17591 | AnalysisResults.merge | train | public AnalysisResults<SolutionType> merge(AnalysisResults<SolutionType> otherResults){
otherResults.results.keySet().forEach(problemID -> {
otherResults.results.get(problemID).keySet().forEach(searchID -> {
List<SearchRunResults<SolutionType>> runs = otherResults.results.get(problemID).get(searchID);
runs.forEach(run -> {
// deep copy run
SearchRunResults<SolutionType> runCopy = new SearchRunResults<>(run);
// register in this results object
registerSearchRun(problemID, searchID, runCopy);
});
});
});
return this;
} | java | {
"resource": ""
} |
q17592 | AnalysisResults.registerSearchRun | train | public void registerSearchRun(String problemID, String searchID, SearchRunResults<SolutionType> run){
if(!results.containsKey(problemID)){
results.put(problemID, new HashMap<>());
}
if(!results.get(problemID).containsKey(searchID)){
results.get(problemID).put(searchID, new ArrayList<>());
}
results.get(problemID).get(searchID).add(run);
} | java | {
"resource": ""
} |
q17593 | AnalysisResults.getNumSearches | train | public int getNumSearches(String problemID){
if(!results.containsKey(problemID)){
throw new UnknownIDException("Unknown problem ID " + problemID + ".");
}
return results.get(problemID).size();
} | java | {
"resource": ""
} |
q17594 | AnalysisResults.getNumRuns | train | public int getNumRuns(String problemID, String searchID){
if(!results.containsKey(problemID)){
throw new UnknownIDException("Unknown problem ID " + problemID + ".");
}
if(!results.get(problemID).containsKey(searchID)){
throw new UnknownIDException("Unknown search ID " + searchID + " for problem " + problemID + ".");
}
return results.get(problemID).get(searchID).size();
} | java | {
"resource": ""
} |
q17595 | AnalysisResults.getRun | train | public SearchRunResults<SolutionType> getRun(String problemID, String searchID, int i){
if(!results.containsKey(problemID)){
throw new UnknownIDException("Unknown problem ID " + problemID + ".");
}
if(!results.get(problemID).containsKey(searchID)){
throw new UnknownIDException("Unknown search ID " + searchID + " for problem " + problemID + ".");
}
return results.get(problemID).get(searchID).get(i);
} | java | {
"resource": ""
} |
q17596 | AbstractDatamappingProcessor.addToContainer | train | @Override
public void addToContainer(Element container, Element element) throws DocumentException, VectorPrintException {
if (container instanceof TextElementArray) {
if (element instanceof Image) {
((TextElementArray) container).add(new Chunk((Image) element, 0, 0, true));
} else {
((TextElementArray) container).add(element);
}
} else if (container instanceof PdfPTable) {
if (element instanceof PdfPCell) {
((PdfPTable) container).addCell((PdfPCell) element);
} else if (element instanceof Phrase) {
((PdfPTable) container).addCell((Phrase) element);
} else if (element instanceof PdfPTable) {
((PdfPTable) container).addCell((PdfPTable) element);
} else if (element instanceof Image) {
((PdfPTable) container).addCell((Image) element);
} else {
throw new VectorPrintException(String.format("don't know how to add %s to %s", (element == null) ? "null" : element.getClass().getName(), (container == null) ? "null" : container.getClass().getName()));
}
} else if (container instanceof PdfPCell) {
if (element instanceof PdfPTable) {
throw new VectorPrintException(String.format("use %s.%s if you want to nest tables", CONTAINER_ELEMENT.class.getName(), CONTAINER_ELEMENT.NESTED_TABLE));
}
((PdfPCell) container).addElement(element);
} else if (container instanceof ColumnText) {
((ColumnText) container).addElement(element);
} else {
throw new VectorPrintException(String.format("don't know how to add %s to %s", (element == null) ? "null" : element.getClass().getName(), (container == null) ? "null" : container.getClass().getName()));
}
} | java | {
"resource": ""
} |
q17597 | Spies.spy | train | public static BooleanSupplier spy(BooleanSupplier proposition, Box<Boolean> result) {
return new CapturingProposition(proposition, result);
} | java | {
"resource": ""
} |
q17598 | Spies.spy | train | public static <R> Supplier<R> spy(Supplier<R> supplier, Box<R> result) {
return new CapturingSupplier<R>(supplier, result);
} | java | {
"resource": ""
} |
q17599 | Spies.spy | train | public static <T, R> Function<T, R> spy(Function<T, R> function, Box<R> result, Box<T> param) {
return new CapturingFunction<>(function, result, param);
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.