Suele pasar . Si solucionaste tu problema, no olvides marcar el tema como solucionado:
Saludos.
Saludos.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menúprivate List<Product> readProducts() {
List<Product> products = null;
Logger logger = Logger.getLogger(Principal.class.getName());
try (ObjectInputStream reader = new ObjectInputStream(
new FileInputStream("./estanteria.obj"))) {
products = new ArrayList<>();
Product product = null;
while( (product = (Product) reader.readObject() ) != null ) {
Product product = (Product) reader.readObject();
products.add(product);
}
} catch(IOException ioex) {
logger.warn(ioex.getMessage());
}
return products;
}
List<Product> products = new ArrayList<Product>();
List<Product> products = new ArrayList<>();
<table class="table" id="table-users">
<thead>
<tr>
<th>ID</th>
<th>Nombres</th>
<th>Apellidos</th>
<th>F. Nacimiento</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Juana</td>
<td>Urresti Echevarría</td>
</tr>
</tbody>
</table>
.#table-users > tbody tr:hover {
background-color: #f5f5f5;
}
if(!!Aprovincias.containsValue(provincia)){
res = false;
System.out.println("La Provincia no existe, creela antes de eliminar poblacion");
}
!Aprovincias.containsValue(provincia)
!!Aprovincias.containsValue(provincia)
public boolean addProvincia(String provincia) {
34. boolean res = false;
35. if(Aprovincias.containsKey(provincia)){
36. System.out.println("Ya existe la provincia");
37. }else{
38. Aprovincias.put(provincia, null);
39. res = true;
40. }
41. return res;
42. }
boolean response = provincias.addProvincia("Madrid");
System.out.println(response);
Población instanceof IPoblacion
List<String> lista = new ArrayList<>();
package net.elhacker.demo.model.entities;
public interface Population {
String getProvinceName();
void setProvinceName(String provinceName);
int getSomething();
void setSomething(int value);
String getStateName();
void setStateName(String stateName);
}
package net.elhacker.demo.model.entities;
public class PopulationImp implements Population {
private String provinceName;
private int something;
private String stateName;
public PopulationImp() {}
public PopulationImp(String provinceName, int something, String stateName) {
super();
this.provinceName = provinceName;
this.something = something;
this.stateName = stateName;
}
@Override
public String getProvinceName() {
return provinceName;
}
@Override
public void setProvinceName(String provinceName) {
this.provinceName = provinceName;
}
@Override
public int getSomething() {
return something;
}
@Override
public void setSomething(int something) {
this.something = something;
}
@Override
public String getStateName() {
return stateName;
}
@Override
public void setStateName(String stateName) {
this.stateName = stateName;
}
}
package net.elhacker.demo.model.services;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.elhacker.demo.model.entities.Population;
public class PopulationService {
private static Map<String, Set<Population>> provincesAndPopulations;
public PopulationService() {
provincesAndPopulations = new HashMap<>();
}
public void addProvince(String provinceName) {
if(provincesAndPopulations.containsKey(provinceName)) return;
provincesAndPopulations.put(provinceName, null);
}
public Object[] addPopulation(String provinceName, Population population) {
Object[] response = new Object[2];
if(!provincesAndPopulations.containsKey(provinceName)) {
response[0] = "La provincia no existe, primero créela";
response[1] = false;
} else {
Set<Population> provincePopulation = this.getPopulationByProvinceName(provinceName);
provincePopulation.add(population);
response[0] = "Provincia añadida correctamente";
response[1] = true;
}
return response;
}
public boolean addProvinceAndPopulation(String provinceName, Population population) {
boolean success = false;
if(!provincesAndPopulations.containsKey(provinceName)) {
Set<Population> provincePopulation = new HashSet<>();
provincePopulation.add(population);
provincesAndPopulations.put(provinceName, provincePopulation);
success = true;
}
return success;
}
private Set<Population> getPopulationByProvinceName(String provinceName) {
Set<Population> population = null;
for(Map.Entry<String, Set<Population>> entry : provincesAndPopulations.entrySet()) {
if(entry.getKey().equals(provinceName))
population = entry.getValue();
}
return population;
}
public void showAll() {
for(Map.Entry<String, Set<Population>> entry : provincesAndPopulations.entrySet()) {
System.out.println("Poblaciones del estado "+entry.getKey()+":\n");
for(Population population : entry.getValue()) {
System.out.println(population.getProvinceName());
System.out.println(population.getSomething());
System.out.println(population.getStateName());
System.out.println();
}
System.out.println();
}
}
}
package net.elhacker.demo;
import net.elhacker.demo.model.entities.Population;
import net.elhacker.demo.model.entities.PopulationImp;
import net.elhacker.demo.model.services.PopulationService;
public class Test {
public static void main(String[] args) {
PopulationService populationService = new PopulationService();
Population population = new PopulationImp("Getafe", 0, "Madrid");
populationService.addProvinceAndPopulation("Madrid", population);
population = new PopulationImp("Leganes", 345, "Madrid");
Object[] response = populationService.addPopulation("Madrid", population);
System.out.println(response[0]);
System.out.println("\n*** Mostrando todas las provincias y sus poblaciones ***\n");
populationService.showAll();
}
}
CitarProvincia añadida correctamente
*** Mostrando todas las provincias y sus poblaciones ***
Poblaciones del estado Madrid:
Getafe
0
Madrid
Leganes
345
Madrid