Skip to content

Commit 8c9324a

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

File tree

12 files changed

+104
-50
lines changed

12 files changed

+104
-50
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
importjava.time.LocalDate;
55
importjava.util.Calendar;
66
importjava.util.Date;
7-
importjava.util.Locale;
87

98
publicclassMainDate{
109
publicstaticvoidmain(String[] args){
11-
Datedate= newDate();
10+
Datedate= newDate();
1211
System.out.println(date.getTime());
1312
Calendarcal = Calendar.getInstance();
1413
System.out.println(cal.getTime());
15-
LocalDateld= LocalDate.now();
14+
LocalDateld= LocalDate.now();
1615
SimpleDateFormatsdf = newSimpleDateFormat("YY/MM/dd");
1716
System.out.println(sdf.format(cal.getTime()));
1817

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
packagecom.urise.webapp.exception;
22

3-
importjava.io.IOException;
4-
53
publicclassStorageExceptionextendsRuntimeException{
64
privatefinalStringuuid;
75

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

1311
publicStorageException(Stringmessage, Stringuuid, Exceptione){
14-
super(message,e);
12+
super(message,e);
1513
this.uuid = uuid;
1614

1715
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Link{
77
privatefinalStringurl;
88

99
publicLink(Stringname, Stringurl){
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
publicStringtoString(){
25-
return"Link ("+ name + ',' + url + ')';
25+
return"Link ("+ name + ',' + url + ')';
2626
}
2727

2828
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ListSection extends AbstractSection{
77
privatefinalList<String> items;
88

99
publicListSection(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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class OrganizationSection extends AbstractSection{
77
privatefinalList<Organization> organizations;
88

99
publicOrganizationSection(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

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
packagecom.urise.webapp.model;
22

3-
importjava.util.*;
3+
importjava.util.EnumMap;
4+
importjava.util.Map;
5+
importjava.util.Objects;
6+
importjava.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
publicStringgetContact (ContactTypetype){
3135
returncontacts.get(type);
@@ -41,6 +45,22 @@ public void addSection (SectionType type, AbstractSection section){
4145

4246
publicvoidaddContact (ContactTypetype, Stringcontact){
4347
contacts.put(type,contact);
48+
=======
49+
publicStringgetContact(ContactTypetype){
50+
returncontacs.get(type);
51+
}
52+
53+
publicSectiongetSection(SectionTypetype){
54+
returnsections.get(type);
55+
}
56+
57+
publicvoidaddSection(SectionTypetype, Sectionsection){
58+
sections.put(type, section);
59+
}
60+
61+
publicvoidaddContact(ContactTypetype, Stringcontact){
62+
contacs.put(type, contact);
63+
>>>>>>> lesson8.
4464
}
4565

4666

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
packagecom.urise.webapp.model;
22

33
publicenumSectionType{
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
privateStringtitle;
1212

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class TextSection extends AbstractSection{
66
privatefinalStringcontent;
77

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

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,38 @@ public abstract class AbstractFileStorage extends AbstractStorage{
1313
privateFiledirectory;
1414

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

2626
@Override
2727
protectedvoiddoUpdate(Resumeresume, ObjectsearchKey){
2828
//как doSave только в существующий
29-
Filef = (File)searchKey;
29+
Filef = (File)searchKey;
3030
try{
31-
doWrite(resume,f);
31+
doWrite(resume,f);
3232
} catch (IOExceptione){
3333
thrownewStorageException("IO error", f.getName(), e);
3434
}
3535
}
3636

3737
@Override
3838
protectedbooleanisExist(Objectfile){
39-
return ((File)file).exists();
39+
return ((File)file).exists();
4040
}
4141

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

5555
@Override
5656
protectedResumedoGet(ObjectsearchKey){
57-
//абстрактный останется
58-
59-
60-
returnnull;
57+
returndoRead ((File)searchKey);
6158
}
6259

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

7067
@Override
7168
protectedObjectgetSearchKey(Stringuuid){
72-
returnnewFile(directory,uuid);
69+
returnnewFile(directory,uuid);
7370
}
7471

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

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

Lines 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-
publicstaticvoidfindFiles(Filefile) throwsIOException{
17+
publicstaticvoidfindFiles(Filefile) throwsIOException{
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 (inti=list.length; --i>=0;){
26+
=======
27+
for (inti = list.length; --i >= 0; ){
28+
>>>>>>> lesson8.
2529
findFiles(list[i]);
2630
}
2731
} else{

0 commit comments

Comments
(0)