List of usage examples for java.util LinkedList get
public E get(int index)
From source file:net.sourceforge.sqlexplorer.service.SqlexplorerService.java
@Override public Driver getDriver(String driverClassName, String jarsPath) throws InstantiationException, IllegalAccessException, ClassNotFoundException { Driver driver = null;/* w w w . j a va2 s .co m*/ if (StringUtils.isNotEmpty(jarsPath)) { try { driver = this.createGenericJDBC(jarsPath, driverClassName); } catch (Exception e) { log.error(e, e); } return driver; } SQLExplorerPlugin sqlExplorerPlugin = SQLExplorerPlugin.getDefault(); if (sqlExplorerPlugin != null) { net.sourceforge.sqlexplorer.dbproduct.DriverManager driverModel = sqlExplorerPlugin.getDriverModel(); try { Collection<ManagedDriver> drivers = driverModel.getDrivers(); for (ManagedDriver managedDriver : drivers) { LinkedList<String> jars = managedDriver.getJars(); List<URL> urls = new ArrayList<URL>(); for (int i = 0; i < jars.size(); i++) { File file = new File(jars.get(i)); if (file.exists()) { urls.add(file.toURI().toURL()); } } if (!urls.isEmpty()) { try { MyURLClassLoader cl; cl = new MyURLClassLoader(urls.toArray(new URL[0])); Class<?> clazz = cl.findClass(driverClassName); if (clazz != null) { driver = (Driver) clazz.newInstance(); if (driver != null) { return driver; } } } catch (ClassNotFoundException e) { // do nothings } } } } catch (MalformedURLException e) { // do nothings } } if (driver == null) { driver = (Driver) Class.forName(driverClassName).newInstance(); } return driver; }
From source file:nf.frex.android.FrexActivity.java
@Override public void onBackPressed() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean navigateOnBack = preferences.getBoolean("navigate_on_back", false); if (!navigateOnBack) { super.onBackPressed(); return;/*from w w w . j a v a 2 s . com*/ } LinkedList<Region> regionHistory = view.getRegionHistory(); if (regionHistory.size() > 0) { Region region; if (regionHistory.size() == 1) { region = regionHistory.get(0); alert(getString(R.string.first_region_msg)); } else { region = regionHistory.pollLast(); } view.setRegionRecordingDisabled(true); view.regenerateRegion(region); view.setRegionRecordingDisabled(false); } else { alert(getString(R.string.empty_region_history_msg)); } }
From source file:com.mirth.connect.plugins.dashboardstatus.DashboardConnectorEventListener.java
public synchronized LinkedList<String[]> getChannelLog(Object object, String sessionId) { String channelName;// w w w.j a va2 s .co m LinkedList<String[]> channelLog; if (object == null) { /* * object is null - no channel is selected. return the latest entire log entries of all * channels combined. ONLY new entries. */ channelName = "No Channel Selected"; channelLog = entireConnectorInfoLogs; } else { // object is not null - a channel is selected. return the latest // (LOG_SIZE) of that particular channel. channelName = object.toString(); // return only the newly added log entries for the client with // matching sessionId. channelLog = connectorInfoLogs.get(channelName); if (channelLog == null) { channelLog = new LinkedList<String[]>(); connectorInfoLogs.put(channelName, channelLog); } } Map<String, Long> lastDisplayedLogIdByChannel; if (lastDisplayedLogIndexBySessionId.containsKey(sessionId)) { // client exist with the sessionId. lastDisplayedLogIdByChannel = lastDisplayedLogIndexBySessionId.get(sessionId); if (lastDisplayedLogIdByChannel.containsKey(channelName)) { // existing channel on an already open client. // -> only display new log entries. long lastDisplayedLogId = lastDisplayedLogIdByChannel.get(channelName); LinkedList<String[]> newChannelLogEntries = new LinkedList<String[]>(); // FYI, channelLog.size() will never be larger than LOG_SIZE // = 1000. for (String[] aChannelLog : channelLog) { if (lastDisplayedLogId < Long.parseLong(aChannelLog[0])) { newChannelLogEntries.addLast(aChannelLog); } } if (newChannelLogEntries.size() > 0) { /* * put the lastDisplayedLogId into the HashMap. index 0 is the most recent * entry, and index0 of that entry contains the logId. */ lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(newChannelLogEntries.get(0)[0])); lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); } try { return SerializationUtils.clone(newChannelLogEntries); } catch (SerializationException e) { logger.error(e); } } else { /* * new channel viewing on an already open client. -> all log entries are new. * display them all. put the lastDisplayedLogId into the HashMap. index0 is the most * recent entry, and index0 of that entry object contains the logId. */ if (channelLog.size() > 0) { lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(channelLog.get(0)[0])); lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); } try { return SerializationUtils.clone(channelLog); } catch (SerializationException e) { logger.error(e); } } } else { // brand new client. // thus also new channel viewing. // -> all log entries are new. display them all. lastDisplayedLogIdByChannel = new HashMap<String, Long>(); if (channelLog.size() > 0) { lastDisplayedLogIdByChannel.put(channelName, Long.parseLong(channelLog.get(0)[0])); } else { // no log exist at all. put the currentLogId-1, which is the // very latest logId. lastDisplayedLogIdByChannel.put(channelName, logId - 1); } lastDisplayedLogIndexBySessionId.put(sessionId, lastDisplayedLogIdByChannel); try { return SerializationUtils.clone(channelLog); } catch (SerializationException e) { logger.error(e); } } return null; }
From source file:org.testmp.datastore.client.DataStoreClient.java
/** * Save data in data store into specified file with JSON representation * /*from w w w .ja va 2 s.co m*/ * @param filepath * @throws DataStoreClientException */ public void saveDataToFile(String filepath) throws DataStoreClientException { List<Tag> tags = getTags(); HashSet<Integer> idSet = new HashSet<Integer>(); for (Tag tag : tags) { idSet.addAll(tag.getRelatedDataIds()); } LinkedList<Integer> idList = new LinkedList<Integer>(idSet); Collections.sort(idList); int maxDataToGetEachTime = 500, i = 0; PrintWriter writer = null; try { writer = new PrintWriter(filepath, "UTF-8"); writer.print("["); boolean isFirst = true; while (i < idList.size()) { int startId = idList.get(i); i = i + maxDataToGetEachTime - 1; int endId = (i >= idList.size() ? idList.getLast() : idList.get(i)); i++; List<DataInfo<Object>> dataInfoList = getDataByRange(Object.class, startId, endId); for (DataInfo<Object> dataInfo : dataInfoList) { if (!isFirst) { writer.println(","); } else { isFirst = false; } writer.print(dataInfo.toString()); } } writer.println("]"); } catch (Exception e) { throw new DataStoreClientException("Failed to save data to file", e); } finally { if (writer != null) { writer.close(); } } }
From source file:bicat.gui.GraphicPane.java
public void visualizeAll(LinkedList list, float[][] data, int x_table) { // , // int/*from w w w . j av a 2 s . c o m*/ // y_table) // { // create table view of the GraphicPane // for all (B)Cs, visualize it in the next window ... JPanel contentPane = new JPanel(new GridLayout(0, x_table)); try { int row_cnt = 0; int col_cnt = 0; // for (int i = 0; i < list.size(); i++) { // get (b)c, bicat.biclustering.Bicluster bc = (bicat.biclustering.Bicluster) list.get(i); Vector genes = new Vector(); Vector bcData = new Vector(); // for (int g = 0; g < bc.getGenes().length; g++) { genes.add(new Integer(bc.getGenes()[g])); bcData.add(data[bc.getGenes()[g]]); } Vector chips = new Vector(); for (int c = 0; c < bc.getChips().length; c++) chips.add(new Integer(bc.getChips()[c])); // get (corresponding) data setGraphDataList(bcData, genes, chips); // visualize the graph(ik) in the corresponding cell chart = newSimpleGraphic(Double.NaN, false); org.jfree.chart.ChartPanel cP = new org.jfree.chart.ChartPanel(chart); contentPane.add(cP); // old: cP.setPreferredSize(new Dimension(100, 10)); // old: cP.setMaximumDrawHeight(2*xStep); // old: cP.setMaximumDrawWidth(6*xStep); // ... management stuff: col_cnt++; if (col_cnt == 3) { col_cnt = 0; row_cnt++; } } this.removeAll(); this.add(contentPane); this.setVisible(true); } catch (Exception ee) { ee.printStackTrace(); } }
From source file:org.apache.sysml.runtime.controlprogram.parfor.opt.PerfTestTool.java
private static void executeTest() throws DMLRuntimeException, IOException { System.out.println("SystemML PERFORMANCE TEST TOOL:"); //foreach registered instruction for (Entry<Integer, Instruction> inst : _regInst.entrySet()) { int instID = inst.getKey(); System.out.println("Running INSTRUCTION " + _regInst_IDNames.get(instID)); Integer[] testDefIDs = _regInst_IDTestDef.get(instID); boolean vectors = _regInst_IDVectors.get(instID); IOSchema schema = _regInst_IDIOSchema.get(instID); //create tmp program block and set instruction Program prog = new Program(); ProgramBlock pb = new ProgramBlock(prog); ArrayList<Instruction> ainst = new ArrayList<Instruction>(); ainst.add(inst.getValue());/*from w w w . java2s . co m*/ pb.setInstructions(ainst); ExecutionContext ec = ExecutionContextFactory.createContext(); //foreach registered test configuration for (Integer defID : testDefIDs) { PerfTestDef def = _regTestDef.get(defID); TestMeasure m = def.getMeasure(); TestVariable lv = def.getVariable(); DataFormat df = def.getDataformat(); InternalTestVariable[] pv = def.getInternalVariables(); double min = def.getMin(); double max = def.getMax(); double samples = def.getNumSamples(); System.out.println("Running TESTDEF(measure=" + m + ", variable=" + String.valueOf(lv) + " " + pv.length + ", format=" + String.valueOf(df) + ")"); //vary input variable LinkedList<Double> dmeasure = new LinkedList<Double>(); LinkedList<Double> dvariable = generateSequence(min, max, samples); int plen = pv.length; if (plen == 1) //1D function { for (Double var : dvariable) { dmeasure.add(executeTestCase1D(m, pv[0], df, var, pb, vectors, schema, ec)); } } else //multi-dim function { //init index stack int[] index = new int[plen]; for (int i = 0; i < plen; i++) index[i] = 0; //execute test int dlen = dvariable.size(); double[] buff = new double[plen]; while (index[0] < dlen) { //set buffer values for (int i = 0; i < plen; i++) buff[i] = dvariable.get(index[i]); //core execution dmeasure.add(executeTestCaseMD(m, pv, df, buff, pb, schema, ec)); //not applicable for vector flag //increment indexes for (int i = plen - 1; i >= 0; i--) { if (i == plen - 1) index[i]++; else if (index[i + 1] >= dlen) { index[i]++; index[i + 1] = 0; } } } } //append values to results if (!_results.containsKey(instID)) _results.put(instID, new HashMap<Integer, LinkedList<Double>>()); _results.get(instID).put(defID, dmeasure); } } }
From source file:util.method.java
public static LinkedList<String> findRelatedVMID(HashMap VMProperty, LinkedList<VM> VMList) { LinkedList<String> VMIDListFound = new LinkedList<String>(); if (VMProperty.containsKey("ID")) VMIDListFound.add((String) VMProperty.get("ID")); else {//from www.j a v a2s . co m Iterator iter = VMProperty.entrySet().iterator(); while (iter.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iter.next(); String keyInRule = (String) entry.getKey(); String valueInRule = (String) entry.getValue(); for (int i = 0; i < VMList.size(); i++) { VM currentVM = VMList.get(i); String currentVMID = currentVM.getID(); HashMap currentServiceDescription = currentVM.getServiceDescription(); if (currentServiceDescription.containsKey(keyInRule)) { if (currentServiceDescription.get(keyInRule).equals(valueInRule)) { addUnRepeatedValueToList(currentVMID, VMIDListFound); } } } } } return VMIDListFound; }
From source file:org.openmrs.module.chartsearch.solr.ChartSearchSearcher.java
/** * Adds filter Queries to the query for selected categories returned from the UI * /*from www . ja v a 2 s . c o m*/ * @param query * @param selectedCats */ public void addSelectedFilterQueriesToQuery(SolrQuery query, List<String> selectedCats) { String filterQuery = ""; LinkedList<String> selectedCategories = new LinkedList<String>(); selectedCategories.addAll(selectedCats); if (selectedCategories == null || selectedCategories.isEmpty()) { } else { LinkedList<CategoryFilter> existingCategories = new LinkedList<CategoryFilter>(); existingCategories.addAll(getChartSearchService().getAllCategoryFilters()); int indexOfFirstSelected = selectedCategories.indexOf(selectedCategories.getFirst()); int indexOfLastSelected = selectedCategories.indexOf(selectedCategories.getLast()); int indexOfFirstExisting = existingCategories.indexOf(existingCategories.getFirst()); int indexOfLastExisting = existingCategories.indexOf(existingCategories.getLast()); for (int i = indexOfFirstSelected; i <= indexOfLastSelected; i++) { String currentSelected = selectedCategories.get(i); for (int j = indexOfFirstExisting; j <= indexOfLastExisting; j++) { CategoryFilter currentExisting = existingCategories.get(j); String currentExistingName = currentExisting.getCategoryName(); if (currentSelected.equals(currentExistingName.toLowerCase())) { if (i != indexOfLastSelected) { filterQuery += currentExisting.getFilterQuery() + " OR "; } else filterQuery += currentExisting.getFilterQuery(); } } } query.addFilterQuery(filterQuery); } }
From source file:util.method.java
public static LinkedList<String> findRelatedHOSTID(HashMap HOSTProperty, LinkedList<HOST> HOSTList) { LinkedList<String> HOSTIDListFound = new LinkedList<String>(); if (HOSTProperty.containsKey("ID")) HOSTIDListFound.add((String) HOSTProperty.get("ID")); else {//from w ww .jav a 2 s . c o m Iterator iter = HOSTProperty.entrySet().iterator(); while (iter.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iter.next(); String keyInRule = (String) entry.getKey(); String valueInRule = (String) entry.getValue(); for (int i = 0; i < HOSTList.size(); i++) { HOST currentHOST = HOSTList.get(i); String currentHOSTID = currentHOST.getID(); HashMap currentServiceDescription = currentHOST.getServiceDescription(); if (currentServiceDescription.containsKey(keyInRule)) { if (currentServiceDescription.get(keyInRule).equals(valueInRule)) { addUnRepeatedValueToList(currentHOSTID, HOSTIDListFound); } } } } } return HOSTIDListFound; }
From source file:org.eclipse.wb.internal.core.xml.model.description.ComponentDescriptionHelper.java
private static ComponentDescription getDescriptionEx(EditorContext context, Class<?> componentClass) throws Exception { ComponentDescription componentDescription = new ComponentDescription(componentClass); // prepare description resources, from generic to specific LinkedList<ClassResourceInfo> descriptionInfos; {/*w w w . j a va2 s . co m*/ descriptionInfos = Lists.newLinkedList(); DescriptionHelper.addDescriptionResources(descriptionInfos, context.getLoadingContext(), componentClass); Assert.isTrueException(!descriptionInfos.isEmpty(), IExceptionConstants.DESCRIPTION_NO_DESCRIPTIONS, componentClass.getName()); } // prepare Digester Digester digester; { digester = new Digester(); digester.setLogger(new NoOpLog()); addRules(digester, context, componentClass); } // read descriptions from generic to specific for (ClassResourceInfo descriptionInfo : descriptionInfos) { ResourceInfo resourceInfo = descriptionInfo.resource; // read next description { //componentDescription.setCurrentClass(descriptionInfo.clazz); digester.push(componentDescription); // do parse InputStream is = resourceInfo.getURL().openStream(); try { digester.parse(is); } finally { IOUtils.closeQuietly(is); } } // clear parts that can not be inherited if (descriptionInfo.clazz == componentClass) { setDescriptionWithInnerTags(componentDescription, resourceInfo); } else { componentDescription.clearCreations(); componentDescription.setDescription(null); } } // set toolkit if (componentDescription.getToolkit() == null) { for (int i = descriptionInfos.size() - 1; i >= 0; i--) { ClassResourceInfo descriptionInfo = descriptionInfos.get(i); ToolkitDescription toolkit = descriptionInfo.resource.getToolkit(); if (toolkit != null) { componentDescription.setToolkit(toolkit); break; } } } // mark for caching presentation if (shouldCachePresentation(descriptionInfos.getLast(), componentClass)) { componentDescription.setPresentationCached(true); } // final operations setIcon(context, componentDescription, componentClass); useDescriptionProcessors(context, componentDescription); componentDescription.postProcess(); // done return componentDescription; }