Line width <= 60
This commit is contained in:
parent
d24a98545c
commit
2327db4c15
@ -26,7 +26,8 @@ public class CompType implements Comparable<CompType> {
|
|||||||
}
|
}
|
||||||
private static Random r = new Random(47);
|
private static Random r = new Random(47);
|
||||||
public static Generator<CompType> generator() {
|
public static Generator<CompType> generator() {
|
||||||
return () -> new CompType(r.nextInt(100),r.nextInt(100));
|
return () ->
|
||||||
|
new CompType(r.nextInt(100),r.nextInt(100));
|
||||||
}
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
CompType[] a =
|
CompType[] a =
|
||||||
|
@ -18,7 +18,8 @@ class MyList(list): # Inherit from list
|
|||||||
reversed.reverse() # Built-in list method
|
reversed.reverse() # Built-in list method
|
||||||
return reversed
|
return reversed
|
||||||
|
|
||||||
list2 = MyList(aList) # No 'new' needed for object creation
|
# No 'new' necessary for object creation:
|
||||||
|
list2 = MyList(aList)
|
||||||
print(type(list2)) # <class '__main__.MyList'>
|
print(type(list2)) # <class '__main__.MyList'>
|
||||||
print(list2.getReversed()) # [8, 7, 6, 5, 4, 3, 2, 1]
|
print(list2.getReversed()) # [8, 7, 6, 5, 4, 3, 2, 1]
|
||||||
#:~
|
#:~
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//: containers/FillingLists.java
|
//: containers/FillingLists.java
|
||||||
// ©2015 MindView LLC: see Copyright.txt
|
// 2015 MindView LLC: see Copyright.txt
|
||||||
// The Collections.fill() & Collections.nCopies() methods.
|
// The Collections.fill() & Collections.nCopies() methods.
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ import java.io.*;
|
|||||||
|
|
||||||
public class FileLocking {
|
public class FileLocking {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
try (FileOutputStream fos = new FileOutputStream("file.txt")) {
|
try(FileOutputStream fos =
|
||||||
|
new FileOutputStream("file.txt")) {
|
||||||
FileLock fl = fos.getChannel().tryLock();
|
FileLock fl = fos.getChannel().tryLock();
|
||||||
if(fl != null) {
|
if(fl != null) {
|
||||||
System.out.println("Locked File");
|
System.out.println("Locked File");
|
||||||
|
@ -29,7 +29,8 @@ public class MappedIO {
|
|||||||
public void test() throws IOException {
|
public void test() throws IOException {
|
||||||
try(DataOutputStream dos = new DataOutputStream(
|
try(DataOutputStream dos = new DataOutputStream(
|
||||||
new BufferedOutputStream(
|
new BufferedOutputStream(
|
||||||
new FileOutputStream(new File("temp.tmp"))))) {
|
new FileOutputStream(
|
||||||
|
new File("temp.tmp"))))) {
|
||||||
for(int i = 0; i < numOfInts; i++)
|
for(int i = 0; i < numOfInts; i++)
|
||||||
dos.writeInt(i);
|
dos.writeInt(i);
|
||||||
}
|
}
|
||||||
@ -38,7 +39,8 @@ public class MappedIO {
|
|||||||
new Tester("Mapped Write") {
|
new Tester("Mapped Write") {
|
||||||
@Override
|
@Override
|
||||||
public void test() throws IOException {
|
public void test() throws IOException {
|
||||||
try (FileChannel fc = new RandomAccessFile("temp.tmp", "rw")
|
try(FileChannel fc =
|
||||||
|
new RandomAccessFile("temp.tmp", "rw")
|
||||||
.getChannel()) {
|
.getChannel()) {
|
||||||
IntBuffer ib = fc.map(
|
IntBuffer ib = fc.map(
|
||||||
FileChannel.MapMode.READ_WRITE, 0, fc.size())
|
FileChannel.MapMode.READ_WRITE, 0, fc.size())
|
||||||
|
@ -5,7 +5,8 @@ import java.io.*;
|
|||||||
public class UsingRandomAccessFile {
|
public class UsingRandomAccessFile {
|
||||||
static String file = "rtest.dat";
|
static String file = "rtest.dat";
|
||||||
static void display() throws IOException {
|
static void display() throws IOException {
|
||||||
try (RandomAccessFile rf = new RandomAccessFile(file, "r")) {
|
try(RandomAccessFile rf =
|
||||||
|
new RandomAccessFile(file, "r")) {
|
||||||
for(int i = 0; i < 7; i++)
|
for(int i = 0; i < 7; i++)
|
||||||
System.out.println(
|
System.out.println(
|
||||||
"Value " + i + ": " + rf.readDouble());
|
"Value " + i + ": " + rf.readDouble());
|
||||||
|
@ -15,7 +15,8 @@ public class ZipCompress {
|
|||||||
CheckedOutputStream csum =
|
CheckedOutputStream csum =
|
||||||
new CheckedOutputStream(f, new Adler32());
|
new CheckedOutputStream(f, new Adler32());
|
||||||
ZipOutputStream zos = new ZipOutputStream(csum);
|
ZipOutputStream zos = new ZipOutputStream(csum);
|
||||||
try (BufferedOutputStream out = new BufferedOutputStream(zos)) {
|
try(BufferedOutputStream out =
|
||||||
|
new BufferedOutputStream(zos)) {
|
||||||
zos.setComment("A test of Java Zipping");
|
zos.setComment("A test of Java Zipping");
|
||||||
// No corresponding getComment(), though.
|
// No corresponding getComment(), though.
|
||||||
for(String arg : args) {
|
for(String arg : args) {
|
||||||
|
@ -11,7 +11,8 @@ public class TextFile extends ArrayList<String> {
|
|||||||
public static String read(String fileName) {
|
public static String read(String fileName) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
try (BufferedReader in = new BufferedReader(new FileReader(
|
try(BufferedReader in =
|
||||||
|
new BufferedReader(new FileReader(
|
||||||
new File(fileName).getAbsoluteFile()))) {
|
new File(fileName).getAbsoluteFile()))) {
|
||||||
String s;
|
String s;
|
||||||
while((s = in.readLine()) != null) {
|
while((s = in.readLine()) != null) {
|
||||||
|
@ -57,7 +57,8 @@ public class JUnitDemo {
|
|||||||
// A helper method to reduce code duplication. As long
|
// A helper method to reduce code duplication. As long
|
||||||
// as it isn't annotated with @Test, it will not
|
// as it isn't annotated with @Test, it will not
|
||||||
// be automatically executed by JUnit.
|
// be automatically executed by JUnit.
|
||||||
private void compare(ArrayList<String> lst, String[] strs) {
|
private
|
||||||
|
void compare(ArrayList<String> lst, String[] strs) {
|
||||||
String[] array = (String[])lst.toArray();
|
String[] array = (String[])lst.toArray();
|
||||||
assertTrue("Arrays not the same length",
|
assertTrue("Arrays not the same length",
|
||||||
array.length == strs.length);
|
array.length == strs.length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user