public Map<String, String> getAllUsers() { Config pwdConfig = new Config("user"); TreeMap<String, String> users = new TreeMap<>(); String suffix = ".password"; for (String user : pwdConfig.listKeys()) { if (user.endsWith(suffix)) { String name = user.substring(0, user.length() - suffix.length()); users.put(name.trim(), pwdConfig.getString(user).trim()); } } return users; }
public void cadastrarOrcamento(boolean cond, String forma_pag, String obs, String garantia) { if (itens.size() > 0) { Orcamento orcamento = new Orcamento(); orcamento.setForma_pag(forma_pag); orcamento.setObs(obs); orcamento.setGarantia(garantia); orcamento.setCliente(Config.getCliente()); orcamento.setDia_orcamento(Calendar.getInstance()); orcamento.setValor(valorTotal); if (cond) { dao.create(orcamento); orcamento.setItens(itens); try { dao.edit(orcamento); } catch (Exception ex) { } JOptionPane.showMessageDialog(null, "Salvo"); int op = JOptionPane.showConfirmDialog( null, "Deseja imprimir?", "Messagem", JOptionPane.YES_OPTION); if (JOptionPane.YES_OPTION == op) { impressao.imprimirOrcamento(orcamento); } } else { impressao.imprimirOrcamento(orcamento); } limpar(); } else { JOptionPane.showMessageDialog(null, "Adicione algum Produto.", "Atenção", 0); } }
@Override public synchronized void readUsers() { for (String userPropertyKey : config.listKeys()) { UserProperty property = new UserProperty(userPropertyKey, config.getString(userPropertyKey)); UserModel user = getUser(property.getUsername()); if (user == null) user = new UserModel(property.getUsername()); PropertyMapper mapper = new PropertyMapper<UserModel>(user); mapper.map(property.getPropertyName(), property.getPropertyValue()); users.put(user.getUserName(), user); } }
/** * @param componentName the name of the component - represented in the prompt * @param config the configuration to use * @param userRequestStream the input stream to read user input from * @param userResponseStream the output stream to write the console output to */ public Chatserver( String componentName, Config config, InputStream userRequestStream, PrintStream userResponseStream) { super(componentName, config, userRequestStream, userResponseStream); this.startTcpServer(config.getInt("tcp.port")); this.startUdpServer(config.getInt("udp.port")); }
public static void main(String[] argv) throws Exception { int numMsg = Config.getNumMsg(); int numByte = Config.getNumByte(); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); // String message = "Hello World!enheng?"; String message = GenString.gen(numByte); long start = System.nanoTime(); // do stuff for (int i = 0; i < numMsg; i++) channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); long end = System.nanoTime(); long microseconds = (end - start) / 1000; System.out.println( " [x] Total time used for " + numMsg + " messages of " + numByte + " bytes: " + microseconds + " micro seconds"); System.out.println( " [x] Time used per message of " + numByte + " bytes: " + (float) microseconds / numMsg + " milli seconds"); System.out.println(" [x] Sent '" + message.toString() + "'"); channel.close(); connection.close(); }
public static void main(String[] args) { // TODO Auto-generated method stub projectName = globalConfig.getValue("project"); projectConfig = new Config("config/" + projectName + ".properties"); issues = (JSONArray) JSONUtil.readJsonFromFile(projectConfig.getValue("ISSUE_FILE")); smells = (JSONArray) JSONUtil.readJsonFromFile(projectConfig.getValue("SMELL_PKG")); addSmess2All(); JSONUtil.writeJSONArray2File(issues, projectConfig.getValue("DEP_CON_PKG")); smells = (JSONArray) JSONUtil.readJsonFromFile(projectConfig.getValue("SMELL_ARC")); addSmess2All(); JSONUtil.writeJSONArray2File(issues, projectConfig.getValue("DEP_CON_ARC")); smells = (JSONArray) JSONUtil.readJsonFromFile(projectConfig.getValue("SMELL_ACDC")); addSmess2All(); JSONUtil.writeJSONArray2File(issues, projectConfig.getValue("DEP_CON_ACDC")); // StringUtil.printStringSet(getDirectoryPrefix()); System.out.println("done! (๑•ᴗ•๑)♡‼"); }
public static void addSmell2Issue(JSONObject issue) { JSONArray commits = (JSONArray) issue.get("commits"); // iterate commits for (int commitIdx = 0; commitIdx < commits.size(); commitIdx++) { JSONObject commit = (JSONObject) commits.get(commitIdx); JSONArray files = (JSONArray) commit.get("files"); // iterate files in each commit for (int fileIdx = 0; fileIdx < files.size(); fileIdx++) { JSONObject file = (JSONObject) files.get(fileIdx); String filename = (String) file.get("filename"); String[] pkgPrefixs = projectConfig.getValue("PKG_PREFIX").split("#"); if (StringUtil.isValidFilename(filename, pkgPrefixs)) { addSmell2File(issue, file, filename); } } } }
public void alterarOrcamento(String forma_pag, String obs, String garantia, Orcamento orcamento) { if (itens.size() > 0) { orcamento.setForma_pag(forma_pag); orcamento.setObs(obs); orcamento.setGarantia(garantia); orcamento.setCliente(Config.getCliente()); orcamento.setDia_orcamento(Calendar.getInstance()); orcamento.setValor(valorTotal); List<Itens> itensAux = new ArrayList<Itens>(); try { orcamento.setItens(itensAux); dao.edit(orcamento); deletarLista(orcamento); orcamento.setItens(itens); } catch (Exception ex) { System.out.println("erro de itens 1"); } try { // orcamento.setItens(criarLista(orcamento)); dao.edit(orcamento); } catch (Exception ex) { System.out.println("erro de itens 2"); } JOptionPane.showMessageDialog(null, "Salvo"); int op = JOptionPane.showConfirmDialog( null, "Deseja imprimir?", "Messagem", JOptionPane.YES_OPTION); if (JOptionPane.YES_OPTION == op) { impressao.imprimirOrcamento(orcamento); } limpar(); } else { JOptionPane.showMessageDialog(null, "Adicione algum Produto.", "Atenção", 0); } }
/** * Constructor that generates the Black Hole. * * @param world The worldCollection in which it resides * @param position Its initial position * @param mass Its mass * @param radius Its radius */ public BlackHole(WorldCollection world, Vector2D position, double mass, double radius) { super(world, position, mass, radius); gravity = Double.parseDouble(Config.get("Gravity_constant")); }
public static void main(String[] args) throws Exception { if (Config.getInstance().getValue("TYPE").equals("default")) { String[] receivers = Config.getInstance().getValue("RECEIVERS").split(","); String[] issuers = Config.getInstance().getValue("ISSUERS").split(","); // create clients List<Client> clients = new ArrayList<Client>(); for (int i = 0; i < Integer.parseInt(Config.getInstance().getValue("CLIENT_COUNT")); i++) { System.out.println("client added"); System.out.println(Integer.parseInt(Config.getInstance().getValue("CLIENT_COUNT"))); clients.add(new Client()); } // first receiver and issuer by now String[] receiver = receivers[0].split(":"); String[] issuer = issuers[0].split(":"); // send queries for (int i = 0; i < Integer.parseInt(Config.getInstance().getValue("QUERY_COUNT")); i++) { for (int j = 0; j < clients.size(); j++) { System.out.println("client " + j + " started"); PEASDoQueries thread = new PEASDoQueries( j, clients.get(j), receiver[0], Integer.parseInt(receiver[1]), issuer[0], Integer.parseInt(issuer[1]), Config.getInstance().getValue("QUERY")); thread.start(); } } } else if (Config.getInstance().getValue("TYPE").equals("onion")) { String[] nodes = Config.getInstance().getValue("NODES").split(","); List<Map<String, String>> servers = new ArrayList<Map<String, String>>(); // create clients List<OnionClient> clients = new ArrayList<OnionClient>(); for (int i = 0; i < Integer.parseInt(Config.getInstance().getValue("CLIENT_COUNT")); i++) { clients.add(new OnionClient()); } // read node addresses for (int i = 0; i < nodes.length; i++) { String[] host = nodes[i].split(":"); Map<String, String> node = new HashMap<String, String>(); node.put("hostname", host[0]); node.put("port", host[1]); servers.add(node); } // send queries for (int i = 0; i < Integer.parseInt(Config.getInstance().getValue("QUERY_COUNT")); i++) { for (int j = 0; j < clients.size(); j++) { OnionDoQueries thread = new OnionDoQueries( j, clients.get(j), servers, Config.getInstance().getValue("QUERY")); thread.start(); } } } }
/** * El metodo se encarga de realizar la asignación Hibrida para depósitos con capacidad limitada * (Algoritmo 1). * * <p>Recibe por parámetro <code>DTDepositoVRP</code> donde contiene toda la información del * problema a resolver. * * <p>Retorna una colección de <code>DTAsignacion</code>. Cada <code>DTAsignacion</code> contiene * un deposito y una colección de clientes que estan asignados al deposito. * * @param d <code>DTDepositoVRP</code> donde contiene toda la información del problema a resolver. * @return Devuelve una colección de <code>DTAsignacion</code>.. */ public Collection<DTAsignacion> asignar(DTDepositoVRP d) { System.out.println("Asignar capacidad"); clientes = new ArrayList<ClienteCap2>(); depositos = new ArrayList<Deposito>(); enajenados = new ArrayList<Enajenado>(); Iterator<DTNodo> it = d.getNodos().iterator(); while (it.hasNext()) { DTNodo dt = it.next(); if (dt.getEsDesposito()) { Deposito dep = new Deposito(dt); depositos.add(dep); } } Iterator<DTNodo> it2 = d.getNodos().iterator(); while (it2.hasNext()) { DTNodo dt = it2.next(); if (!dt.getEsDesposito()) { ClienteCap2 cli = new ClienteCap2(dt); cli.setMu(calcularMu(cli, depositos)); clientes.add(cli); } } // Calculo los 2 clientes mas cercanos para cada cliente (precalculo para fase 2) Iterator<ClienteCap2> it3 = this.clientes.iterator(); while (it3.hasNext()) { ClienteCap2 cliente = it3.next(); cliente = addClientesMasCercanos(cliente); System.out.println( "Clientes mas cercanos" + cliente.getNodo().getId() + " y nodos " + cliente.getClieteMasCercano1().getNodo().getId() + " ," + cliente.getClieteMasCercano2().getNodo().getId()); } // Asigno los nodos por urgencia (fase 1). while (clientes.size() > 0) { TreeSet<ClienteCap2> tr = new TreeSet<ClienteCap2>(clientes); Iterator<ClienteCap2> itc = tr.iterator(); ClienteCap2 proximo = itc.next(); proximo .getMasCercano() .agregarCliente(proximo); // agrego el cliente en el deposito mas cercano. clientes.remove(proximo); Iterator<ClienteCap2> itcli = clientes.iterator(); while (itcli.hasNext()) { ClienteCap2 n = itcli.next(); n.setMu(calcularMu(n, depositos)); } } // agrego a lista si los 2 cliente + cercanos a cada cliente pertencen al mismo deposito // deposito (que no es el mismo que el deposito asignado para el cliente). // acaaaa int capacidadvehiculo = Integer.valueOf(d.getCAPACITY()); System.out.println("cap del vehiculo " + capacidadvehiculo); ArrayList<DTAsignacion> ar = null; int costomenor = 0; Iterator<Deposito> itdd = this.depositos.iterator(); while (itdd.hasNext()) { Deposito dep = itdd.next(); DTAsignacion dta = new DTAsignacion(dep.getNodo()); Iterator<Cliente> itcli = dep.getAsignados().iterator(); while (itcli.hasNext()) { Cliente cli = itcli.next(); dta.agregarCliente(cli.getNodo()); } Iterator<DTRuteo> itrut = Fabrica.getInstancia().getRuteo().rutear(dta, capacidadvehiculo).iterator(); while (itrut.hasNext()) { DTRuteo next = itrut.next(); costomenor = costomenor + next.getCosto(); } } System.out.println("costo inicial " + costomenor); int cantidadIteraciones = 0; // Inicializo el Tiempo en Config Config.getInstancia().empezarAlgoritmo(costomenor); ArrayList<Integer> aux, tmp; tmp = new ArrayList<Integer>(); boolean terminar = false; while (!terminar) { cantidadIteraciones++; System.out.println("Cantidad Iteraciones " + cantidadIteraciones); this.calcularEnagenamiento(); // Aplico todos los cambios de la lista de enajenados .... aux = new ArrayList<Integer>(); Iterator<Enajenado> itena = this.enajenados.iterator(); while (itena.hasNext()) { Enajenado ena = itena.next(); aux.add(ena.getCliente().getNodo().getId()); if (ena.getDepositoDestino().getCapacidadLibrePonderada() >= ena.getCliente().getNodo().getDemanda()) { Iterator<Deposito> respita = this.depositos.iterator(); while (respita.hasNext()) { Deposito dep = respita.next(); Deposito nuevo = new Deposito(dep); if (nuevo.getNodo().getId() == ena.getDeposito().getNodo().getId()) nuevo.sacarCliente(ena.getCliente()); if (nuevo.getNodo().getId() == ena.getDepositoDestino().getNodo().getId()) nuevo.agregarCliente(ena.getCliente()); DTAsignacion dta = new DTAsignacion(nuevo.getNodo()); Iterator<Cliente> itcli = nuevo.getAsignados().iterator(); while (itcli.hasNext()) { Cliente cli = itcli.next(); dta.agregarCliente(cli.getNodo()); } } ena.getDeposito().sacarCliente(ena.getCliente()); ena.getDepositoDestino().agregarCliente(ena.getCliente()); } } boolean equalLists = ((aux.size() == tmp.size()) && (tmp.containsAll(aux))); tmp = new ArrayList<Integer>(); tmp.addAll(aux); if ((Config.getInstancia().terminarPorConfig(cantidadIteraciones, costomenor)) || equalLists) terminar = true; } // construir DT de salida. ar = new ArrayList<DTAsignacion>(); Iterator<Deposito> itd = depositos.iterator(); while (itd.hasNext()) { Deposito dep = itd.next(); DTAsignacion dta = new DTAsignacion(dep.getNodo()); Iterator<Cliente> itcli = dep.getAsignados().iterator(); while (itcli.hasNext()) { Cliente cli = itcli.next(); dta.agregarCliente(cli.getNodo()); } ar.add(dta); } Penalization.getInstancia().getCalculoPenalidad(ar); return ar; }
/** Constructor por defecto. */ private UrgenciasCap2() { // UrgenciasCap2 - Algoritmo = 0 Config.getInstancia().setAlgoritmo(Config.urgenciasCapRapido); }