List of usage examples for java.util LinkedList get
public E get(int index)
From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.Whiteboard.java
private void loadImages() throws Exception { interactiveCanvas = new InteractiveCanvas(); WindowManager.getInstance().setBackgroundControl(interactiveCanvas); interactiveCanvas.setSize(new Size(displayMode.getWidth(), displayMode.getHeight())); interactiveCanvas.setTopLeftPosition(new Point(0.0f, 0.0f)); clearCanvas();//from www. j av a2 s . c o m // pens updatePens(new BasicStroke(5.0f), Color.BLACK); // color buttons int totalButtonsWidth = 0; LinkedList<TexturedControl> buttons = new LinkedList<TexturedControl>(); for (Object[] button : COLOR_BUTTONS) { final Stroke stroke = (Stroke) button[1]; final Color color = (Color) button[2]; TexturedControl texturedControl = new TexturedControl(); texturedControl.setTexture(getClass().getResource((String) button[0])); texturedControl.addTouchListener(new TouchListener() { public void touchEnded(TouchEvent touchEvent) { } public void touchMoved(TouchEvent touchEvent) { } public void touchStarted(TouchEvent touchEvent) { updatePens(stroke, color); } }); buttons.add(texturedControl); totalButtonsWidth += texturedControl.getSize().getWidth(); } int numberOfPaddings = COLOR_BUTTONS.length + 1; int padding = (int) Math.floor(((displayMode.getWidth() - totalButtonsWidth) / (double) numberOfPaddings)); for (int i = 0; i < buttons.size(); i++) { TexturedControl texturedControl = buttons.get(i); texturedControl.setTopLeftPosition( new Point((((i + 1) * padding) + (i * texturedControl.getSize().getWidth())), 15)); } // clear button TexturedControl clearButton = new TexturedControl(); clearButton.setTexture(getClass().getResource(CLEAR_BUTTON)); clearButton.addTouchListener(new TouchListener() { public void touchEnded(TouchEvent touchEvent) { } public void touchMoved(TouchEvent touchEvent) { } public void touchStarted(TouchEvent touchEvent) { clearCanvas(); } }); clearButton.setTopLeftPosition(new Point((displayMode.getWidth() - 10 - clearButton.getSize().getWidth()), (displayMode.getHeight() - 10 - clearButton.getSize().getHeight()))); }
From source file:com.commander4j.thread.AutoLabellerThread.java
public void run() { logger.debug("AutoLabeller Thread running"); setSessionID(JUnique.getUniqueID()); JDBUser user = new JDBUser(getHostID(), getSessionID()); user.setUserId("interface"); user.setPassword("interface"); user.setLoginPassword("interface"); Common.userList.addUser(getSessionID(), user); Common.sd.setData(getSessionID(), "silentExceptions", "Yes", true); Boolean dbconnected = false;//from ww w. j a va 2 s . c o m if (Common.hostList.getHost(hostID).isConnected(sessionID) == false) { dbconnected = Common.hostList.getHost(hostID).connect(sessionID, hostID); } else { dbconnected = true; } if (dbconnected) { JDBViewAutoLabellerPrinter alp = new JDBViewAutoLabellerPrinter(getHostID(), getSessionID()); LinkedList<JDBViewAutoLabellerPrinter> autolabellerList = new LinkedList<JDBViewAutoLabellerPrinter>(); int noOfMessages = 0; while (true) { JWait.milliSec(500); if (allDone) { if (dbconnected) { Common.hostList.getHost(hostID).disconnect(getSessionID()); } return; } autolabellerList.clear(); autolabellerList = alp.getModifiedPrinterLines(); noOfMessages = autolabellerList.size(); if (noOfMessages > 0) { for (int x = 0; x < noOfMessages; x++) { JWait.milliSec(100); JDBViewAutoLabellerPrinter autolabview = autolabellerList.get(x); messageProcessedOK = true; messageError = ""; if (autolabview.getPrinterObj().isEnabled()) { logger.debug("Line =" + autolabview.getAutoLabellerObj().getLine()); logger.debug("Line Description =" + autolabview.getAutoLabellerObj().getDescription()); logger.debug("Printer ID =" + autolabview.getPrinterObj().getPrinterID()); logger.debug("Printer Enabled =" + autolabview.getPrinterObj().isEnabled()); logger.debug("Export Path =" + autolabview.getPrinterObj().getExportRealPath()); logger.debug("Export Enabled =" + autolabview.getPrinterObj().isExportEnabled()); logger.debug("Export Format =" + autolabview.getPrinterObj().getExportFormat()); logger.debug("Direct Print =" + autolabview.getPrinterObj().isDirectPrintEnabled()); logger.debug("Printer Type =" + autolabview.getPrinterObj().getPrinterType()); logger.debug("Printer IP =" + autolabview.getPrinterObj().getIPAddress()); logger.debug("Printer Port =" + autolabview.getPrinterObj().getPort()); logger.debug("Process Order =" + autolabview.getLabelDataObj().getProcessOrder()); logger.debug("Material =" + autolabview.getLabelDataObj().getMaterial()); logger.debug("Module ID =" + autolabview.getModuleObj().getModuleId()); logger.debug("Module Type =" + autolabview.getModuleObj().getType()); if (autolabview.getPrinterObj().isExportEnabled()) { String exportPath = JUtility.replaceNullStringwithBlank( JUtility.formatPath(autolabview.getPrinterObj().getExportRealPath())); if (exportPath.equals("") == false) { if (exportPath.substring(exportPath.length() - 1) .equals(File.separator) == false) { exportPath = exportPath + File.separator; } } else { exportPath = Common.interface_output_path + "Auto Labeller" + File.separator; } String exportFilename = exportPath + JUtility.removePathSeparators(autolabview.getAutoLabellerObj().getLine()) + "_" + JUtility.removePathSeparators(autolabview.getPrinterObj().getPrinterID()) + "." + autolabview.getPrinterObj().getExportFormat(); String exportFilenameTemp = exportFilename + ".out"; logger.debug("Export Filename =" + exportFilename); /* ================CSV================ */ if (autolabview.getPrinterObj().getExportFormat().equals("CSV")) { try { PreparedStatement stmt = null; ResultSet rs; String labelType = autolabview.getLabelDataObj().getLabelType(); stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()) .prepareStatement( Common.hostList.getHost(getHostID()).getSqlstatements() .getSQL("DBVIEW_AUTO_LABELLER_PRINTER.getProperties" + "_" + labelType)); stmt.setString(1, autolabview.getAutoLabellerObj().getLine()); stmt.setString(2, autolabview.getPrinterObj().getPrinterID()); stmt.setFetchSize(50); rs = stmt.executeQuery(); logger.debug("Writing CSV"); CSVWriter writer = new CSVWriter(new FileWriter(exportFilenameTemp), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END); writer.writeAll(rs, true); rs.close(); stmt.close(); writer.close(); File fromFile = new File(exportFilenameTemp); File toFile = new File(exportFilename); FileUtils.deleteQuietly(toFile); FileUtils.moveFile(fromFile, toFile); fromFile = null; toFile = null; } catch (Exception e) { messageProcessedOK = false; messageError = e.getMessage(); } } /* ================XML================ */ if (autolabview.getPrinterObj().getExportFormat().equals("XML")) { try { PreparedStatement stmt = null; ResultSet rs; stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()) .prepareStatement(Common.hostList.getHost(getHostID()) .getSqlstatements() .getSQL("DBVIEW_AUTO_LABELLER_PRINTER.getProperties")); stmt.setString(1, autolabview.getAutoLabellerObj().getLine()); stmt.setString(2, autolabview.getPrinterObj().getPrinterID()); stmt.setFetchSize(50); rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); int colCount = rsmd.getColumnCount(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element message = (Element) document.createElement("message"); Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID()); message.appendChild(hostUniqueID); Element messageRef = addElement(document, "messageRef", autolabview.getAutoLabellerObj().getUniqueID()); message.appendChild(messageRef); Element messageType = addElement(document, "interfaceType", "Auto Labeller Data"); message.appendChild(messageType); Element messageInformation = addElement(document, "messageInformation", "Unique ID=" + autolabview.getAutoLabellerObj().getUniqueID()); message.appendChild(messageInformation); Element messageDirection = addElement(document, "interfaceDirection", "Output"); message.appendChild(messageDirection); Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime())); message.appendChild(messageDate); if (rs.first()) { Element labelData = (Element) document.createElement("LabelData"); Element row = document.createElement("Row"); labelData.appendChild(row); for (int i = 1; i <= colCount; i++) { String columnName = rsmd.getColumnName(i); Object value = rs.getObject(i); Element node = document.createElement(columnName); node.appendChild(document.createTextNode(value.toString())); row.appendChild(node); } message.appendChild(labelData); document.appendChild(message); JXMLDocument xmld = new JXMLDocument(); xmld.setDocument(document); // =============================== DOMImplementationLS DOMiLS = null; FileOutputStream FOS = null; // testing the support for DOM // Load and Save if ((document.getFeature("Core", "3.0") != null) && (document.getFeature("LS", "3.0") != null)) { DOMiLS = (DOMImplementationLS) (document.getImplementation()) .getFeature("LS", "3.0"); // get a LSOutput object LSOutput LSO = DOMiLS.createLSOutput(); FOS = new FileOutputStream(exportFilename); LSO.setByteStream((OutputStream) FOS); // get a LSSerializer object LSSerializer LSS = DOMiLS.createLSSerializer(); // do the serialization LSS.write(document, LSO); FOS.close(); } // =============================== } rs.close(); stmt.close(); } catch (Exception e) { messageError = e.getMessage(); } } if (autolabview.getPrinterObj().getExportFormat().equals("LQF")) { } } if (autolabview.getPrinterObj().isDirectPrintEnabled()) { } } if (messageProcessedOK == true) { autolabview.getAutoLabellerObj().setModified(false); autolabview.getAutoLabellerObj().update(); } else { logger.debug(messageError); } autolabview = null; } } } } }
From source file:com.github.lindenb.jvarkit.tools.misc.BamTile.java
@Override public Collection<Throwable> call(final String inputName) throws Exception { SAMRecordIterator iter = null;/*w ww . j ava 2 s . c om*/ SamReader sfr = null; SAMFileWriter sfw = null; try { sfr = openSamReader(inputName); SAMFileHeader header1 = sfr.getFileHeader(); if (header1 == null) { return wrapException("File header missing"); } if (header1.getSortOrder() != SAMFileHeader.SortOrder.coordinate) { return wrapException("File header not sorted on coordinate"); } SAMFileHeader header2 = header1.clone(); header2.addComment(getName() + ":" + getVersion() + ":" + getProgramCommandLine()); sfw = openSAMFileWriter(header2, true); SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header1); iter = sfr.iterator(); LinkedList<SAMRecord> buffer = new LinkedList<>(); for (;;) { SAMRecord rec = null; if (iter.hasNext()) { rec = progress.watch(iter.next()); if (rec.getReadUnmappedFlag()) continue; if (!buffer.isEmpty()) { SAMRecord last = buffer.getLast(); if (last.getReferenceIndex() == rec.getReferenceIndex() && last.getAlignmentStart() <= rec.getAlignmentStart() && last.getAlignmentEnd() >= rec.getAlignmentEnd()) { continue; } } } if (rec == null || (!buffer.isEmpty() && buffer.getLast().getReferenceIndex() != rec.getReferenceIndex())) { while (!buffer.isEmpty()) { sfw.addAlignment(buffer.removeFirst()); } if (rec == null) break; } buffer.add(rec); if (buffer.size() > 2) { int index = buffer.size(); SAMRecord prev = buffer.get(index - 3); SAMRecord curr = buffer.get(index - 2); SAMRecord next = buffer.get(index - 1); if (prev.getAlignmentEnd() >= next.getAlignmentStart() || curr.getAlignmentEnd() <= prev.getAlignmentEnd()) { buffer.remove(index - 2); } else if (curr.getAlignmentStart() == prev.getAlignmentStart() && curr.getAlignmentEnd() > prev.getAlignmentEnd()) { buffer.remove(index - 3); } } while (buffer.size() > 3) { sfw.addAlignment(buffer.removeFirst()); } } progress.finish(); LOG.info("done"); return Collections.emptyList(); } catch (Exception err) { return wrapException(err); } finally { CloserUtil.close(iter); CloserUtil.close(sfr); CloserUtil.close(sfw); } }
From source file:org.minig.imap.EncodedWord.java
/** * Takes a text in form of a CharSequence encoded in the given charset (e.g. * ISO-8859-1) and makes it US-ASCII compatible and RFC822 compatible for * the use as e.g. subject with special characters. <br> * This algorithm tries to achieve several goals when decoding: <li>never * encode a single character but try to encode whole words</li> <li>if two * words must be encoded and there a no more than 3 characters inbetween, * encode everything in one single encoded word</li> <li>an encoded word * must never be longer than 76 characters in total</li> <li>ensure that no * encodedWord is in a line-wrap (RFC822 advices to no have more than 78 * characters in a headerline)</li> * /* w w w. ja v a2 s . com*/ * @param input * the headerline * @param charset * the used charset (e.g. ISO-8859-1) * @param type * the encoding to be used * @return input encoded in EncodedWords */ public static StringBuilder encode(CharSequence input, Charset charset, int type) { StringBuilder result = new StringBuilder(input.length()); LinkedList<int[]> words = new LinkedList<int[]>(); String encodedWordPrototype; int maxLength; if (type == QUOTED_PRINTABLE) { encodedWordPrototype = "=?" + charset.displayName() + "?q?"; maxLength = 75 - encodedWordPrototype.length() - 2; } else { encodedWordPrototype = "=?" + charset.displayName() + "?b?"; maxLength = 75 - encodedWordPrototype.length() - 6; } // First find words which need to be encoded Matcher matcher = wordTokenizerPattern.matcher(input); float encodedChar = type == QUOTED_PRINTABLE ? 3.0f : 4.0f / 3.0f; float normalChar = type == QUOTED_PRINTABLE ? 1.0f : 4.0f / 3.0f; while (matcher.find()) { String word = matcher.group(1); float encodedLength = 0.0f; int start = matcher.start(); int end = matcher.end(); boolean mustEncode = false; for (int i = 0; i < word.length(); i++) { if (word.charAt(i) > 127) { encodedLength += encodedChar; mustEncode = true; } else { encodedLength += normalChar; } // Split if too long if (Math.ceil(encodedLength) > maxLength) { words.add(new int[] { start, start + i, maxLength }); word = word.substring(i); start += i; i = 0; encodedLength = 0.0f; mustEncode = false; } } if (mustEncode) words.add(new int[] { start, end, (int) Math.ceil(encodedLength) }); } // No need to create encodedWords if (words.isEmpty()) { return result.append(input); } // Second group them together if possible (see goals above) int[] last = null; for (int i = 0; i < words.size(); i++) { int[] act = words.get(i); if (last != null && (last[2] + act[2] + (act[0] - last[1]) * normalChar < maxLength) && (act[0] - last[1]) < 10) { words.remove(i--); last[1] = act[1]; last[2] += act[2] + (act[0] - last[1]) * normalChar; } else { last = act; } } // Create encodedWords Iterator<int[]> it = words.iterator(); int lastWordEnd = 0; while (it.hasNext()) { int[] act = it.next(); // create encoded part CharSequence rawWord = input.subSequence(act[0], act[1]); CharSequence encodedPart; if (type == QUOTED_PRINTABLE) { // Replace <space> with _ Matcher wsMatcher = whitespacePattern.matcher(rawWord); rawWord = wsMatcher.replaceAll("_"); encodedPart = QuotedPrintable.encode(rawWord, charset); } else { encodedPart = Base64.encodeBase64String(charset.encode(CharBuffer.wrap(rawWord)).array()); } result.append(input.subSequence(lastWordEnd, act[0])); result.append(encodedWordPrototype); result.append(encodedPart); result.append("?="); lastWordEnd = act[1]; } result.append(input.subSequence(lastWordEnd, input.length())); return result; }
From source file:fi.ni.IFC_ClassModel.java
/** * Fill java class instance values.//from w w w .ja v a 2 s . co m * * @param name * the name * @param vo * the value object representing the IFC file line * @param level_up_vo * the IFC line pointing to this line * @param level * the iteration count in the recursive run */ private void fillJavaClassInstanceValues(String name, IFC_X3_VO vo, IFC_X3_VO level_up_vo, int level) { EntityVO evo = entities.get(ExpressReader.formatClassName(vo.name)); if (evo == null) System.err.println("Does not exist: " + vo.name); String subject = null; if (vo.getGid() != null) { subject = "gref_" + filter_extras(vo.getGid()); } else { subject = "iref_" + ifc_filename + "_i" + vo.line_num; } // Somebody has pointed here from above: if (vo != level_up_vo) { String level_up_subject; if (level_up_vo.getGid() != null) { level_up_subject = "gref_" + filter_extras(level_up_vo.getGid()); } else { level_up_subject = "iref_" + ifc_filename + "_i" + level_up_vo.line_num; } addLiteralValue(level_up_vo.getLine_num(), vo.getLine_num(), level_up_subject, name); } if (vo.is_touched()) return; int attribute_pointer = 0; for (int i = 0; i < vo.list.size(); i++) { Object o = vo.list.get(i); if (String.class.isInstance(o)) { if (!((String) o).equals("$")) { // Do not print out empty // values' if (types.get(ExpressReader.formatClassName((String) o)) == null) { if ((evo != null) && (evo.getDerived_attribute_list() != null) && (evo.getDerived_attribute_list().size() > attribute_pointer)) { addLiteralValue(vo.getLine_num(), subject, evo.getDerived_attribute_list().get(attribute_pointer).getName(), "\'" + filter_extras((String) o) + "'"); } attribute_pointer++; } } else attribute_pointer++; } else if (IFC_X3_VO.class.isInstance(o)) { if ((evo != null) && (evo.getDerived_attribute_list() != null) && (evo.getDerived_attribute_list().size() > attribute_pointer)) { fillJavaClassInstanceValues(evo.getDerived_attribute_list().get(attribute_pointer).getName(), (IFC_X3_VO) o, vo, level + 1); addIFCAttribute(vo, evo.getDerived_attribute_list().get(attribute_pointer), (IFC_X3_VO) o); } else { fillJavaClassInstanceValues("-", (IFC_X3_VO) o, vo, level + 1); System.out.println("1!" + evo); } attribute_pointer++; } else if (LinkedList.class.isInstance(o)) { @SuppressWarnings("unchecked") LinkedList<Object> tmp_list = (LinkedList<Object>) o; StringBuffer local_txt = new StringBuffer(); for (int j = 0; j < tmp_list.size(); j++) { Object o1 = tmp_list.get(j); if (String.class.isInstance(o1)) { if (j > 0) local_txt.append(", "); local_txt.append(filter_extras((String) o1)); } if (IFC_X3_VO.class.isInstance(o1)) { if ((evo != null) && (evo.getDerived_attribute_list() != null) && (evo.getDerived_attribute_list().size() > attribute_pointer)) { fillJavaClassInstanceValues( evo.getDerived_attribute_list().get(attribute_pointer).getName(), (IFC_X3_VO) o1, vo, level + 1); addIFCAttribute(vo, evo.getDerived_attribute_list().get(attribute_pointer), (IFC_X3_VO) o1); } else { fillJavaClassInstanceValues("-", (IFC_X3_VO) o1, vo, level + 1); System.out.println("2!" + evo); } } } if (local_txt.length() > 0) { if ((evo != null) && (evo.getDerived_attribute_list() != null) && (evo.getDerived_attribute_list().size() > attribute_pointer)) { addLiteralValue(vo.getLine_num(), subject, evo.getDerived_attribute_list().get(attribute_pointer).getName(), "'" + local_txt.toString() + "\'"); } } attribute_pointer++; } } }
From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneSearcherImpl.java
public List<Pair<String, Integer>> getTopTerms(String field, int count) { ClosingIndexSearcher searcher = null; try {//from w w w .j a v a 2 s .c om LinkedList<Pair<String, Integer>> answer = new LinkedList<Pair<String, Integer>>(); searcher = getSearcher(indexer); IndexReader reader = searcher.getIndexReader(); TermEnum terms = reader.terms(new Term(field, "")); do { Term term = terms.term(); if (term != null) { if (!term.field().equals(field)) { break; } int freq = terms.docFreq(); Pair<String, Integer> pair = new Pair<String, Integer>(term.text(), Integer.valueOf(freq)); if (answer.size() < count) { if (answer.size() == 0) { answer.add(pair); } else if (answer.get(answer.size() - 1).getSecond().compareTo(pair.getSecond()) >= 0) { answer.add(pair); } else { for (ListIterator<Pair<String, Integer>> it = answer.listIterator(); it .hasNext(); /**/) { Pair<String, Integer> test = it.next(); if (test.getSecond().compareTo(pair.getSecond()) < 0) { it.previous(); it.add(pair); break; } } } } else if (answer.get(count - 1).getSecond().compareTo(pair.getSecond()) < 0) { for (ListIterator<Pair<String, Integer>> it = answer.listIterator(); it.hasNext(); /**/) { Pair<String, Integer> test = it.next(); if (test.getSecond().compareTo(pair.getSecond()) < 0) { it.previous(); it.add(pair); break; } } answer.removeLast(); } else { // off the end } } } while (terms.next()); terms.close(); return answer; } catch (IOException e) { throw new SearcherException(e); } finally { if (searcher != null) { try { searcher.close(); } catch (IOException e) { throw new SearcherException(e); } } } }
From source file:edu.cmu.tetrad.search.SearchGraphUtils.java
public static Graph bestGuessCycleOrientation(Graph graph, IndependenceTest test) { while (true) { List<Node> cycle = GraphUtils.directedCycle(graph); if (cycle == null) { break; }//from w w w .jav a 2s . c o m LinkedList<Node> _cycle = new LinkedList<Node>(cycle); Node first = _cycle.getFirst(); Node last = _cycle.getLast(); _cycle.addFirst(last); _cycle.addLast(first); int _j = -1; double minP = Double.POSITIVE_INFINITY; for (int j = 1; j < _cycle.size() - 1; j++) { int i = j - 1; int k = j + 1; Node x = test.getVariable(_cycle.get(i).getName()); Node y = test.getVariable(_cycle.get(j).getName()); Node z = test.getVariable(_cycle.get(k).getName()); test.isIndependent(x, z, Collections.singletonList(y)); double p = test.getPValue(); if (p < minP) { _j = j; minP = p; } } Node x = _cycle.get(_j - 1); Node y = _cycle.get(_j); Node z = _cycle.get(_j + 1); graph.removeEdge(x, y); graph.removeEdge(z, y); graph.addDirectedEdge(x, y); graph.addDirectedEdge(z, y); } return graph; }
From source file:org.syndeticlogic.zold.array.FixedLengthArrayScannerTest.java
@Test public void testContents() throws Exception { try {/* w ww . j a v a 2 s.co m*/ pageSystemAssembler = new PageSystemAssembler(PageSystemAssembler.BufferPoolMemoryType.Native, PageSystemAssembler.CachingPolicy.PinnableLru, null); path = Util.prefixToPath("target"); arrays = new FixedLengthArrayScanner[attributeSizes.length]; arrayDescriptors = new ArrayDescriptor[attributeSizes.length]; cardinality = 337; c = new FixedLengthArrayGenerator[attributeSizes.length]; fi = new FileInputStream[attributeSizes.length]; //int pageSize = 4096; int bufferPoolPages = 12800; // 50 MB int workingSetSize = 1048576; LinkedList<String> filenames = new LinkedList<String>(); CompositeKey id = new CompositeKey(); id.append(0); int seed = 31337; for (int i = 0; i < attributeSizes.length; i++) { filenames.add(path + "ArrayTestFile" + i + ArrayDescriptor.ARRAY_DATA_POSTFIX); c[i] = new FixedLengthArrayGenerator( path + "ArrayTestFile" + i + ArrayDescriptor.ARRAY_DATA_POSTFIX, seed, attributeSizes[i], cardinality); c[i].generateFixedLengthArray(); arrayDescriptors[i] = new ArrayDescriptor(path, "Array", "Test", "File" + i, id, attributeSizes[i], cardinality); seed++; fi[i] = new FileInputStream(path + "ArrayTestFile" + i + ArrayDescriptor.ARRAY_DATA_POSTFIX); } PersistentPageManager persistentPageManager = pageSystemAssembler.createPersistantPageManager(filenames, 4096, bufferPoolPages, workingSetSize); for (int i = 0; i < attributeSizes.length; i++) { PageVector pageVector = persistentPageManager.createPageVector(filenames.get(i)); arrays[i] = new FixedLengthArrayScanner(arrayDescriptors[i], pageVector, attributeSizes[i], cardinality); // arrays[i] = new FixedLengthArray(new File(path // + "ArrayTestFile" + i), // ((FixedLengthArrayDescriptor) arrayDescriptors[i]) // .getIndexSize()); c[i].reset(); } for (int i = 0; i < cardinality; i++) { log.debug("Comparing index = " + i); compare(i); } } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:net.semanticmetadata.lire.imageanalysis.bovw.LocalFeatureHistogramBuilderFromCodeBook.java
private HashSet<Integer> selectVocabularyDocs() throws IOException { // need to make sure that this is not running forever ... int loopCount = 0; float maxDocs = reader.maxDoc(); int capacity = (int) Math.min(numDocsForVocabulary, maxDocs); if (capacity < 0) capacity = (int) (maxDocs / 2); HashSet<Integer> result = new HashSet<Integer>(capacity); int tmpDocNumber, tmpIndex; LinkedList<Integer> docCandidates = new LinkedList<Integer>(); // three cases: ///*from ww w. j a v a 2 s. c o m*/ // either it's more or the same number as documents if (numDocsForVocabulary >= maxDocs) { for (int i = 0; i < maxDocs; i++) { result.add(i); } return result; } else if (numDocsForVocabulary >= maxDocs - 100) { // or it's slightly less: for (int i = 0; i < maxDocs; i++) { result.add(i); } while (result.size() > numDocsForVocabulary) { result.remove((int) Math.floor(Math.random() * result.size())); } return result; } else { for (int i = 0; i < maxDocs; i++) { docCandidates.add(i); } for (int r = 0; r < capacity; r++) { boolean worksFine = false; do { tmpIndex = (int) Math.floor(Math.random() * (double) docCandidates.size()); tmpDocNumber = docCandidates.get(tmpIndex); docCandidates.remove(tmpIndex); // check if the selected doc number is valid: not null, not deleted and not already chosen. worksFine = (reader.document(tmpDocNumber) != null) && !result.contains(tmpDocNumber); } while (!worksFine); result.add(tmpDocNumber); // need to make sure that this is not running forever ... if (loopCount++ > capacity * 100) throw new UnsupportedOperationException( "Could not get the documents, maybe there are not enough documents in the index?"); } return result; } }
From source file:org.syndeticlogic.zold.array.FixedLengthArrayScannerTest.java
public void testSpeed() throws Exception { try {//from w w w. j a va 2 s . c o m pageSystemAssembler = new PageSystemAssembler(PageSystemAssembler.BufferPoolMemoryType.Native, PageSystemAssembler.CachingPolicy.PinnableLru, null); path = Util.prefixToPath("target"); arrays = new FixedLengthArrayScanner[attributeSizes.length]; arrayDescriptors = new ArrayDescriptor[attributeSizes.length]; cardinality = 37; c = new FixedLengthArrayGenerator[attributeSizes.length]; //int pageSize = 4096; int bufferPoolPages = 12800; // 50 MB int workingSetSize = 1048576; LinkedList<String> filenames = new LinkedList<String>(); CompositeKey id = new CompositeKey(); id.append(0); int seed = 31337; for (int i = 0; i < attributeSizes.length; i++) { filenames.add(path + "ArrayTestFile" + i + ArrayDescriptor.ARRAY_DATA_POSTFIX); c[i] = new FixedLengthArrayGenerator( path + "ArrayTestFile" + i + ArrayDescriptor.ARRAY_DATA_POSTFIX, seed, attributeSizes[i], cardinality); seed++; c[i].generateFileArray(); arrayDescriptors[i] = new ArrayDescriptor(path, "Array", "Test", "File" + i, id, attributeSizes[i], cardinality); } PersistentPageManager persistentPageManager = pageSystemAssembler.createPersistantPageManager(filenames, 4096, bufferPoolPages, workingSetSize); long total = 0; ArrayList<byte[]> actual = new ArrayList<byte[]>(attributeSizes.length); for (int i = 0; i < attributeSizes.length; i++) { PageVector pageVector = persistentPageManager.createPageVector(filenames.get(i)); arrays[i] = new FixedLengthArrayScanner(arrayDescriptors[i], pageVector, attributeSizes[i], cardinality); // arrays[i] = new FixedLengthArray(new File(path // + "ArrayTestFile" + i), // ((FixedLengthArrayDescriptor) arrayDescriptors[i]) // .getIndexSize()); total += cardinality * attributeSizes[i]; actual.add(new byte[attributeSizes[i]]); } /* * cardinality = 8192; path = Util.prefixToPath("target"); c = new * FixedLengthArrayGenerator[attributeSizes.length]; arrays = new * FixedLengthArray[attributeSizes.length]; arrayDescriptors = new * IArrayDescriptor[attributeSizes.length]; long total = 0; * CompositeKey id = new CompositeKey(); id.append(0); * ArrayList<byte[]> actual = new * ArrayList<byte[]>(attributeSizes.length); for (int i = 0; i < * attributeSizes.length; i++) { c[i] = new * FixedLengthArrayGenerator(path+"ArrayTestFile" + i, 1337, * attributeSizes[i],cardinality); c[i].generateFileArray(); * * arrayDescriptors[i] = new ArrayDescriptor("target", "Array", * "Test", "File" + i, id, attributeSizes[i], cardinality); * arrays[i] = new FixedLengthArray(new * File(path+"ArrayTestFile"+i), attributeSizes[i]); * * } */ long begin = System.nanoTime(); for (int i = 0; i < cardinality; i++) { for (int j = 0; j < attributeSizes.length; j++) { assert arrays[j].nextIndexSize() == attributeSizes[j]; arrays[j].scanNextIndex(actual.get(j), 0); } } long totalNano = System.nanoTime() - begin; long totalSecs = totalNano / 1000000000; float MB = ((float) total) / ((float) 1048576); float MBPerSec = MB / (float) totalSecs; System.out.println("Data in MB = " + MB); System.out.println("Response time in seconds = " + totalSecs); System.out.println("Throughput in MB/s = " + MBPerSec); } catch (Exception e) { throw e; } }