You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
package tiaozhanti1;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import jichuti1.Book;
|
|
import jinjieti1.BranchLibrary;
|
|
import jinjieti1.Library;
|
|
|
|
/**
|
|
* 图书资源共享管理类(多对多聚合关系)
|
|
*/
|
|
public class ResourceSharingManager {
|
|
private List<Library> libraries; // 参与共享的图书馆
|
|
private Map<Book, List<Library>> sharedBooks; // 共享图书映射
|
|
|
|
public ResourceSharingManager() {
|
|
this.libraries = new ArrayList<>();
|
|
this.sharedBooks = new HashMap<>();
|
|
}
|
|
|
|
// 添加参与共享的图书馆
|
|
public void addLibrary(Library lib2) {
|
|
libraries.add(lib2);
|
|
}
|
|
|
|
// 共享图书
|
|
public void shareBook(Book book, Library fromLib, List<Library> toLibs) {
|
|
for (Library lib : toLibs) {
|
|
if (libraries.contains(lib) && !lib.equals(fromLib)) {
|
|
sharedBooks.computeIfAbsent(book, k -> new ArrayList<>()).add(lib);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void shareBook(Book sharedBook, BranchLibrary lib1, List<BranchLibrary> of) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void addLibrary(BranchLibrary lib1) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
}
|