Is everything agile?
Here are a couple of things agile for you. It obviously starts with “Agile Software Development” and ...Read more
private static final Random random = new Random();
public static Integer[] generateRandomIntArray(int size) {
return IntStream.range(0, size).map(i -> random.nextInt(size)).boxed()
.toArray(Integer[]::new);
}
IntStream.range(0, randomNumbers.length / 2)
.forEach(i -> swap(randomNumbers, i, randomNumbers.length - i - 1));
IntStream.range(0, items.length)
.forEach(i -> IntStream.range(i + 1, items.length)
.filter(j -> items[i]> items[j])
.forEach(j -> swap(items, i, j)));
public class ShouterMain {
public static void main(String... args) throws Exception {
String id = UUID.randomUUID().toString();
final MulticastSocket socket = new MulticastSocket(4444);
...
public static void main(String... args) throws Exception {
new ShouterMain(System.out, System.in).doMain();
}
final List<String> firstClientLines = new ArrayList<>();
try (
PrintStream firstOut = new PrintStream(new ByteArrayOutputStream()) {
@Override
public void println(String str) {
firstClientLines.add(str);
}
};
InputStream firstIn = new ByteArrayInputStream(new byte[]{});
) {
new ShouterMain(firstOut, firstIn).doMain();
Assert.assertEquals("Someone shouted: 'I am Second!'", firstClientLines.get(0));
}
10
-20
30
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(Example.class.getResourceAsStream("/input.txt")))) {
reader.lines().forEach(line -> System.out.println(line));
} catch (IOException e) {
throw new RuntimeException(e);
}
List<String> lineList = reader.lines()
.collect(Collectors.toList());
int sum = reader.lines()
.mapToInt(line -> Integer.parseInt(line)).sum();
int sum = reader.lines()
.mapToInt(line -> Integer.parseInt(line))
.filter(anInt -> anInt > 0).sum();
btnSave.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
saveInternalStorage();
synchronizeOnWeb(); // long running operation,
}
});
btnSave.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
new Thread(new Runnable() {
@Override public void run() {
longRunningOperation(); } }).start();
}
}
);
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
...
btnSave.setImageResource(R.drawable.progress1);
...
}
}).start();
android.view.ViewRootImpl$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4746)
...
at android.widget.ImageView.setImageResource(ImageView.java:352)
at mca.activities.NoteListActivity$3$1.run(NoteListActivity.java:69)
at java.lang.Thread.run(Thread.java:856)
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
MyActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
btnTest.setImageResource(R.drawable.progress1);
}
});
}
}).start();
}
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
myBtn.post(new Runnable() {
@Override
public void run() {
myBtn.setImageResource(R.drawable.progress1);
}
});
}
}).start();
}
final ProgressControllerAnimationThread progressT =
new ProgressControllerAnimationThread(btnSave, R.drawable.save);
progressT.start();
new Thread(new Runnable() {
@Override
public void run() {
longRunningOperation();
progressT.end(true);
}
}).start();
public void onClick(View v) {
AsyncTask testTask = new AsyncTask...{
protected Void doInBackground(Void... params) {
...
while (System.currentTimeMillis() - start < 2000) {
doApartOfLongRunningOp();
if (System.currentTimeMillis() - changeTime > 100) {
changeTime = System.currentTimeMillis();
publishProgress(progress++);
}
}
return null;
}
protected void onProgressUpdate(Integer... values) {...}
};
testTask.execute();
}
class BackgroundThread extends Thread {
public Handler handler;
public void run() {
Looper.prepare();
handler = new Handler() {
public void handleMessage(Message msg) {
// process incoming messages here
}
};
Looper.loop();
}
}
<tow:inputtext id="name" value="#{new.name}" label="#{lbl.name}"
required="true" maxLength="30" />