List of usage examples for java.util ArrayList get
public E get(int index)
From source file:mt.LengthDistribution.java
public static ArrayList<Pair<Integer, Double>> LengthdistroatTime(File file, final int framenumber) { ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file); ArrayList<Pair<Integer, Double>> lengthlist = new ArrayList<Pair<Integer, Double>>(); if (currentobject != null) { for (int index = 0; index < currentobject.size(); ++index) { if (currentobject.get(index).Framenumber == framenumber) { lengthlist.add(new ValuePair<Integer, Double>(currentobject.get(index).seedID, currentobject.get(index).length)); }/*w ww .j av a2 s. c om*/ } } return lengthlist; }
From source file:Main.java
public static byte[] encodeData(byte[] data) { // use arraylists because byte[] is annoying. ArrayList<Byte> inData = fromBytes(data); ArrayList<Byte> outData = new ArrayList<>(); /*//from w ww. j a v a2s .co m ArrayList<Byte> dataPlusCrc = fromBytes(OtherCRC.appendCRC(data)); ArrayList<Byte> dataPlusMyCrc = fromBytes(data); */ //dataPlusMyCrc.add(CRC.crc8(data)); final byte[] codes = new byte[] { 21, 49, 50, 35, 52, 37, 38, 22, 26, 25, 42, 11, 44, 13, 14, 28 }; int acc = 0; int bitcount = 0; int i; for (i = 0; i < inData.size(); i++) { acc <<= 6; acc |= codes[(inData.get(i) >> 4) & 0x0f]; bitcount += 6; acc <<= 6; acc |= codes[inData.get(i) & 0x0f]; bitcount += 6; while (bitcount >= 8) { byte outByte = (byte) (acc >> (bitcount - 8) & 0xff); outData.add(outByte); bitcount -= 8; acc &= (0xffff >> (16 - bitcount)); } } if (bitcount > 0) { acc <<= (8 - bitcount); byte outByte = (byte) (acc & 0xff); outData.add(outByte); } // convert back to byte[] byte[] rval = toBytes(outData); Log.e(TAG, "encodeData: (length " + data.length + ") input is " + toHexString(data)); Log.e(TAG, "encodeData: (length " + rval.length + ") output is " + toHexString(rval)); return rval; }
From source file:biomine.nodeimportancecompression.ImportanceCompressionReport.java
public static Map<String, Double> readMap(BufferedReader read) throws IOException { ArrayList<String> lines = new ArrayList<String>(); String line;/* w w w . j a v a 2 s .c o m*/ while ((line = read.readLine()) != null) { lines.add(line); } HashMap<String, Double> ret = new HashMap<String, Double>(); for (int i = 0; i < lines.size(); i++) { line = lines.get(i); String[] s = line.split("[,\\s]+"); String id = null; double d = 1; if (s.length == 0) { } else if (s.length == 1) { id = s[0]; } else if (s.length == 2) { id = s[0]; d = Double.parseDouble(s[1]); } else if (s.length > 2) { System.out.println("Error parsing queryfile: Too much whitespace:" + line); System.exit(1); } if (id != null && id.length() == 0) id = null; if (id != null) ret.put(id, d); } return ret; }
From source file:gr.demokritos.iit.cru.creativity.reasoning.semantic.WebMiner.java
public static String WebMiner(String seed, int difficulty, String language, boolean compactForm) throws ClassNotFoundException, SQLException, IOException, InstantiationException, IllegalAccessException {//from www.ja v a 2 s .c o m Gson gson = new Gson(); Connect c = new Connect(language); RandomWordGenerator r = new RandomWordGenerator(c); String randomPhrase = r.selectRandomWord(seed, difficulty).replace(",", " "); InfoSummarization inf = new InfoSummarization(c); LinkedHashMap<String, Double> TagCloud = new LinkedHashMap<String, Double>(); Set<String> pages = new HashSet<String>(); ArrayList<String> urls = new ArrayList<String>(); ArrayList<String> urls_temp = new ArrayList<String>(); if (language.equalsIgnoreCase("en")) { if (randomPhrase.length() == 0) { randomPhrase = seed; } String bingAppId = c.getBingAppId(); BingCrawler bc = new BingCrawler(bingAppId, language); urls_temp = bc.crawl(randomPhrase); int url_loop = 0; while ((url_loop < 5) && (url_loop < urls_temp.size())) { urls.add(urls_temp.get(url_loop)); url_loop++; } } else if (language.equalsIgnoreCase("el")) { String bingAppId = c.getBingAppId(); BingCrawler bc = new BingCrawler(bingAppId, language); urls_temp = bc.crawl(randomPhrase); int url_loop = 0; while ((url_loop < 5) && (url_loop < urls_temp.size())) { urls.add(urls_temp.get(url_loop)); url_loop++; } } else if (language.equalsIgnoreCase("de")) {//keep only the first word of the random phrase for search if (randomPhrase.length() == 0) { randomPhrase = seed; } urls_temp = HTMLUtilities.linkExtractor( "http://www.fragfinn.de/kinderliste/suche?start=0&query=" + randomPhrase.split(" ")[0], "UTF-8", 0); for (String url : urls_temp) { urls.add(StringEscapeUtils.unescapeHtml4(url)); if (urls.size() == 5) { break; } } } String delims = "[{} .,;?!():\"]+"; String[] words = randomPhrase.split(","); String[] user_keywords = seed.split(delims); if (urls.size() > 0) { ExecutorService threadPool = Executors.newFixedThreadPool(urls.size()); for (String url : urls) { threadPool.submit(new HTMLPages(url, pages, language)); //stopWordSet, tokensHashMap,language)); // threadPool.submit(HTMLTokenizer()); } threadPool.shutdown(); while (!threadPool.isTerminated()) { } LinkedHashMap<ArrayList<String>, Double> temp = inf.TopTermsBing(pages, compactForm); HashMap<String, Double> temp2 = new HashMap<String, Double>(); for (ArrayList<String> stems : temp.keySet()) { for (int j = 0; j < stems.size(); j++) { String s = stems.get(j).split("\\{")[0]; s = s.replace(",", " "); s = s.trim(); boolean wordnet = true; //if term is not one of the initial random phrase for (int i = 0; i < words.length; i++) { if (s.equalsIgnoreCase(words[i])) { wordnet = false; } } //and if it 's not in the initial words of user for (int i = 0; i < user_keywords.length; i++) { if (s.equalsIgnoreCase(user_keywords[i])) { wordnet = false; } } //in german or greek, ignore english words from search english words if (language.equalsIgnoreCase("de") || language.equalsIgnoreCase("el")) { if (c.getWn().getCommonPos(s) != null) { continue; } } //return it with its stem's weight if (wordnet) { //for every stem, put each of its corresponding terms to tagCloud with the stem's tf temp2.put(stems.get(j), temp.get(stems)); } } } TagCloud = inf.sortHashMapByValues(temp2); threadPool.shutdownNow(); } String json = gson.toJson(TagCloud); c.CloseConnection(); return json; }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void registrarUsuarioConvocatoria(HttpServletRequest request, HttpServletResponse response) throws IOException { /*Enumeration<String> parameterNames = request.getParameterNames(); String param;/* w w w .ja v a 2 s . com*/ while(parameterNames.hasMoreElements()){ param = parameterNames.nextElement(); System.out.print(param); System.out.print(": "); System.out.print(request.getParameter(param)); }*/ ArrayList r = CtrlUsuario.registrarAConvocatoriaUsuario(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // parameter 1: idUsuario param2: idConv response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (r.get(0) == "error") { JSONObject obj = new JSONObject(); obj.put("isError", true); obj.put("errorDescrip", r.get(1)); out.print(obj); } else if (r.get(0) == "isExitoso") { JSONObject obj = new JSONObject(); obj.put("Exitoso", true); out.print(obj); } else { Util.errordeRespuesta(r, out); } }
From source file:org.wso2.carbon.core.transports.util.XsdUtil.java
public static void printXsd(CarbonHttpRequest request, CarbonHttpResponse response, ConfigurationContext configCtx, String serviceName, AxisService axisService) throws IOException { if (GhostDeployerUtils.isGhostService(axisService)) { // if the existing service is a ghost service, deploy the actual one axisService = GhostDeployerUtils.deployActualService(configCtx.getAxisConfiguration(), axisService); }// www.j a v a 2 s .c om if (!RequestProcessorUtil.canExposeServiceMetadata(axisService)) { response.setError(HttpStatus.SC_FORBIDDEN, "Access to service metadata for service: " + serviceName + " has been forbidden"); return; } OutputStream outputStream = response.getOutputStream(); String contextRoot = request.getContextPath(); if (axisService == null) { response.addHeader(HTTP.CONTENT_TYPE, "text/html"); response.setError(HttpStatus.SC_NOT_FOUND); outputStream.write( ("<h4>Service " + serviceName + " is not found. Cannot display Schema.</h4>").getBytes()); outputStream.flush(); return; } if (!axisService.isActive()) { response.addHeader(HTTP.CONTENT_TYPE, "text/html"); outputStream .write(("<h4>Service " + serviceName + " is inactive. Cannot display Schema.</h4>").getBytes()); outputStream.flush(); return; } //cater for named xsds - check for the xsd name String uri = request.getQueryString(); if (request.getQueryString().endsWith(".xsd")) { String schemaName = uri.substring(uri.lastIndexOf('=') + 1); Map services = configCtx.getAxisConfiguration().getServices(); AxisService service = (AxisService) services.get(serviceName); if (service != null) { //run the population logic just to be sure service.populateSchemaMappings(); //write out the correct schema Map schemaTable = service.getSchemaMappingTable(); XmlSchema schema = (XmlSchema) schemaTable.get(schemaName); if (schema == null) { int slashIndex = schemaName.lastIndexOf('/'); int dotIndex = schemaName.lastIndexOf('.'); if (slashIndex > 0) { String schemaKey = schemaName.substring(slashIndex + 1, dotIndex); schema = (XmlSchema) schemaTable.get(schemaKey); } } if (schema == null) { int dotIndex = schemaName.indexOf('.'); if (dotIndex > 0) { String schemaKey = schemaName.substring(0, dotIndex); schema = (XmlSchema) schemaTable.get(schemaKey); } } //schema found - write it to the stream if (schema != null) { response.setStatus(HttpStatus.SC_OK); response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); schema.write(response.getOutputStream()); return; } else { InputStream instream = service.getClassLoader() .getResourceAsStream(DeploymentConstants.META_INF + "/" + schemaName); if (instream != null) { response.setStatus(HttpStatus.SC_OK); response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); OutputStream outstream = response.getOutputStream(); boolean checkLength = true; int length = Integer.MAX_VALUE; int nextValue = instream.read(); if (checkLength) { length--; } while (-1 != nextValue && length >= 0) { outstream.write(nextValue); nextValue = instream.read(); if (checkLength) { length--; } } outstream.flush(); return; } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int ret = service.printXSD(baos, schemaName); if (ret > 0) { baos.flush(); instream = new ByteArrayInputStream(baos.toByteArray()); response.setStatus(HttpStatus.SC_OK); response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); OutputStream outstream = response.getOutputStream(); boolean checkLength = true; int length = Integer.MAX_VALUE; int nextValue = instream.read(); if (checkLength) { length--; } while (-1 != nextValue && length >= 0) { outstream.write(nextValue); nextValue = instream.read(); if (checkLength) { length--; } } outstream.flush(); return; } } } } } axisService.populateSchemaMappings(); Map schemaMappingtable = axisService.getSchemaMappingTable(); String xsds = request.getParameter("xsd"); if (xsds != null && xsds.trim().length() != 0) { response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); XmlSchema schema = (XmlSchema) schemaMappingtable.get(xsds); if (schema == null) { int dotIndex = xsds.indexOf('.'); if (dotIndex > 0) { String schemaKey = xsds.substring(0, dotIndex); schema = (XmlSchema) schemaMappingtable.get(schemaKey); } } if (schema != null) { //schema is there - pump it outs schema.write(new OutputStreamWriter(outputStream, "UTF8")); outputStream.flush(); outputStream.close(); } else if (xsds.endsWith(".xsd") && xsds.indexOf("..") == -1) { InputStream in = axisService.getClassLoader() .getResourceAsStream(DeploymentConstants.META_INF + "/" + xsds); if (in != null) { outputStream.write(IOUtils.getStreamAsByteArray(in)); outputStream.flush(); outputStream.close(); } else { response.setError(HttpServletResponse.SC_NOT_FOUND); } } else { String msg = "Invalid schema " + xsds + " requested"; throw new IOException(msg); } return; } ArrayList schemas = axisService.getSchema(); if (schemas.size() == 1) { response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); // Write to the output stream processSchema((XmlSchema) schemas.get(0), outputStream, contextRoot, request); } else { String idParam = request.getParameter("id"); if (idParam != null) { XmlSchema schema = axisService.getSchema(Integer.parseInt(idParam)); if (schema != null) { response.addHeader(HTTP.CONTENT_TYPE, "text/xml"); processSchema(schema, outputStream, contextRoot, request); } else { response.addHeader(HTTP.CONTENT_TYPE, "text/html"); outputStream.write("<h4>Schema not found!</h4>".getBytes()); } } else { /*String ipAddress = "http://" + NetworkUtils.getLocalHostname() + ":" + ServerManager.getInstance().getHttpPort(); String version = ServerConfiguration.getInstance().getFirstProperty("Version"); outputStream.write(("<html><head>" + "<title>WSO2 Web Services Application Server v" + version + "Management Console" + " - " + axisService.getName() + " Service Schema</title>" + "</head>" + "<body>" + "<b>Schemas for " + axisService.getName() + " service</b><br/><br/>").getBytes()); if (schemas.size() != 0) { for (int i = 0; i < schemas.size(); i++) { String st = "<a href=\"" + ipAddress + RequestProcessorUtil.getServiceContextPath(configCtx) + "/" + axisService.getName() + "?xsd&id=" + i + "&" + ServerConstants.HTTPConstants.ANNOTATION + "=true" + "\">Schema " + i + "</a><br/>"; outputStream.write(st.getBytes()); } } else { outputStream.write("<p>No schemas found</p>".getBytes()); } outputStream.write("</body></html>".getBytes());*/ } } }
From source file:com.cisco.oss.foundation.message.HornetQMessagingFactory.java
private static void printHQVersion(final Map<String, Map<String, String>> serverConnections, final ArrayList<String> serverConnectionKeys) { if (serverConnectionKeys != null && !serverConnectionKeys.isEmpty()) { String host = serverConnections.get(serverConnectionKeys.get(0)).get("host"); String port = serverConnections.get(serverConnectionKeys.get(0)).get("jmxPort"); if (port == null) { port = "3900"; }//from ww w .j av a 2 s . c o m printHQVersion(host, port); } }
From source file:com.teamsun.framework.util.ConvertUtil.java
/** * ??LIST??LIST VO???/*from w w w. jav a 2 s . com*/ * * @param src * @param dest * @return * @throws ConvertException * @throws IllegalAccessException * @throws InvocationTargetException * @throws InstantiationException * @throws NoSuchMethodException */ public static List convertListToObjctList(ArrayList src, Object dest) { if (src == null || src.size() < 1) return null; BeanUtilsBean ub = new BeanUtilsBean(); List result = new ArrayList(); try { for (int i = 0; i < src.size(); i++) { Map obj = (Map) src.get(i); Iterator names = obj.keySet().iterator(); while (names.hasNext()) { String name = (String) names.next(); String reName = dealField(name); Object value = obj.get(name); ub.copyProperty(dest, reName, value); } Object clone = BeanUtils.cloneBean(dest); result.add(clone); } } catch (Exception e) { throw new ConvertException("convertListToObjctList?", e); } return result; }
From source file:com.qwazr.server.configuration.ServerConfiguration.java
private static String findListenAddress(final String addressPattern) { if (StringUtils.isEmpty(addressPattern)) return DEFAULT_LISTEN_ADDRESS; try {/*from www . ja v a 2 s. com*/ final ArrayList<String> list = new ArrayList<>(); findMatchingAddress(addressPattern, list); return list.isEmpty() ? DEFAULT_LISTEN_ADDRESS : list.get(0); } catch (SocketException e) { LOGGER.log(Level.WARNING, e, () -> "Failed in extracting IP informations. Listen address set to default (" + DEFAULT_LISTEN_ADDRESS + ")"); return DEFAULT_LISTEN_ADDRESS; } }
From source file:fr.paris.lutece.plugins.workflow.modules.notifygru.service.ServiceConfigTaskForm.java
/** * display the error message.//from ww w.j a v a 2 s . co m * * @param errors the list of errors * @param request the http request * @return the error message */ public static String displayErrorMessage(ArrayList<String> errors, HttpServletRequest request) { Object[] tabRequiredFields = new Object[errors.size()]; for (int i = 0; i < errors.size(); i++) { tabRequiredFields[i] = errors.get(i); } if (tabRequiredFields.length > 2) { return AdminMessageService.getMessageUrl(request, Constants.MESSAGE_MANDATORY_THREE_FIELD, tabRequiredFields, AdminMessage.TYPE_WARNING); } else if (tabRequiredFields.length == 2) { return AdminMessageService.getMessageUrl(request, Constants.MESSAGE_MANDATORY_TWO_FIELD, tabRequiredFields, AdminMessage.TYPE_WARNING); } return AdminMessageService.getMessageUrl(request, Constants.MESSAGE_MANDATORY_ONE_FIELD, tabRequiredFields, AdminMessage.TYPE_WARNING); }