Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8c9324a

Browse filesBrowse files
committed
lesson 8.
Устранение ошибок: 1. Реализация doRead в AbstarctFileStorage 2.ALT+L 3. обработка null из listFiles() в AbstractFileStoradge.doCopyAll
1 parent 66a044e commit 8c9324a
Copy full SHA for 8c9324a

File tree

Expand file treeCollapse file tree

12 files changed

+104
-50
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

12 files changed

+104
-50
lines changed
Open diff view settings
Collapse file

‎src/com/urise/webapp/MainDate.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/MainDate.java
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
import java.time.LocalDate;
55
import java.util.Calendar;
66
import java.util.Date;
7-
import java.util.Locale;
87

98
public class MainDate {
109
public static void main(String[] args) {
11-
Date date= new Date();
10+
Date date = new Date();
1211
System.out.println(date.getTime());
1312
Calendar cal = Calendar.getInstance();
1413
System.out.println(cal.getTime());
15-
LocalDate ld= LocalDate.now();
14+
LocalDate ld = LocalDate.now();
1615
SimpleDateFormat sdf = new SimpleDateFormat("YY/MM/dd");
1716
System.out.println(sdf.format(cal.getTime()));
1817

Collapse file

‎src/com/urise/webapp/exception/StorageException.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/exception/StorageException.java
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.urise.webapp.exception;
22

3-
import java.io.IOException;
4-
53
public class StorageException extends RuntimeException {
64
private final String uuid;
75

@@ -11,7 +9,7 @@ public StorageException(String message, String uuid) {
119
}
1210

1311
public StorageException(String message, String uuid, Exception e) {
14-
super(message,e);
12+
super(message, e);
1513
this.uuid = uuid;
1614

1715
}
Collapse file

‎src/com/urise/webapp/model/Link.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/model/Link.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Link {
77
private final String url;
88

99
public Link(String name, String url) {
10-
Objects.requireNonNull(name,"name must not be null");
10+
Objects.requireNonNull(name, "name must not be null");
1111
this.name = name;
1212
this.url = url;
1313
}
@@ -22,7 +22,7 @@ public String getUrl() {
2222

2323
@Override
2424
public String toString() {
25-
return "Link ("+ name + ',' + url + ')';
25+
return "Link (" + name + ',' + url + ')';
2626
}
2727

2828
@Override
Collapse file

‎src/com/urise/webapp/model/ListSection.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/model/ListSection.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ListSection extends AbstractSection {
77
private final List<String> items;
88

99
public ListSection(List<String> items) {
10-
Objects.requireNonNull(items,"items must not null");
10+
Objects.requireNonNull(items, "items must not null");
1111
this.items = items;
1212
}
1313

Collapse file

‎src/com/urise/webapp/model/OrganizationSection.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/model/OrganizationSection.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class OrganizationSection extends AbstractSection {
77
private final List<Organization> organizations;
88

99
public OrganizationSection(List<Organization> organizations) {
10-
Objects.requireNonNull(organizations,"organizations must not null");
10+
Objects.requireNonNull(organizations, "organizations must not null");
1111
this.organizations = organizations;
1212
}
1313

Collapse file

‎src/com/urise/webapp/model/Resume.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/model/Resume.java
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.urise.webapp.model;
22

3-
import java.util.*;
3+
import java.util.EnumMap;
4+
import java.util.Map;
5+
import java.util.Objects;
6+
import java.util.UUID;
47

58
/**
69
* Initial resume class
@@ -26,6 +29,7 @@ public Resume(String uuid, String fullName) {
2629
this.fullName = fullName;
2730
}
2831

32+
<<<<<<< HEAD
2933

3034
public String getContact (ContactType type){
3135
return contacts.get(type);
@@ -41,6 +45,22 @@ public void addSection (SectionType type, AbstractSection section){
4145

4246
public void addContact (ContactType type, String contact){
4347
contacts.put(type,contact);
48+
=======
49+
public String getContact(ContactType type) {
50+
return contacs.get(type);
51+
}
52+
53+
public Section getSection(SectionType type) {
54+
return sections.get(type);
55+
}
56+
57+
public void addSection(SectionType type, Section section) {
58+
sections.put(type, section);
59+
}
60+
61+
public void addContact(ContactType type, String contact) {
62+
contacs.put(type, contact);
63+
>>>>>>> lesson 8.
4464
}
4565

4666

Collapse file

‎src/com/urise/webapp/model/SectionType.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/model/SectionType.java
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.urise.webapp.model;
22

33
public enum SectionType {
4-
PERSONAL ("Личные качества"),
5-
OBJECTIVE ("Позиция"),
6-
ACHIEVEMENT ("Достижения"),
7-
QUALIFICATIONS ("Квалификация"),
8-
EXPIRIENCE ("Опыт работы"),
9-
EDUCATION ("Образование");
4+
PERSONAL("Личные качества"),
5+
OBJECTIVE("Позиция"),
6+
ACHIEVEMENT("Достижения"),
7+
QUALIFICATIONS("Квалификация"),
8+
EXPIRIENCE("Опыт работы"),
9+
EDUCATION("Образование");
1010

1111
private String title;
1212

Collapse file

‎src/com/urise/webapp/model/TextSection.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/model/TextSection.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class TextSection extends AbstractSection {
66
private final String content;
77

88
public TextSection(String content) {
9-
Objects.requireNonNull(content,"content must not null");
9+
Objects.requireNonNull(content, "content must not null");
1010
this.content = content;
1111
}
1212

Collapse file

‎src/com/urise/webapp/storage/AbstractFileStorage.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/storage/AbstractFileStorage.java
+21-25Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,38 @@ public abstract class AbstractFileStorage extends AbstractStorage {
1313
private File directory;
1414

1515
protected AbstractFileStorage(File directory) {
16-
Objects.requireNonNull(directory,"directory must not null");
17-
if (directory.isDirectory()){
18-
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not directory");
16+
Objects.requireNonNull(directory, "directory must not null");
17+
if (directory.isDirectory()) {
18+
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not directory");
1919
}
20-
if (directory.canRead()||directory.canWrite()){
21-
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not readable/writable");
20+
if (directory.canRead() || directory.canWrite()) {
21+
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not readable/writable");
2222
}
23-
this.directory=directory;
23+
this.directory = directory;
2424
}
2525

2626
@Override
2727
protected void doUpdate(Resume resume, Object searchKey) {
2828
//как doSave только в существующий
29-
File f = (File)searchKey;
29+
File f = (File) searchKey;
3030
try {
31-
doWrite(resume,f);
31+
doWrite(resume, f);
3232
} catch (IOException e) {
3333
throw new StorageException("IO error", f.getName(), e);
3434
}
3535
}
3636

3737
@Override
3838
protected boolean isExist(Object file) {
39-
return ((File)file).exists();
39+
return ( (File) file).exists();
4040
}
4141

4242
@Override
4343
protected void doSave(Resume resume, Object file) {
44-
File f =((File)file);
44+
File f = ((File) file);
4545
try {
4646
f.createNewFile();
47-
doWrite (resume,f);
47+
doWrite(resume, f);
4848
} catch (IOException e) {
4949
throw new StorageException("IO error", f.getName(), e);
5050
}
@@ -54,35 +54,31 @@ protected void doSave(Resume resume, Object file) {
5454

5555
@Override
5656
protected Resume doGet(Object searchKey) {
57-
//абстрактный останется
58-
59-
60-
return null;
57+
return doRead ((File)searchKey);
6158
}
6259

6360
@Override
6461
protected void doDelete(Object searchKey) {
65-
File f= (File)searchKey;
62+
File f = (File) searchKey;
6663
f.delete();
6764
//удаляет файл
6865
}
6966

7067
@Override
7168
protected Object getSearchKey(String uuid) {
72-
return new File(directory,uuid);
69+
return new File(directory, uuid);
7370
}
7471

7572
@Override
7673
protected List<Resume> doCopyAll() {
7774
//читает все файлы и делает do Read и возвращает list
78-
List<Resume> resumes = new ArrayList<>();
79-
try {
80-
for (File f : directory.listFiles()) {
81-
resumes.add(doRead(f));
82-
}
75+
File[] arrFiles = directory.listFiles();
76+
if (arrFiles == null) {
77+
throw new StorageException("Resume files not founded in directory " + directory.getAbsolutePath() , "");
8378
}
84-
catch (NullPointerException e){
85-
throw new StorageException("FileStorage got empty list of files","",e);
79+
List<Resume> resumes = new ArrayList<>();
80+
for (File f : arrFiles) {
81+
resumes.add(doRead(f));
8682
}
8783
return resumes;
8884
}
@@ -92,7 +88,7 @@ protected List<Resume> doCopyAll() {
9288
@Override
9389
public void clear() {
9490
//получить все файлыиз каталога и удалить
95-
for (File f:
91+
for (File f :
9692
directory.listFiles()) {
9793
f.delete();
9894
}
Collapse file

‎src/com/urise/webapp/storage/MainFile.java‎

Copy file name to clipboardExpand all lines: src/com/urise/webapp/storage/MainFile.java
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ public static void main(String[] args) {
1414
}
1515
}
1616

17-
public static void findFiles(File file) throws IOException{
17+
public static void findFiles(File file) throws IOException {
1818
if (file.isDirectory()) {
1919
File[] list = file.listFiles();
20+
<<<<<<< HEAD
2021
if (list==null){
2122
System.out.println("Files not found!");
2223
return;
2324
}
2425
for (int i=list.length; --i>=0;) {
26+
=======
27+
for (int i = list.length; --i >= 0; ) {
28+
>>>>>>> lesson 8.
2529
findFiles(list[i]);
2630
}
2731
} else {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.