Чтобы избежать всех отрицательных эффектов инициализации двойной комбинации, например:
делать следующие вещи:
Пример:
public class MyClass {
public static class Builder {
public int first = -1 ;
public double second = Double.NaN;
public String third = null ;
public MyClass create() {
return new MyClass(first, second, third);
}
}
protected final int first ;
protected final double second;
protected final String third ;
protected MyClass(
int first ,
double second,
String third
) {
this.first = first ;
this.second= second;
this.third = third ;
}
public int first () { return first ; }
public double second() { return second; }
public String third () { return third ; }
}
Использование :
MyClass my = new MyClass.Builder(){{ first = 1; third = "3"; }}.create();
Преимущества:
Недостатки:
И, как результат, у нас самый простой шаблон java-строителя.
См. все образцы в github: java-sf-builder-simple-example
Вы верная банка.
можно определить опции для '\r' и '\n' значения с
rl_bind_key('\r', return_func);
return_func может теперь решить, что сделать с теми ключами.
int return_func(int cnt, int key) { ... }
при выполнении этой внутренней части терминал UNIX необходимо будет узнать о кодах терминала ANSI, если Вы захотите переместить свой курсор. Существует стартовая ссылка на Википедию.
Вот некоторый пример кода, который использует readline для чтения мультилинии и прекратит редактировать, когда Вы входите в точку с запятой (я установил это как EOQ или конец-или-запрос). Readline чрезвычайно мощен, существует много материала для изучения.
#include <stdio.h>
#include <unistd.h>
#include <readline/readline.h>
#include <readline/history.h>
int my_startup(void);
int my_bind_cr(int, int);
int my_bind_eoq(int, int);
char *my_readline(void);
int my_eoq;
int
main(int argc, char *argv[])
{
if (isatty(STDIN_FILENO)) {
rl_readline_name = "my";
rl_startup_hook = my_startup;
my_readline();
}
}
int
my_startup(void)
{
my_eoq = 0;
rl_bind_key('\n', my_bind_cr);
rl_bind_key('\r', my_bind_cr);
rl_bind_key(';', my_bind_eoq);
}
int
my_bind_cr(int count, int key) {
if (my_eoq == 1) {
rl_done = 1;
}
printf("\n");
}
int
my_bind_eoq(int count, int key) {
my_eoq = 1;
printf(";");
}
char *
my_readline(void)
{
char *line;
if ((line = readline("")) == NULL) {
return NULL;
}
printf("LINE : %s\n", line);
}