### EstoqueProdutos API Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/map/README.md API documentation for a conceptual EstoqueProdutos class that uses a Java Map to manage product inventory, including quantities and prices. ```APIDOC EstoqueProdutos: Description: Manages product inventory, mapping product codes to product details. Implements: Uses java.util.Map internally, where Produto is a custom class. Methods: adicionarProduto(long cod, String nome, int quantidade, double preco): - Adds a new product or updates an existing one in the stock. - Parameters: - cod: The unique code for the product (long, key). - nome: The name of the product (String). - quantidade: The current stock quantity (int). - preco: The price per unit of the product (double). - Returns: void exibirProdutos(): - Displays all products in the stock, including their code, name, quantity, and price. - Iterates through the map and prints details for each product. - Returns: void calcularValorTotalEstoque(): - Calculates the total monetary value of all products currently in stock. - For each product, multiplies quantity by price and sums these values. - Returns: The total stock value (double). obterProdutoMaisCaro(): - Finds and returns the product with the highest price per unit. - Iterates through the map, comparing prices. - Returns: The product object (Produto) with the highest price, or null if the stock is empty. obterProdutoMaisBarato(): - Finds and returns the product with the lowest price per unit. - Iterates through the map, comparing prices. - Returns: The product object (Produto) with the lowest price, or null if the stock is empty. obterProdutoMaiorQuantidadeValorTotalNoEstoque(): - Identifies the product that represents the highest total value in stock (quantity * price). - Calculates the total value for each product and finds the maximum. - Returns: The product object (Produto) with the highest total value, or null if the stock is empty. ``` -------------------------------- ### EstoqueProdutos API Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/map/README.md API documentation for a conceptual EstoqueProdutos class that uses a Java Map to manage product inventory, including quantities and prices. ```APIDOC EstoqueProdutos: Description: Manages product inventory, mapping product codes to product details. Implements: Uses java.util.Map internally, where Produto is a custom class. Methods: adicionarProduto(long cod, String nome, int quantidade, double preco): - Adds a new product or updates an existing one in the stock. - Parameters: - cod: The unique code for the product (long, key). - nome: The name of the product (String). - quantidade: The current stock quantity (int). - preco: The price per unit of the product (double). - Returns: void exibirProdutos(): - Displays all products in the stock, including their code, name, quantity, and price. - Iterates through the map and prints details for each product. - Returns: void calcularValorTotalEstoque(): - Calculates the total monetary value of all products currently in stock. - For each product, multiplies quantity by price and sums these values. - Returns: The total stock value (double). obterProdutoMaisCaro(): - Finds and returns the product with the highest price per unit. - Iterates through the map, comparing prices. - Returns: The product object (Produto) with the highest price, or null if the stock is empty. obterProdutoMaisBarato(): - Finds and returns the product with the lowest price per unit. - Iterates through the map, comparing prices. - Returns: The product object (Produto) with the lowest price, or null if the stock is empty. obterProdutoMaiorQuantidadeValorTotalNoEstoque(): - Identifies the product that represents the highest total value in stock (quantity * price). - Calculates the total value for each product and finds the maximum. - Returns: The product object (Produto) with the highest total value, or null if the stock is empty. ``` -------------------------------- ### Dicionario API Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/map/README.md API documentation for a conceptual Dicionario class that uses a Java Map to store words and their definitions. ```APIDOC Dicionario: Description: Manages a collection of words and their definitions. Implements: Uses java.util.Map internally. Methods: adicionarPalavra(String palavra, String definicao): - Adds a word and its definition to the dictionary. - Parameters: - palavra: The word to add (String, key). - definicao: The definition of the word (String, value). - Returns: void removerPalavra(String palavra): - Removes a word and its definition from the dictionary. - Parameters: - palavra: The word to remove (String). - Returns: void exibirPalavras(): - Displays all words and their definitions stored in the dictionary. - Iterates through the map and prints each word-definition pair. - Returns: void pesquisarPorPalavra(String palavra): - Retrieves the definition for a given word. - Parameters: - palavra: The word to search for (String). - Returns: The definition (String) if the word is found, otherwise null or throws an exception. ``` -------------------------------- ### Java Set: Conjunto de Convidados Operations Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/set/README.md Implements methods to manage a set of guests, identified by invitation code. This includes adding guests, removing them by code, counting the total number of guests, and displaying all guests. ```Java import java.util.HashSet; import java.util.Set; class Convidado { private String nome; private int codigoConvite; public Convidado(String nome, int codigoConvite) { this.nome = nome; this.codigoConvite = codigoConvite; } public String getNome() { return nome; } public int getCodigoConvite() { return codigoConvite; } @Override public String toString() { return "Convidado{" + "nome='" + nome + '\'' + ", codigoConvite=" + codigoConvite + '}'; } // Equals and hashCode based on codigoConvite for uniqueness in Set @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Convidado convidado = (Convidado) o; return codigoConvite == convidado.codigoConvite; } @Override public int hashCode() { return Integer.hashCode(codigoConvite); } } public class ConjuntoConvidados { private Set convidadosSet; public ConjuntoConvidados() { this.convidadosSet = new HashSet<>(); } public void adicionarConvidado(String nome, int codigoConvite) { Convidado novoConvidado = new Convidado(nome, codigoConvite); convidadosSet.add(novoConvidado); System.out.println("Convidado adicionado: " + nome); } public void removerConvidadoPorCodigoConvite(int codigoConvite) { Convidado convidadoParaRemover = null; for (Convidado c : convidadosSet) { if (c.getCodigoConvite() == codigoConvite) { convidadoParaRemover = c; break; } } if (convidadoParaRemover != null) { convidadosSet.remove(convidadoParaRemover); System.out.println("Convidado removido com código " + codigoConvite); } else { System.out.println("Convidado com código " + codigoConvado + " não encontrado."); } } public int contarConvidados() { return convidadosSet.size(); } public void exibirConvidados() { System.out.println("Lista de Convidados:"); for (Convidado c : convidadosSet) { System.out.println(c); } } } ``` -------------------------------- ### AgendaContatos API Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/map/README.md API documentation for a conceptual AgendaContatos class that uses a Java Map to store contact names and phone numbers. ```APIDOC AgendaContatos: Description: Manages a collection of contacts, mapping names to phone numbers. Implements: Uses java.util.Map internally. Methods: adicionarContato(String nome, Integer telefone): - Adds or updates a contact in the agenda. - Parameters: - nome: The name of the contact (String, key). - telefone: The phone number of the contact (Integer, value). - Returns: void removerContato(String nome): - Removes a contact from the agenda by name. - Parameters: - nome: The name of the contact to remove (String). - Returns: void exibirContatos(): - Displays all contacts currently stored in the agenda. - Iterates through the map and prints each name-phone pair. - Returns: void pesquisarPorNome(String nome): - Retrieves the phone number associated with a given contact name. - Parameters: - nome: The name of the contact to search for (String). - Returns: The phone number (Integer) if found, otherwise null or throws an exception depending on implementation. ``` -------------------------------- ### Java Set: Agenda de Contatos Operations Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/set/README.md Manages a contact list using a Set, where each contact has a name and phone number. Supports adding contacts, displaying all contacts, searching for contacts by name, and updating a contact's phone number. ```Java import java.util.HashSet; import java.util.Set; import java.util.Iterator; class Contato { private String nome; private int numero; public Contato(String nome, int numero) { this.nome = nome; this.numero = numero; } public String getNome() { return nome; } public int getNumero() { return numero; } public void setNumero(int numero) { this.numero = numero; } @Override public String toString() { return "Contato{" + "nome='" + nome + '\'' + ", numero=" + numero + '}'; } // Equals and hashCode based on nome for uniqueness and searching @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Contato contato = (Contato) o; return nome.equalsIgnoreCase(contato.nome); } @Override public int hashCode() { return nome.toLowerCase().hashCode(); } } public class AgendaContatos { private Set agendaSet; public AgendaContatos() { this.agendaSet = new HashSet<>(); } public void adicionarContato(String nome, int numero) { Contato novoContato = new Contato(nome, numero); if (agendaSet.add(novoContato)) { System.out.println("Contato adicionado: " + nome); } else { System.out.println("Contato com nome '" + nome + "' já existe. Use atualizarNumeroContato para modificar."); } } public void exibirContatos() { System.out.println("Agenda de Contatos:"); if (agendaSet.isEmpty()) { System.out.println("A agenda está vazia."); } else { for (Contato c : agendaSet) { System.out.println(c); } } } public Set pesquisarPorNome(String nome) { Set contatosEncontrados = new HashSet<>(); for (Contato c : agendaSet) { if (c.getNome().equalsIgnoreCase(nome)) { contatosEncontrados.add(c); } } if (contatosEncontrados.isEmpty()) { System.out.println("Nenhum contato encontrado com o nome: " + nome); } else { System.out.println("Contatos encontrados para '" + nome + "':"); for (Contato c : contatosEncontrados) { System.out.println(c); } } return contatosEncontrados; } public void atualizarNumeroContato(String nome, int novoNumero) { Contato contatoParaAtualizar = null; for (Contato c : agendaSet) { if (c.getNome().equalsIgnoreCase(nome)) { contatoParaAtualizar = c; break; } } if (contatoParaAtualizar != null) { contatoParaAtualizar.setNumero(novoNumero); System.out.println("Número de " + nome + " atualizado para " + novoNumero); } else { System.out.println("Contato com nome '" + nome + "' não encontrado para atualização."); } } } ``` -------------------------------- ### AgendaContatos API Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/map/README.md API documentation for a conceptual AgendaContatos class that uses a Java Map to store contact names and phone numbers. ```APIDOC AgendaContatos: Description: Manages a collection of contacts, mapping names to phone numbers. Implements: Uses java.util.Map internally. Methods: adicionarContato(String nome, Integer telefone): - Adds or updates a contact in the agenda. - Parameters: - nome: The name of the contact (String, key). - telefone: The phone number of the contact (Integer, value). - Returns: void removerContato(String nome): - Removes a contact from the agenda by name. - Parameters: - nome: The name of the contact to remove (String). - Returns: void exibirContatos(): - Displays all contacts currently stored in the agenda. - Iterates through the map and prints each name-phone pair. - Returns: void pesquisarPorNome(String nome): - Retrieves the phone number associated with a given contact name. - Parameters: - nome: The name of the contact to search for (String). - Returns: The phone number (Integer) if found, otherwise null or throws an exception depending on implementation. ``` -------------------------------- ### Java Set: Agenda de Contatos Operations Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/set/README.md Manages a contact list using a Set, where each contact has a name and phone number. Supports adding contacts, displaying all contacts, searching for contacts by name, and updating a contact's phone number. ```Java import java.util.HashSet; import java.util.Set; import java.util.Iterator; class Contato { private String nome; private int numero; public Contato(String nome, int numero) { this.nome = nome; this.numero = numero; } public String getNome() { return nome; } public int getNumero() { return numero; } public void setNumero(int numero) { this.numero = numero; } @Override public String toString() { return "Contato{" + "nome='" + nome + '\'' + ", numero=" + numero + '}'; } // Equals and hashCode based on nome for uniqueness and searching @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Contato contato = (Contato) o; return nome.equalsIgnoreCase(contato.nome); } @Override public int hashCode() { return nome.toLowerCase().hashCode(); } } public class AgendaContatos { private Set agendaSet; public AgendaContatos() { this.agendaSet = new HashSet<>(); } public void adicionarContato(String nome, int numero) { Contato novoContato = new Contato(nome, numero); if (agendaSet.add(novoContato)) { System.out.println("Contato adicionado: " + nome); } else { System.out.println("Contato com nome '" + nome + "' já existe. Use atualizarNumeroContato para modificar."); } } public void exibirContatos() { System.out.println("Agenda de Contatos:"); if (agendaSet.isEmpty()) { System.out.println("A agenda está vazia."); } else { for (Contato c : agendaSet) { System.out.println(c); } } } public Set pesquisarPorNome(String nome) { Set contatosEncontrados = new HashSet<>(); for (Contato c : agendaSet) { if (c.getNome().equalsIgnoreCase(nome)) { contatosEncontrados.add(c); } } if (contatosEncontrados.isEmpty()) { System.out.println("Nenhum contato encontrado com o nome: " + nome); } else { System.out.println("Contatos encontrados para '" + nome + "':"); for (Contato c : contatosEncontrados) { System.out.println(c); } } return contatosEncontrados; } public void atualizarNumeroContato(String nome, int novoNumero) { Contato contatoParaAtualizar = null; for (Contato c : agendaSet) { if (c.getNome().equalsIgnoreCase(nome)) { contatoParaAtualizar = c; break; } } if (contatoParaAtualizar != null) { contatoParaAtualizar.setNumero(novoNumero); System.out.println("Número de " + nome + " atualizado para " + novoNumero); } else { System.out.println("Contato com nome '" + nome + "' não encontrado para atualização."); } } } ``` -------------------------------- ### Dicionario API Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/map/README.md API documentation for a conceptual Dicionario class that uses a Java Map to store words and their definitions. ```APIDOC Dicionario: Description: Manages a collection of words and their definitions. Implements: Uses java.util.Map internally. Methods: adicionarPalavra(String palavra, String definicao): - Adds a word and its definition to the dictionary. - Parameters: - palavra: The word to add (String, key). - definicao: The definition of the word (String, value). - Returns: void removerPalavra(String palavra): - Removes a word and its definition from the dictionary. - Parameters: - palavra: The word to remove (String). - Returns: void exibirPalavras(): - Displays all words and their definitions stored in the dictionary. - Iterates through the map and prints each word-definition pair. - Returns: void pesquisarPorPalavra(String palavra): - Retrieves the definition for a given word. - Parameters: - palavra: The word to search for (String). - Returns: The definition (String) if the word is found, otherwise null or throws an exception. ``` -------------------------------- ### Java Set: Conjunto de Convidados Operations Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/set/README.md Implements methods to manage a set of guests, identified by invitation code. This includes adding guests, removing them by code, counting the total number of guests, and displaying all guests. ```Java import java.util.HashSet; import java.util.Set; class Convidado { private String nome; private int codigoConvite; public Convidado(String nome, int codigoConvite) { this.nome = nome; this.codigoConvite = codigoConvite; } public String getNome() { return nome; } public int getCodigoConvite() { return codigoConvite; } @Override public String toString() { return "Convidado{" + "nome='" + nome + '\'' + ", codigoConvite=" + codigoConvite + '}'; } // Equals and hashCode based on codigoConvite for uniqueness in Set @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Convidado convidado = (Convidado) o; return codigoConvite == convidado.codigoConvite; } @Override public int hashCode() { return Integer.hashCode(codigoConvite); } } public class ConjuntoConvidados { private Set convidadosSet; public ConjuntoConvidados() { this.convidadosSet = new HashSet<>(); } public void adicionarConvidado(String nome, int codigoConvite) { Convidado novoConvidado = new Convidado(nome, codigoConvite); convidadosSet.add(novoConvidado); System.out.println("Convidado adicionado: " + nome); } public void removerConvidadoPorCodigoConvite(int codigoConvite) { Convidado convidadoParaRemover = null; for (Convidado c : convidadosSet) { if (c.getCodigoConvite() == codigoConvite) { convidadoParaRemover = c; break; } } if (convidadoParaRemover != null) { convidadosSet.remove(convidadoParaRemover); System.out.println("Convidado removido com código " + codigoConvite); } else { System.out.println("Convidado com código " + codigoConvado + " não encontrado."); } } public int contarConvidados() { return convidadosSet.size(); } public void exibirConvidados() { System.out.println("Lista de Convidados:"); for (Convidado c : convidadosSet) { System.out.println(c); } } } ``` -------------------------------- ### Java Set: Conjunto de Palavras Únicas Operations Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/set/README.md Manages a set of unique words. Provides functionality to add new words, remove existing words, check for the presence of a word, and display all unique words stored in the set. ```Java import java.util.HashSet; import java.util.Set; public class ConjuntoPalavrasUnicas { private Set palavrasSet; public ConjuntoPalavrasUnicas() { this.palavrasSet = new HashSet<>(); } public void adicionarPalavra(String palavra) { palavrasSet.add(palavra); System.out.println("Palavra adicionada: " + palavra); } public void removerPalavra(String palavra) { if (palavrasSet.remove(palavra)) { System.out.println("Palavra removida: " + palavra); } else { System.out.println("Palavra não encontrada: " + palavra); } } public boolean verificarPalavra(String palavra) { boolean presente = palavrasSet.contains(palavra); System.out.println("Palavra '" + palavra + "' está presente? " + presente); return presente; } public void exibirPalavrasUnicas() { System.out.println("Palavras Únicas:"); for (String palavra : palavrasSet) { System.out.println(palavra); } } } ``` -------------------------------- ### Java Set: Conjunto de Palavras Únicas Operations Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/set/README.md Manages a set of unique words. Provides functionality to add new words, remove existing words, check for the presence of a word, and display all unique words stored in the set. ```Java import java.util.HashSet; import java.util.Set; public class ConjuntoPalavrasUnicas { private Set palavrasSet; public ConjuntoPalavrasUnicas() { this.palavrasSet = new HashSet<>(); } public void adicionarPalavra(String palavra) { palavrasSet.add(palavra); System.out.println("Palavra adicionada: " + palavra); } public void removerPalavra(String palavra) { if (palavrasSet.remove(palavra)) { System.out.println("Palavra removida: " + palavra); } else { System.out.println("Palavra não encontrada: " + palavra); } } public boolean verificarPalavra(String palavra) { boolean presente = palavrasSet.contains(palavra); System.out.println("Palavra '" + palavra + "' está presente? " + presente); return presente; } public void exibirPalavrasUnicas() { System.out.println("Palavras Únicas:"); for (String palavra : palavrasSet) { System.out.println(palavra); } } } ``` -------------------------------- ### Java Set Interface Overview Source: https://github.com/cami-la/collections-java-api-2023/blob/master/out/production/collections-java-api-2023/main/java/set/README.md The Java Set interface represents a collection that cannot contain duplicate elements. It is used to represent mathematical sets and has three general-purpose implementations: HashSet, TreeSet, and LinkedHashSet. Sets do not allow random access to elements; iteration is typically done using an iterator or a foreach loop. ```Java /** * A collection that contains no duplicate elements. * More formally, sets contain no pair of elements e1 and e2 * such that e1.equals(e2), and at most one null element. */ interface Set extends Collection { // Basic operations int size(); boolean isEmpty(); boolean contains(Object o); Iterator iterator(); Object[] toArray(); T[] toArray(T[] a); boolean add(E e); boolean remove(Object o); // Bulk operations boolean containsAll(Collection c); boolean addAll(Collection c); boolean retainAll(Collection c); boolean removeAll(Collection c); void clear(); // Comparison and hashing boolean equals(Object o); int hashCode(); // Transformation T[] toArray(IntFunction a); // Views // SortedSet operations (if applicable, e.g., for TreeSet) // NavigableSet operations (if applicable) } // Implementations: // HashSet: Stores elements in a hash table, no guaranteed order, efficient search. // TreeSet: Stores elements in a balanced binary tree, elements are sorted. // LinkedHashSet: Stores elements in a hash table and a doubly-linked list, maintains insertion order. ``` -------------------------------- ### Java Set Interface Overview Source: https://github.com/cami-la/collections-java-api-2023/blob/master/src/main/java/set/README.md The Java Set interface represents a collection that cannot contain duplicate elements. It is used to represent mathematical sets and has three general-purpose implementations: HashSet, TreeSet, and LinkedHashSet. Sets do not allow random access to elements; iteration is typically done using an iterator or a foreach loop. ```Java /** * A collection that contains no duplicate elements. * More formally, sets contain no pair of elements e1 and e2 * such that e1.equals(e2), and at most one null element. */ interface Set extends Collection { // Basic operations int size(); boolean isEmpty(); boolean contains(Object o); Iterator iterator(); Object[] toArray(); T[] toArray(T[] a); boolean add(E e); boolean remove(Object o); // Bulk operations boolean containsAll(Collection c); boolean addAll(Collection c); boolean retainAll(Collection c); boolean removeAll(Collection c); void clear(); // Comparison and hashing boolean equals(Object o); int hashCode(); // Transformation T[] toArray(IntFunction a); // Views // SortedSet operations (if applicable, e.g., for TreeSet) // NavigableSet operations (if applicable) } // Implementations: // HashSet: Stores elements in a hash table, no guaranteed order, efficient search. // TreeSet: Stores elements in a balanced binary tree, elements are sorted. // LinkedHashSet: Stores elements in a hash table and a doubly-linked list, maintains insertion order. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.