Download benchmarks/java/Library.java from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/java/Library.java
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/java/Library.java
-
curl -L -o Library.java https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/java/Library.java
2.25 kB
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.Optional; | |
| /** | |
| * Kütüphane ödünç sistemi — arayüz (sözleşme) testleri için örnek. | |
| * Genel API: | |
| * addBook(isbn, title) -> boolean (yeni eklendiyse true) | |
| * borrow(isbn, member) -> IllegalStateException (ödünçte), NoSuchElementException (yok) | |
| * giveBack(isbn) -> Optional<String> (iade eden üye) | |
| * borrowedBy(member) -> List<String> isbn (alfabetik sıralı) | |
| * isAvailable(isbn) -> boolean | |
| * Bir üye en fazla MAX_LOANS kitap ödünç alabilir. | |
| */ | |
| public class Library { | |
| public static final int MAX_LOANS = 3; | |
| private final Map<String, String> titles = new HashMap<>(); | |
| private final Map<String, String> loans = new HashMap<>(); | |
| public boolean addBook(String isbn, String title) { | |
| if (isbn == null || isbn.isBlank() || title == null || title.isBlank()) { | |
| throw new IllegalArgumentException("isbn and title are required"); | |
| } | |
| return titles.putIfAbsent(isbn, title) == null; | |
| } | |
| public void borrow(String isbn, String member) { | |
| if (!titles.containsKey(isbn)) { | |
| throw new java.util.NoSuchElementException("unknown book: " + isbn); | |
| } | |
| if (loans.containsKey(isbn)) { | |
| throw new IllegalStateException("already borrowed"); | |
| } | |
| if (borrowedBy(member).size() >= MAX_LOANS) { | |
| throw new IllegalStateException("loan limit reached"); | |
| } | |
| loans.put(isbn, member); | |
| } | |
| public Optional<String> giveBack(String isbn) { | |
| return Optional.ofNullable(loans.remove(isbn)); | |
| } | |
| public List<String> borrowedBy(String member) { | |
| List<String> out = new ArrayList<>(); | |
| for (Map.Entry<String, String> e : loans.entrySet()) { | |
| if (e.getValue().equals(member)) { | |
| out.add(e.getKey()); | |
| } | |
| } | |
| out.sort(String::compareTo); | |
| return out; | |
| } | |
| public boolean isAvailable(String isbn) { | |
| return titles.containsKey(isbn) && !loans.containsKey(isbn); | |
| } | |
| public int bookCount() { | |
| return titles.size(); | |
| } | |
| } | |