Merge remote-tracking branch 'upstream/master' into tutorials/binaryTreeJava

This commit is contained in:
Marcos
2017-12-07 23:38:58 +01:00
60 changed files with 1882 additions and 708 deletions

View File

@@ -0,0 +1,41 @@
package com.baeldung.array;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;
import org.apache.commons.lang3.ArrayUtils;
import com.google.common.collect.Lists;
public class ArrayInverter {
public void invertUsingFor(Object[] array) {
for (int i = 0; i < array.length / 2; i++) {
Object temp = array[i];
array[i] = array[array.length - 1 - i];
array[array.length - 1 - i] = temp;
}
}
public void invertUsingCollectionsReverse(Object[] array) {
List<Object> list = Arrays.asList(array);
Collections.reverse(list);
}
public Object[] invertUsingStreams(final Object[] array) {
return IntStream.range(1, array.length + 1).mapToObj(i -> array[array.length - i]).toArray();
}
public void invertUsingCommonsLang(Object[] array) {
ArrayUtils.reverse(array);
}
public Object[] invertUsingGuava(Object[] array) {
List<Object> list = Arrays.asList(array);
List<Object> reverted = Lists.reverse(list);
return reverted.toArray();
}
}

View File

@@ -54,7 +54,7 @@ public class GenericFile {
}
public String getFileInfo() {
return "File Name: " + this.getName() + "\n" + "Extension: " + this.getExtension() + "\n" + "Date Created: " + this.getDateCreated() + "\n" + "Version: " + this.getVersion() + "\n";
return String.format("File Name: %s\n" + " Extension: %s\n" + " Date Created: %s\n" + " Version: %s\n", this.getName(), this.getExtension(), this.getDateCreated(), this.getVersion());
}
public Object read() {

View File

@@ -30,7 +30,7 @@ public class ImageFile extends GenericFile {
}
public String getFileInfo() {
return super.getFileInfo() + "Height: " + this.getHeight() + "\n" + "Width: " + this.getWidth();
return String.format(" %s Height: %d\n Width: %d", super.getFileInfo(), this.getHeight(), this.getWidth());
}
public String read() {

View File

@@ -21,7 +21,7 @@ public class TextFile extends GenericFile {
}
public String getFileInfo() {
return super.getFileInfo() + "Word Count: " + wordCount;
return String.format(" %s Word Count: %d", super.getFileInfo(), wordCount);
}
public String read() {