/** initializes the attribute indices. */ protected void initializeAttributeIndices() { m_AttributeIndices.setUpper(m_Data.numAttributes() - 1); m_ActiveIndices = new boolean[m_Data.numAttributes()]; for (int i = 0; i < m_ActiveIndices.length; i++) { m_ActiveIndices[i] = m_AttributeIndices.isInRange(i); } }
public static void main(String[] args) { Main obj = new Main(); String text = "Hello world!"; Range range = obj.encode(text); System.out.println(range.getLow() + " " + range.getHigh()); System.out.println(obj.decode(text.length(), (range.getLow() + range.getHigh()) / 2)); }
/** * Removes the EXACT range defined by (low,high). If no range is defined on exactly those * coordinates, no elements are removed */ public Object remove(int low, int high) { RangeHolder holder = new RangeHolder(low, high); int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, false); Range found = (Range) ranges.elementAt(pos); if (found.equals(holder)) return data.remove(holder); else return null; }
public Vector put(Range holder, Object value) { int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true); if (pos == -1) { pos = 0; } Vector output = new Vector(); int posHigh = VectorUtil.binarySearch( ranges, new RangeHolder(holder.getHigh(), holder.getHigh()), rangeComparator, true); Vector purged = new Vector(); boolean positionRemoved = false; for (int i = (pos - 1 >= 0 ? pos - 1 : 0); i < posHigh && i < ranges.size(); i++) { Range clobberMe = (Range) ranges.elementAt(i); if (overlaps(clobberMe, holder)) { if (i == pos - 1) positionRemoved = true; output.addElement(data.remove(clobberMe)); purged.addElement(clobberMe); } } for (int i = 0; i < purged.size(); i++) ranges.removeElement(purged.elementAt(i)); if (positionRemoved) pos = pos - 1; ranges.insertElementAt(holder, pos); data.put(holder, value); return output; }
public double[] getInterval(int key) { double[] output = new double[2]; RangeHolder holder = new RangeHolder(key, key + 1); int pos = VectorUtil.binarySearch(ranges, holder, rangeComparator, true) - 1; // System.err.println("ranges = "+ranges); if (ranges.size() == 0) { output[0] = Double.NEGATIVE_INFINITY; output[1] = Double.POSITIVE_INFINITY; return output; } if (pos < 0) { output[0] = Double.NEGATIVE_INFINITY; output[1] = (double) ((Range) ranges.elementAt(0)).getLow() - 1; return output; } if (pos >= ranges.size()) { output[0] = (double) ((Range) ranges.elementAt(ranges.size() - 1)).getHigh() + 1; output[1] = Double.POSITIVE_INFINITY; return output; } Range rh = (Range) ranges.elementAt(pos); if (contains(rh, key)) { output[0] = (double) rh.getLow(); output[1] = (double) rh.getHigh(); } else { output[0] = (double) rh.getHigh() + 1; if (pos < ranges.size() - 1) output[1] = ((Range) ranges.elementAt(pos + 1)).getLow() - 1; else output[1] = Double.POSITIVE_INFINITY; } return output; }
/** * Handle UTR joins * * @param feature * @param key * @param qualifiers * @return */ private Location joinUtrs(Feature feature, Key key, QualifierVector qualifiers) { Location location = feature.getLocation(); if (key.getKeyString().equals("5'UTR") || key.getKeyString().equals("3'UTR")) { ChadoCanonicalGene gene = ((GFFStreamFeature) feature).getChadoGene(); String utrName = GeneUtils.getUniqueName(feature); String transcriptName = gene.getTranscriptFromName(utrName); List<Feature> utrs; if (key.getKeyString().equals("5'UTR")) utrs = gene.get5UtrOfTranscript(transcriptName); else utrs = gene.get3UtrOfTranscript(transcriptName); if (utrs.size() > 1) { int start = Integer.MAX_VALUE; RangeVector ranges = new RangeVector(); for (int i = 0; i < utrs.size(); i++) { Feature utr = utrs.get(i); Range range = utr.getLocation().getTotalRange(); if (start > range.getStart()) start = range.getStart(); ranges.add(range); } if (start != feature.getLocation().getTotalRange().getStart()) return null; location = new Location(ranges, feature.getLocation().isComplement()); } int ntranscripts = gene.getTranscripts().size(); if (ntranscripts == 1) transcriptName = gene.getGeneUniqueName(); qualifiers.setQualifier(new Qualifier("locus_tag", transcriptName)); qualifiers.removeQualifierByName("ID"); } return location; }
@Test public void testAllocateMac() throws Exception { assertThat(rangeOf10Macs.allocateMacs(5).size(), is(5)); assertThat(rangeOf10Macs.getAvailableCount(), is(5)); assertThat(rangeOf10Macs.allocateMacs(5).size(), is(5)); assertThat(rangeOf10Macs.getAvailableCount(), is(0)); }
public void testSplit2() throws Exception { LongRangeSpliter spliter = new LongRangeSpliter(); List<Range<Long>> list = spliter.split(-2l, 10l, 4); for (Range range : list) { System.out.println(range.toString()); } }
/** Test that we can replace text in our Range with Unicode text. */ public void testRangeReplacementOne() { HWPFDocument daDoc = HWPFTestDataSamples.openSampleFile(illustrativeDocFile); Range range = daDoc.getRange(); assertEquals(1, range.numSections()); Section section = range.getSection(0); assertEquals(5, section.numParagraphs()); Paragraph para = section.getParagraph(2); String text = para.text(); assertEquals(originalText, text); int offset = text.indexOf(searchText); assertEquals(181, offset); para.replaceText(searchText, replacementText, offset); assertEquals(1, range.numSections()); section = range.getSection(0); assertEquals(4, section.numParagraphs()); para = section.getParagraph(2); text = para.text(); assertEquals(expectedText2, text); }
/** * Create a new emitter configurable externally * * @param name The name of emitter */ public ConfigurableEmitter(String name) { this.name = name; leftToEmit = (int) emitCount.random(); timeout = (int) (length.random()); colors.add(new ColorRecord(0, Color.white)); colors.add(new ColorRecord(1, Color.red)); ArrayList<Vector2f> curve = new ArrayList<>(); curve.add(new Vector2f(0.0f, 0.0f)); curve.add(new Vector2f(1.0f, 255.0f)); alpha = new LinearInterpolator(curve, 0, 255); curve = new ArrayList<>(); curve.add(new Vector2f(0.0f, 0.0f)); curve.add(new Vector2f(1.0f, 255.0f)); size = new LinearInterpolator(curve, 0, 255); curve = new ArrayList<>(); curve.add(new Vector2f(0.0f, 0.0f)); curve.add(new Vector2f(1.0f, 1.0f)); velocity = new LinearInterpolator(curve, 0, 1); curve = new ArrayList<>(); curve.add(new Vector2f(0.0f, 0.0f)); curve.add(new Vector2f(1.0f, 1.0f)); scaleY = new LinearInterpolator(curve, 0, 1); }
private void shapeContextually(char[] text, int start, int count, Range ctxKey) { // if we don't support the specified context, then don't shape. if (ctxKey == null || !rangeSet.contains(ctxKey)) { ctxKey = Range.EUROPEAN; } Range lastKey = ctxKey; int base = ctxKey.getDigitBase(); char minDigit = (char) ('0' + ctxKey.getNumericBase()); final int end = start + count; for (int i = start; i < end; ++i) { char c = text[i]; if (c >= minDigit && c <= '9') { text[i] = (char) (c + base); continue; } if (isStrongDirectional(c)) { ctxKey = rangeForCodePoint(c); if (ctxKey != lastKey) { lastKey = ctxKey; base = ctxKey.getDigitBase(); minDigit = (char) ('0' + ctxKey.getNumericBase()); } } } }
/** * Returns a <code>String</code> that describes this shaper. This method is used for debugging * purposes only. * * @return a <code>String</code> describing this shaper. */ public String toString() { StringBuilder buf = new StringBuilder(super.toString()); buf.append("[contextual:").append(isContextual()); String[] keyNames = null; if (isContextual()) { buf.append(", context:"); buf.append(shapingRange == null ? Range.values()[key] : shapingRange); } if (rangeSet == null) { buf.append(", range(s): "); boolean first = true; for (int i = 0; i < NUM_KEYS; ++i) { if ((mask & (1 << i)) != 0) { if (first) { first = false; } else { buf.append(", "); } buf.append(Range.values()[i]); } } } else { buf.append(", range set: ").append(rangeSet); } buf.append(']'); return buf.toString(); }
private void invalidateRanges() { synchronized (myLock) { for (Range range : myRanges) { range.invalidate(); } } }
@Test public void testUntil() { Range<Character> range = new Range<>('a').until('z'); assertThat(range.getTo(), is('z')); assertThat(range.isToIncluded(), is(false)); Helpers.assertThrows(NullPointerException.class, () -> new Range<>("").until(null)); }
/** * Clears the specified range of characters from the character set so that subsequent calls to * {@code test} for characters within the range will return {@code false}. * * @see #difference(Chset, Chset) */ private void clear(Range r) { if (ranges.isEmpty()) { return; } int pos = find(r.first); if (pos > 0) { Range prev = ranges.get(pos - 1); if (prev.includes(r.first)) { if (prev.last > r.last) { Range n = new Range(r.last + 1, prev.last); prev.last = r.first - 1; ranges.add(pos, n); refreshAsciiSet(); return; } else { prev.last = r.first - 1; } } } while ((pos < ranges.size()) && r.includes(ranges.get(pos))) { ranges.remove(pos); } if ((pos < ranges.size()) && ranges.get(pos).includes(r.last)) { ranges.get(pos).first = r.last + 1; } refreshAsciiSet(); }
/** * Test if the given address is contained within this address pool. * * @param addr the address to test for containment in this address pool * @return true, if successful */ public boolean contains(InetAddress addr) { if ((Util.compareInetAddrs(addr, range.getStartAddress()) >= 0) && (Util.compareInetAddrs(addr, range.getEndAddress()) <= 0)) { return true; } return false; }
/** * @return new {@link Range} with {@literal min} and {@literal max} set to {@link * Boundary#infinite()}. */ public static Range unbounded() { Range range = new Range(); range.min = Boundary.infinite(); range.max = Boundary.infinite(); return range; }
public synchronized void add(RangeSet that) { int lhs = 0, rhs = 0; while (lhs < this.ranges.size() && rhs < that.ranges.size()) { Range lr = this.ranges.get(lhs); Range rr = that.ranges.get(rhs); // no overlap if (lr.end < rr.start) { lhs++; continue; } if (rr.end < lr.start) { ranges.add(lhs, rr); lhs++; rhs++; continue; } // overlap. merge two Range m = lr.combine(rr); rhs++; // since ranges[lhs] is expanded, it might overlap with others in this.ranges while (lhs + 1 < this.ranges.size() && !m.isIndependent(this.ranges.get(lhs + 1))) { m = m.combine(this.ranges.get(lhs + 1)); this.ranges.remove(lhs + 1); } this.ranges.set(lhs, m); } // if anything is left in that.ranges, add them all this.ranges.addAll(that.ranges.subList(rhs, that.ranges.size())); }
/** * Returns {@code true} if the specified object is an instance of <code>NumericShaper</code> and * shapes identically to this one, regardless of the range representations, the bit mask or the * enum. For example, the following code produces {@code "true"}. * * <blockquote> * * <pre> * NumericShaper ns1 = NumericShaper.getShaper(NumericShaper.ARABIC); * NumericShaper ns2 = NumericShaper.getShaper(NumericShaper.Range.ARABIC); * System.out.println(ns1.equals(ns2)); * </pre> * * </blockquote> * * @param o the specified object to compare to this <code>NumericShaper</code> * @return <code>true</code> if <code>o</code> is an instance of <code>NumericShaper</code> and * shapes in the same way; <code>false</code> otherwise. * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object o) { if (o != null) { try { NumericShaper rhs = (NumericShaper) o; if (rangeSet != null) { if (rhs.rangeSet != null) { return isContextual() == rhs.isContextual() && rangeSet.equals(rhs.rangeSet) && shapingRange == rhs.shapingRange; } return isContextual() == rhs.isContextual() && rangeSet.equals(Range.maskToRangeSet(rhs.mask)) && shapingRange == Range.indexToRange(rhs.key); } else if (rhs.rangeSet != null) { Set<Range> rset = Range.maskToRangeSet(mask); Range srange = Range.indexToRange(key); return isContextual() == rhs.isContextual() && rset.equals(rhs.rangeSet) && srange == rhs.shapingRange; } return rhs.mask == mask && rhs.key == key; } catch (ClassCastException e) { } } return false; }
public int getAvailableMacsCount() { int count = 0; for (Range range : ranges) { count += range.getAvailableCount(); } return count; }
/** * Tests whether the specified range overlaps with this range using <code>long</code> comparison. * * <p><code>null</code> is handled and returns <code>false</code>. * * @param range the range to test, may be <code>null</code> * @return <code>true</code> if the specified range overlaps with this range */ public boolean overlapsRange(Range range) { if (range == null) { return false; } return range.containsLong(min) || range.containsLong(max) || containsLong(range.getMinimumLong()); }
private boolean useMac(long mac, boolean allowDuplicates) { Range range = findIncludingRange(mac); if (range == null) { return customMacs.add(mac, allowDuplicates); } else { return range.use(mac, allowDuplicates); } }
@Test public void decrement() { Range<Integer> range = new IntRange(3, 1).decrementBy(2); Iterator<Integer> iterator = range.iterator(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.next(), is(3)); assertThat(iterator.hasNext(), is(false)); }
private Range findIncludingRange(long mac) { for (Range range : ranges) { if (range.contains(mac)) { return range; } } return null; }
private Range getRangeWithAvailableMac() { for (Range range : ranges) { if (range.getAvailableCount() > 0) { return range; } } return null; }
public void freeMac(long mac) { Range range = findIncludingRange(mac); if (range == null) { customMacs.remove(mac); } else { range.freeMac(mac); } }
@Test public void singletonRev() { Range<Integer> range = new IntRange(1, 0).incrementBy(-1); Iterator<Integer> iterator = range.iterator(); assertThat(iterator.hasNext(), is(true)); assertThat(iterator.next(), is(1)); assertThat(iterator.hasNext(), is(false)); }
@Test public void testAssigningMacWithAllowedDuplicates() throws Exception { assertThat(rangeOf10Macs.use(MAC_FROM_RANGE, true), is(true)); assertThat(rangeOf10Macs.getAvailableCount(), is(NUMBER_OF_MACS - 1)); assertThat(rangeOf10Macs.use(MAC_FROM_RANGE, true), is(true)); assertThat(rangeOf10Macs.getAvailableCount(), is(NUMBER_OF_MACS - 1)); assertThat(rangeOf10Macs.isAllocated(MAC_FROM_RANGE), is(true)); }
@Override public Collection<Slice> getSearchSlicesSingle( String shardKey, SolrParams params, DocCollection collection) { if (shardKey == null) { // search across whole collection // TODO: this may need modification in the future when shard splitting could cause an overlap return collection.getSlices(); } String id = shardKey; int idx = shardKey.indexOf(separator); if (idx < 0) { // shardKey is a simple id, so don't do a range return Collections.singletonList( hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection)); } int m1 = mask1; int m2 = mask2; String part1 = id.substring(0, idx); int bitsSepIdx = part1.indexOf(bitsSepartor); if (bitsSepIdx > 0) { int firstBits = getBits(part1, bitsSepIdx); if (firstBits >= 0) { m1 = firstBits == 0 ? 0 : (-1 << (32 - firstBits)); m2 = firstBits == 32 ? 0 : (-1 >>> firstBits); part1 = part1.substring(0, bitsSepIdx); } } // If the upper bits are 0xF0000000, the range we want to cover is // 0xF0000000 0xFfffffff int hash1 = Hash.murmurhash3_x86_32(part1, 0, part1.length(), 0); int upperBits = hash1 & m1; int lowerBound = upperBits; int upperBound = upperBits | m2; if (m1 == 0) { // no bits used from first part of key.. the code above will produce 0x000000000->0xffffffff // which only works on unsigned space, but we're using signed space. lowerBound = Integer.MIN_VALUE; upperBound = Integer.MAX_VALUE; } Range completeRange = new Range(lowerBound, upperBound); List<Slice> targetSlices = new ArrayList<Slice>(1); for (Slice slice : collection.getSlices()) { Range range = slice.getRange(); if (range != null && range.overlaps(completeRange)) { targetSlices.add(slice); } } return targetSlices; }
@Test public void testZSS502_NonExistingSheet2007() { Book book = Util.loadBook(this, "book/blank.xlsx"); Sheet sheet = book.getSheetAt(0); Range cell = Ranges.range(sheet, "A1"); cell.setCellEditText("=nonExisted!B1"); assertEquals("=nonExisted!B1", cell.getCellEditText()); assertEquals(ErrorConstants.getText(ErrorConstants.ERROR_REF), cell.getCellFormatText()); }