List of usage examples for java.util BitSet get
public boolean get(int bitIndex)
From source file:org.apache.hadoop.mapreduce.lib.input.TestCombineTextInputFormat.java
@Test(timeout = 10000) public void testFormat() throws Exception { Job job = Job.getInstance(new Configuration(defaultConf)); Random random = new Random(); long seed = random.nextLong(); LOG.info("seed = " + seed); random.setSeed(seed);/*from www. j a v a 2s. c o m*/ localFs.delete(workDir, true); FileInputFormat.setInputPaths(job, workDir); final int length = 10000; final int numFiles = 10; // create files with various lengths createFiles(length, numFiles, random); // create a combined split for the files CombineTextInputFormat format = new CombineTextInputFormat(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(length / 20) + 1; LOG.info("splitting: requesting = " + numSplits); List<InputSplit> splits = format.getSplits(job); LOG.info("splitting: got = " + splits.size()); // we should have a single split as the length is comfortably smaller than // the block size assertEquals("We got more than one splits!", 1, splits.size()); InputSplit split = splits.get(0); assertEquals("It should be CombineFileSplit", CombineFileSplit.class, split.getClass()); // check the split BitSet bits = new BitSet(length); LOG.debug("split= " + split); TaskAttemptContext context = MapReduceTestUtil.createDummyMapTaskAttemptContext(job.getConfiguration()); RecordReader<LongWritable, Text> reader = format.createRecordReader(split, context); assertEquals("reader class is CombineFileRecordReader.", CombineFileRecordReader.class, reader.getClass()); MapContext<LongWritable, Text, LongWritable, Text> mcontext = new MapContextImpl<LongWritable, Text, LongWritable, Text>( job.getConfiguration(), context.getTaskAttemptID(), reader, null, null, MapReduceTestUtil.createDummyReporter(), split); reader.initialize(split, mcontext); try { int count = 0; while (reader.nextKeyValue()) { LongWritable key = reader.getCurrentKey(); assertNotNull("Key should not be null.", key); Text value = reader.getCurrentValue(); final int v = Integer.parseInt(value.toString()); LOG.debug("read " + v); assertFalse("Key in multiple partitions.", bits.get(v)); bits.set(v); count++; } LOG.debug("split=" + split + " count=" + count); } finally { reader.close(); } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }
From source file:srebrinb.compress.sevenzip.SevenZFile.java
private void readFilesInfo(final ByteBuffer header, final Archive archive) throws IOException { final long numFiles = readUint64(header); final SevenZArchiveEntry[] files = new SevenZArchiveEntry[(int) numFiles]; for (int i = 0; i < files.length; i++) { files[i] = new SevenZArchiveEntry(); }//from w w w. ja va 2s . co m BitSet isEmptyStream = null; BitSet isEmptyFile = null; BitSet isAnti = null; while (true) { final int propertyType = getUnsignedByte(header); if (propertyType == 0) { break; } final long size = readUint64(header); switch (propertyType) { case NID.kEmptyStream: { isEmptyStream = readBits(header, files.length); break; } case NID.kEmptyFile: { if (isEmptyStream == null) { // protect against NPE throw new IOException("Header format error: kEmptyStream must appear before kEmptyFile"); } isEmptyFile = readBits(header, isEmptyStream.cardinality()); break; } case NID.kAnti: { if (isEmptyStream == null) { // protect against NPE throw new IOException("Header format error: kEmptyStream must appear before kAnti"); } isAnti = readBits(header, isEmptyStream.cardinality()); break; } case NID.kName: { final int external = getUnsignedByte(header); if (external != 0) { throw new IOException("Not implemented"); } if (((size - 1) & 1) != 0) { throw new IOException("File names length invalid"); } final byte[] names = new byte[(int) (size - 1)]; header.get(names); int nextFile = 0; int nextName = 0; for (int i = 0; i < names.length; i += 2) { if (names[i] == 0 && names[i + 1] == 0) { files[nextFile++].setName(new String(names, nextName, i - nextName, CharsetNames.UTF_16LE)); nextName = i + 2; } } if (nextName != names.length || nextFile != files.length) { throw new IOException("Error parsing file names"); } break; } case NID.kCTime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = getUnsignedByte(header); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasCreationDate(timesDefined.get(i)); if (files[i].getHasCreationDate()) { files[i].setCreationDate(header.getLong()); } } break; } case NID.kATime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = getUnsignedByte(header); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasAccessDate(timesDefined.get(i)); if (files[i].getHasAccessDate()) { files[i].setAccessDate(header.getLong()); } } break; } case NID.kMTime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = getUnsignedByte(header); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasLastModifiedDate(timesDefined.get(i)); if (files[i].getHasLastModifiedDate()) { files[i].setLastModifiedDate(header.getLong()); } } break; } case NID.kWinAttributes: { final BitSet attributesDefined = readAllOrBits(header, files.length); final int external = getUnsignedByte(header); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasWindowsAttributes(attributesDefined.get(i)); if (files[i].getHasWindowsAttributes()) { files[i].setWindowsAttributes(header.getInt()); } } break; } case NID.kStartPos: { throw new IOException("kStartPos is unsupported, please report"); } case NID.kDummy: { // 7z 9.20 asserts the content is all zeros and ignores the property // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287 if (skipBytesFully(header, size) < size) { throw new IOException("Incomplete kDummy property"); } break; } default: { // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287 if (skipBytesFully(header, size) < size) { throw new IOException("Incomplete property of type " + propertyType); } break; } } } int nonEmptyFileCounter = 0; int emptyFileCounter = 0; for (int i = 0; i < files.length; i++) { files[i].setHasStream(isEmptyStream == null ? true : !isEmptyStream.get(i)); if (files[i].hasStream()) { files[i].setDirectory(false); files[i].setAntiItem(false); files[i].setHasCrc(archive.subStreamsInfo.hasCrc.get(nonEmptyFileCounter)); files[i].setCrcValue(archive.subStreamsInfo.crcs[nonEmptyFileCounter]); files[i].setSize(archive.subStreamsInfo.unpackSizes[nonEmptyFileCounter]); ++nonEmptyFileCounter; } else { files[i].setDirectory(isEmptyFile == null ? true : !isEmptyFile.get(emptyFileCounter)); files[i].setAntiItem(isAnti == null ? false : isAnti.get(emptyFileCounter)); files[i].setHasCrc(false); files[i].setSize(0); ++emptyFileCounter; } } archive.files = files; calculateStreamMap(archive); }
From source file:edu.oregonstate.eecs.mcplan.util.Fn.java
/** * Convert a BitSet to a string in which each character represents * 'block_size' consecutive bits.//from w ww . ja v a 2 s . c o m * @param bits * @param block_size Min 1, max 5 * @return */ public static String toDigits(final BitSet bits, final int block_size) { assert (block_size >= 1); assert (block_size <= 5); final int radix = 1 << block_size; final StringBuffer sb = new StringBuffer(); for (int i = 0; i < bits.length(); i += block_size) { int c = 0; for (int j = 0; j < block_size; ++j) { c |= (bits.get(i + j) ? 1 : 0) << j; } sb.append(Character.forDigit(c, radix)); } return sb.reverse().toString(); }
From source file:bobs.is.compress.sevenzip.SevenZFile.java
private void readFilesInfo(final DataInput header, final Archive archive) throws IOException { final long numFiles = readUint64(header); final SevenZArchiveEntry[] files = new SevenZArchiveEntry[(int) numFiles]; for (int i = 0; i < files.length; i++) { files[i] = new SevenZArchiveEntry(); }//from w w w. ja v a 2s . co m BitSet isEmptyStream = null; BitSet isEmptyFile = null; BitSet isAnti = null; while (true) { final int propertyType = header.readUnsignedByte(); if (propertyType == 0) { break; } final long size = readUint64(header); switch (propertyType) { case NID.kEmptyStream: { isEmptyStream = readBits(header, files.length); break; } case NID.kEmptyFile: { if (isEmptyStream == null) { // protect against NPE throw new IOException("Header format error: kEmptyStream must appear before kEmptyFile"); } isEmptyFile = readBits(header, isEmptyStream.cardinality()); break; } case NID.kAnti: { if (isEmptyStream == null) { // protect against NPE throw new IOException("Header format error: kEmptyStream must appear before kAnti"); } isAnti = readBits(header, isEmptyStream.cardinality()); break; } case NID.kName: { final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Not implemented"); } if (((size - 1) & 1) != 0) { throw new IOException("File names length invalid"); } final byte[] names = new byte[(int) (size - 1)]; header.readFully(names); int nextFile = 0; int nextName = 0; for (int i = 0; i < names.length; i += 2) { if (names[i] == 0 && names[i + 1] == 0) { files[nextFile].setName(new String(names, nextName, i - nextName, CharsetNames.UTF_16LE)); nextName = i + 2; this.mapFilename.put(files[nextFile].getName(), nextFile); nextFile++; } } if (nextName != names.length || nextFile != files.length) { throw new IOException("Error parsing file names"); } break; } case NID.kCTime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasCreationDate(timesDefined.get(i)); if (files[i].getHasCreationDate()) { files[i].setCreationDate(Long.reverseBytes(header.readLong())); } } break; } case NID.kATime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasAccessDate(timesDefined.get(i)); if (files[i].getHasAccessDate()) { files[i].setAccessDate(Long.reverseBytes(header.readLong())); } } break; } case NID.kMTime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasLastModifiedDate(timesDefined.get(i)); if (files[i].getHasLastModifiedDate()) { files[i].setLastModifiedDate(Long.reverseBytes(header.readLong())); } } break; } case NID.kWinAttributes: { final BitSet attributesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasWindowsAttributes(attributesDefined.get(i)); if (files[i].getHasWindowsAttributes()) { files[i].setWindowsAttributes(Integer.reverseBytes(header.readInt())); } } break; } case NID.kStartPos: { throw new IOException("kStartPos is unsupported, please report"); } case NID.kDummy: { // 7z 9.20 asserts the content is all zeros and ignores the property // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287 if (skipBytesFully(header, size) < size) { throw new IOException("Incomplete kDummy property"); } break; } default: { // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287 if (skipBytesFully(header, size) < size) { throw new IOException("Incomplete property of type " + propertyType); } break; } } } int nonEmptyFileCounter = 0; int emptyFileCounter = 0; for (int i = 0; i < files.length; i++) { files[i].setHasStream(isEmptyStream == null ? true : !isEmptyStream.get(i)); if (files[i].hasStream()) { files[i].setDirectory(false); files[i].setAntiItem(false); files[i].setHasCrc(archive.subStreamsInfo.hasCrc.get(nonEmptyFileCounter)); files[i].setCrcValue(archive.subStreamsInfo.crcs[nonEmptyFileCounter]); files[i].setSize(archive.subStreamsInfo.unpackSizes[nonEmptyFileCounter]); ++nonEmptyFileCounter; } else { files[i].setDirectory(isEmptyFile == null ? true : !isEmptyFile.get(emptyFileCounter)); files[i].setAntiItem(isAnti == null ? false : isAnti.get(emptyFileCounter)); files[i].setHasCrc(false); files[i].setSize(0); ++emptyFileCounter; } } archive.files = files; calculateStreamMap(archive); }
From source file:org.zkoss.poi.ss.format.CellNumberFormatter.java
/** {@inheritDoc} */ public void formatValue(StringBuffer toAppendTo, Object valueObject) { double value = ((Number) valueObject).doubleValue(); value *= scale;/*from www .j av a 2 s. c o m*/ // For negative numbers: // - If the cell format has a negative number format, this method // is called with a positive value and the number format has // the negative formatting required, e.g. minus sign or brackets. // - If the cell format does not have a negative number format, // this method is called with a negative value and the number is // formatted with a minus sign at the start. boolean negative = value < 0; if (negative) value = -value; // Split out the fractional part if we need to print a fraction double fractional = 0; if (slash != null) { if (improperFraction) { fractional = value; value = 0; } else { fractional = value % 1.0; //noinspection SillyAssignment value = (long) value; } } Set<StringMod> mods = new TreeSet<StringMod>(); StringBuffer output = new StringBuffer(desc); if (exponent != null) { writeScientific(value, output, mods); } else if (improperFraction) { writeFraction(value, null, fractional, output, mods); } else { StringBuffer result = new StringBuffer(); Formatter f = new Formatter(result, locale); //ZSS-68 f.format(locale, printfFmt, value); //ZSS-68 if (numerator == null) { writeFractional(result, output); writeInteger(result, output, integerSpecials, mods, integerCommas, false); } else { writeFraction(value, result, fractional, output, mods); } } // Now strip out any remaining '#'s and add any pending text ... ListIterator<Special> it = specials.listIterator(); Iterator<StringMod> changes = mods.iterator(); StringMod nextChange = (changes.hasNext() ? changes.next() : null); int adjust = 0; BitSet deletedChars = new BitSet(); // records chars already deleted final String groupSeparator = "" + Formatters.getGroupingSeparator(locale); //ZSS-68 while (it.hasNext()) { Special s = it.next(); int adjustedPos = s.pos + adjust; if (!deletedChars.get(s.pos) && output.charAt(adjustedPos) == '#') { output.deleteCharAt(adjustedPos); adjust--; deletedChars.set(s.pos); } while (nextChange != null && s == nextChange.special) { int lenBefore = output.length(); int modPos = s.pos + adjust; int posTweak = 0; switch (nextChange.op) { case StringMod.AFTER: // ignore adding a comma after a deleted char (which was a '#') if (nextChange.toAdd.equals(groupSeparator) && deletedChars.get(s.pos)) //20110321, henrichen@zkoss.org: respect current locale break; posTweak = 1; //noinspection fallthrough case StringMod.BEFORE: output.insert(modPos + posTweak, nextChange.toAdd); break; case StringMod.REPLACE: int delPos = s.pos; // delete starting pos in original coordinates if (!nextChange.startInclusive) { delPos++; modPos++; } // Skip over anything already deleted while (deletedChars.get(delPos)) { delPos++; modPos++; } int delEndPos = nextChange.end.pos; // delete end point in original if (nextChange.endInclusive) delEndPos++; int modEndPos = delEndPos + adjust; // delete end point in current if (modPos < modEndPos) { if (nextChange.toAdd == "") output.delete(modPos, modEndPos); else { char fillCh = nextChange.toAdd.charAt(0); for (int i = modPos; i < modEndPos; i++) output.setCharAt(i, fillCh); } deletedChars.set(delPos, delEndPos); } break; default: throw new IllegalStateException("Unknown op: " + nextChange.op); } adjust += output.length() - lenBefore; if (changes.hasNext()) nextChange = changes.next(); else nextChange = null; } } // Finally, add it to the string if (negative) toAppendTo.append('-'); toAppendTo.append(output); }
From source file:com.joliciel.jochre.graphics.ShapeImplTest.java
@Test public void testGetOutline(@NonStrict final SourceImage sourceImage) { final int threshold = 100; final int width = 8; final int height = 8; new NonStrictExpectations() { {// w w w. j a v a 2 s . c om sourceImage.getHeight(); returns(height); sourceImage.getWidth(); returns(width); sourceImage.getSeparationThreshold(); returns(threshold); sourceImage.getWhiteGapFillFactor(); returns(0); int[] pixels = { 0, 1, 1, 0, 0, 1, 1, 1, // row 0 0, 1, 1, 1, 0, 1, 1, 1, // row 1 0, 0, 1, 1, 0, 0, 1, 1, // row 2 0, 0, 1, 1, 0, 1, 1, 0, // row 3 0, 0, 0, 1, 1, 1, 1, 0, // row 4 0, 0, 0, 1, 1, 1, 0, 0, // row 5 0, 0, 1, 1, 1, 0, 0, 0, // row 6 1, 1, 1, 1, 1, 0, 0, 0, // row 7 }; for (int x = -1; x <= width; x++) for (int y = -1; y <= height; y++) { sourceImage.isPixelBlack(x, y, threshold); if (x >= 0 && x < width && y >= 0 && y < height) returns(pixels[y * width + x] == 1); else returns(false); if (x >= 0 && x < width && y >= 0 && y < height) { sourceImage.getAbsolutePixel(x, y); if (pixels[y * width + x] == 1) returns(0); else returns(255); } } } }; Shape shape = new ShapeImpl(sourceImage); shape.setTop(0); shape.setBottom(7); shape.setLeft(0); shape.setRight(7); BitSet outline = shape.getOutline(threshold); int[] outlinePixels = { 0, 1, 1, 0, 0, 1, 1, 1, // row 0 0, 1, 0, 1, 0, 1, 0, 1, // row 1 0, 0, 1, 1, 0, 0, 1, 1, // row 2 0, 0, 1, 1, 0, 1, 1, 0, // row 3 0, 0, 0, 1, 1, 0, 1, 0, // row 4 0, 0, 0, 1, 0, 1, 0, 0, // row 5 0, 0, 1, 0, 1, 0, 0, 0, // row 6 1, 1, 1, 1, 1, 0, 0, 0, // row 7 }; for (int x = 0; x < 8; x++) for (int y = 0; y < 8; y++) { assertEquals("x = " + x + ",y = " + y, outlinePixels[y * 8 + x] == 1, outline.get(y * 8 + x)); } }
From source file:itemsetmining.itemset.ItemsetTree.java
/** * Pearson's chi-squared test for itemset independence. This tests the * empirical itemset distribution against the independence model. * * <p>/*w ww .j ava 2 s. com*/ * N.B. the chi-squared distribution has one degree of freedom. * * @see S. Brin et al. Beyond Market Baskets: Generalizing Association Rules * to Correlations */ private double recursiveChiSquared(final int n, final BitSet cell, final int[] sortedItems, final Multiset<Integer> singletons) { double chiSquared = 0.; if (n == sortedItems.length) { double pInd = noTransactions; final int[] inItems = new int[cell.cardinality()]; final int[] outItems = new int[n - cell.cardinality()]; int i = 0, j = 0; for (int k = 0; k < n; k++) { if (cell.get(k)) { inItems[i] = sortedItems[k]; i++; pInd *= singletons.count(sortedItems[k]) / (double) noTransactions; } else { outItems[j] = sortedItems[k]; j++; pInd *= (noTransactions - singletons.count(sortedItems[k])) / (double) noTransactions; } } final double pEmp = countEmpirical(inItems, outItems, root, new int[0]); chiSquared = ((pEmp - pInd) * (pEmp - pInd)) / pInd; } else { final BitSet celln = (BitSet) cell.clone(); celln.set(n); chiSquared += recursiveChiSquared(n + 1, celln, sortedItems, singletons); chiSquared += recursiveChiSquared(n + 1, cell, sortedItems, singletons); } return chiSquared; }
From source file:jetbrains.buildServer.clouds.azure.connector.AzureApiConnector.java
private OperationResponse createVM(final AzureCloudImageDetails imageDetails, final boolean generalized, final String vmName, final CloudInstanceUserData tag, final HostedServiceGetDetailedResponse.Deployment deployment) throws ServiceException, IOException { BitSet busyPorts = new BitSet(); busyPorts.set(MIN_PORT_NUMBER, MAX_PORT_NUMBER); for (RoleInstance instance : deployment.getRoleInstances()) { for (InstanceEndpoint endpoint : instance.getInstanceEndpoints()) { final int port = endpoint.getPort(); if (port >= MIN_PORT_NUMBER && port <= MAX_PORT_NUMBER) { busyPorts.set(port, false); }/*from w ww .j a v a 2s .c om*/ } } for (Role role : deployment.getRoles()) { for (ConfigurationSet conf : role.getConfigurationSets()) { for (InputEndpoint endpoint : conf.getInputEndpoints()) { final int port = endpoint.getPort(); if (port >= MIN_PORT_NUMBER && port <= MAX_PORT_NUMBER) { busyPorts.set(port, false); } } } } int portNumber = MIN_PORT_NUMBER; for (int i = MIN_PORT_NUMBER; i <= MAX_PORT_NUMBER; i++) { if (busyPorts.get(i)) { portNumber = i; break; } } final VirtualMachineOperations vmOperations = myClient.getVirtualMachinesOperations(); final VirtualMachineCreateParameters parameters = new VirtualMachineCreateParameters(); parameters.setRoleSize(imageDetails.getVmSize()); parameters.setProvisionGuestAgent(Boolean.TRUE); parameters.setRoleName(vmName); parameters.setVMImageName(imageDetails.getSourceName()); final ArrayList<ConfigurationSet> configurationSetList = createConfigurationSetList(imageDetails, generalized, vmName, tag, portNumber); parameters.setConfigurationSets(configurationSetList); try { return vmOperations.beginCreating(imageDetails.getServiceName(), deployment.getName(), parameters); } catch (ParserConfigurationException e) { throw new ServiceException(e); } catch (SAXException e) { throw new IOException(e); } catch (TransformerException e) { throw new IOException(e); } }
From source file:MSUmpire.SpectrumParser.mzXMLParser.java
private List<MzXMLthreadUnit> ParseScans(final BitSet IncludedScans) { List<MzXMLthreadUnit> ScanList = new ArrayList<>(); ArrayList<ForkJoinTask<?>> futures = new ArrayList<>(); final ForkJoinPool fjp = new ForkJoinPool(NoCPUs); Iterator<Entry<Integer, Long>> iter = ScanIndex.entrySet().iterator(); Entry<Integer, Long> ent = iter.next(); long currentIdx = ent.getValue(); int nextScanNo = ent.getKey(); final RandomAccessFile fileHandler; try {/*w w w. jav a 2 s.co m*/ fileHandler = new RandomAccessFile(filename, "r"); } catch (FileNotFoundException e) { throw new RuntimeException(e); } byte[] buffer = new byte[1 << 10]; if (step == -1) step = fjp.getParallelism() * 32; while (iter.hasNext()) { ent = iter.next(); long startposition = currentIdx; long nexposition = ent.getValue(); int currentScanNo = nextScanNo; nextScanNo = ent.getKey(); currentIdx = nexposition; if (IncludedScans.get(currentScanNo)) { try { final int bufsize = (int) (nexposition - startposition); if (buffer.length < bufsize) buffer = new byte[Math.max(bufsize, buffer.length << 1)]; // byte[] buffer = new byte[bufsize]; // RandomAccessFile fileHandler = new RandomAccessFile(filename, "r"); fileHandler.seek(startposition); fileHandler.read(buffer, 0, bufsize); // fileHandler.close(); // String xmltext = new String(buffer); String xmltext = new String(buffer, 0, bufsize, StandardCharsets.ISO_8859_1); if (ent.getKey() == Integer.MAX_VALUE) { xmltext = xmltext.replaceAll("</msRun>", ""); } boolean ReadPeak = true; final MzXMLthreadUnit unit = new MzXMLthreadUnit(xmltext, parameter, datatype, ReadPeak); futures.add(fjp.submit(unit)); ScanList.add(unit); if ((ScanList.size() % step) == 0) { futures.get(futures.size() - step).get(); if (iter.hasNext() && fjp.getActiveThreadCount() < fjp.getParallelism()) { step *= 2; // System.out.println("MzXMLthreadUnit: fjp.getActiveThreadCount()\t" + fjp.getActiveThreadCount()+"\t"+step); } } } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } } } try { fileHandler.close(); } catch (IOException ex) { throw new RuntimeException(ex); } fjp.shutdown(); try { fjp.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException ex) { throw new RuntimeException(ex); } // for (MzXMLthreadUnit unit : ScanList) { // executorPool.execute(unit); // } // executorPool.shutdown(); // // try { // executorPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); // } catch (InterruptedException e) { // Logger.getRootLogger().info("interrupted.."); // } return ScanList; }
From source file:org.exoplatform.services.jcr.impl.core.query.lucene.CachingIndexReader.java
/** * Returns the <code>DocId</code> of the parent of <code>n</code> or * {@link DocId#NULL} if <code>n</code> does not have a parent * (<code>n</code> is the root node). * * @param n the document number./* w w w. j a va 2s .c o m*/ * @param deleted the documents that should be regarded as deleted. * @return the <code>DocId</code> of <code>n</code>'s parent. * @throws IOException if an error occurs while reading from the index. */ DocId getParent(int n, BitSet deleted) throws IOException { DocId parent; boolean existing = false; parent = parents[n]; if (parent != null) { existing = true; // check if valid and reset if necessary if (!parent.isValid(deleted)) { if (log.isDebugEnabled()) { log.debug(parent + " not valid anymore."); } parent = null; } } if (parent == null) { Document doc = document(n, FieldSelectors.UUID_AND_PARENT); String[] parentUUIDs = doc.getValues(FieldNames.PARENT); if (parentUUIDs.length == 0 || parentUUIDs[0].length() == 0) { // root node parent = DocId.NULL; } else { if (shareableNodes.get(n)) { parent = DocId.create(parentUUIDs); } else { if (!existing) { Term id = new Term(FieldNames.UUID, parentUUIDs[0]); TermDocs docs = termDocs(id); try { while (docs.next()) { if (!deleted.get(docs.doc())) { parent = DocId.create(docs.doc()); break; } } } finally { docs.close(); } } // if still null, then parent is not in this index, or existing // DocId was invalid. thus, only allowed to create DocId from uuid if (parent == null) { parent = DocId.create(parentUUIDs[0]); } } } // finally put to cache parents[n] = parent; } return parent; }