List of usage examples for java.util BitSet size
public int size()
From source file:org.elasticsearch.hadoop.rest.RestRepository.java
public void flush() { BitSet bulk = tryFlush(); if (!bulk.isEmpty()) { throw new EsHadoopException( String.format("Could not write all entries [%s/%s] (maybe ES was overloaded?). Bailing out...", bulk.cardinality(), bulk.size())); }//from w w w . j ava2 s .com }
From source file:org.jahia.ajax.gwt.helper.NodeHelper.java
private void populatePermissions(GWTJahiaNode n, JCRNodeWrapper node) { BitSet bs = node.getPermissionsAsBitSet(); if (bs != null) { GWTBitSet gwtBs = new GWTBitSet(bs.size()); gwtBs.setReferenceHashCode(JahiaPrivilegeRegistry.getRegisteredPrivilegeNames().hashCode()); for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { gwtBs.set(i);//w ww . j a v a 2 s .co m } n.setPermissions(gwtBs); try { boolean hasAcl = node.hasNode("j:acl") && node.getNode("j:acl").hasNodes(); n.setHasAcl(hasAcl); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } }
From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java
private OpenBitSet getDocIdSet(Query query, final String locale) { OpenBitSet docIds = null;/*www .jav a 2s. co m*/ try { final BitSet bitset = new BitSet(); searcher.search(query, new AbstractHitCollector() { @Override public void collect(int docId, float scorer) { if (locale != null) { try { int docMainDocId = getMainDocIdForTranslations( searcher.getIndexReader().document(docId, TRANSLATION_FIELDS), locale); if (docMainDocId != -1) { bitset.set(docMainDocId); } } catch (Exception e) { logger.warn("Error getting index document while faceting", e); } } bitset.set(docId); } @Override public boolean acceptsDocsOutOfOrder() { return true; } }); docIds = new OpenBitSetDISI(new DocIdBitSet(bitset).iterator(), bitset.size()); } catch (IOException e) { logger.debug("Can't retrive bitset from hits", e); } return docIds; }
From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java
OpenBitSet getPositiveDocSet(Query q, final String locale) throws IOException { OpenBitSet answer;//from w ww .j av a 2 s . c om // if (filterCache != null) { // answer = filterCache.get(q); // if (answer!=null) return answer; // } final BitSet bitset = new BitSet(); searcher.search(q, new AbstractHitCollector() { @Override public void collect(int docId, float scorer) { if (locale != null) { try { int docMainDocId = getMainDocIdForTranslations( searcher.getIndexReader().document(docId, TRANSLATION_FIELDS), locale); if (docMainDocId != -1) { bitset.set(docMainDocId); } } catch (Exception e) { logger.warn("Error getting index document while faceting", e); } } bitset.set(docId); } @Override public boolean acceptsDocsOutOfOrder() { return true; } }); answer = new OpenBitSetDISI(new DocIdBitSet(bitset).iterator(), bitset.size()); // answer = getDocSetNC(q,null); // if (filterCache != null) filterCache.put(q,answer); return answer; }
From source file:org.jpos.iso.ISOBasePackager.java
/** * @param m/*from w w w. ja v a 2 s . c o m*/ * the Container of this message * @param b * ISO message image * @return consumed bytes * @exception ISOException */ public int unpack(ISOComponent m, byte[] b) throws ISOException { LogEvent evt = new LogEvent(this, "unpack"); int consumed = 0; try { if (m.getComposite() != m) throw new ISOException("Can't call packager on non Composite"); if (logger != null) // save a few CPU cycle if no logger available evt.addMessage(CardNoEncodeUtil.encodeCardNo((ISOUtil.hexString(b)))); // if ISOMsg and headerLength defined // if (m instanceof ISOMsg /* && ((ISOMsg) m).getHeader()==null */ // && headerLength > 0) { // byte[] h = new byte[headerLength]; // System.arraycopy(b, 0, h, 0, headerLength); // ((ISOMsg) m).setHeader(h); // consumed += headerLength; // } if (!(fld[0] == null) && !(fld[0] instanceof ISOBitMapPackager)) { ISOComponent mti = fld[0].createComponent(0); consumed += fld[0].unpack(mti, b, consumed); m.set(mti); } BitSet bmap = null; int maxField = fld.length; if (emitBitMap()) { ISOBitMap bitmap = new ISOBitMap(-1); consumed += getBitMapfieldPackager().unpack(bitmap, b, consumed); bmap = (BitSet) bitmap.getValue(); if (logger != null) evt.addMessage("<bitmap>" + bmap.toString() + "</bitmap>"); m.set(bitmap); maxField = Math.min(maxField, bmap.size()); } for (int i = getFirstField(); i < maxField; i++) { try { if (bmap == null && fld[i] == null) continue; if (maxField > 128 && i == 65) continue; // ignore extended bitmap if (bmap == null || bmap.get(i)) { if (fld[i] == null) throw new ISOException("field packager '" + i + "' is null"); ISOComponent c = fld[i].createComponent(i); consumed += fld[i].unpack(c, b, consumed); if (logger != null) { String value = c.getValue() + ""; evt.addMessage("<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\" name=\"" + fld[i].getDescription() + "\">"); if (c.getValue() instanceof ISOMsg) evt.addMessage(c.getValue()); else if (c.getValue() instanceof byte[]) { evt.addMessage(" <value type='binary'>" + ISOUtil.hexString((byte[]) c.getValue()) + "</value>"); } else { if (i == 2) { value = simpleEncodeCardNo(value); } evt.addMessage(" <value>" + value + "</value>"); } evt.addMessage("</unpack>"); } m.set(c); } } catch (ISOException e) { evt.addMessage("error unpacking field " + i + " consumed=" + consumed); evt.addMessage(e); // jPOS-3 e = new ISOException(String.format("%s (%s) unpacking field=%d, consumed=%d", e.getMessage(), e.getNested().toString(), i, consumed)); throw e; } } if (b.length != consumed) { evt.addMessage("WARNING: unpack len=" + b.length + " consumed=" + consumed); } return consumed; } catch (ISOException e) { evt.addMessage(e); throw e; } catch (Exception e) { evt.addMessage(e); throw new ISOException(e.getMessage() + " consumed=" + consumed); } finally { Logger.log(evt); } }
From source file:org.jpos.iso.ISOBasePackager.java
public void unpack(ISOComponent m, InputStream in) throws IOException, ISOException { LogEvent evt = new LogEvent(this, "unpack"); try {/*from ww w. j a v a 2s . c o m*/ if (m.getComposite() != m) throw new ISOException("Can't call packager on non Composite"); // if ISOMsg and headerLength defined // if (m instanceof ISOMsg && ((ISOMsg) m).getHeader() == null && headerLength > 0) { // byte[] h = new byte[headerLength]; // in.read(h, 0, headerLength); // ((ISOMsg) m).setHeader(h); // } if (!(fld[0] instanceof ISOMsgFieldPackager) && !(fld[0] instanceof ISOBitMapPackager)) { ISOComponent mti = fld[0].createComponent(0); fld[0].unpack(mti, in); m.set(mti); } BitSet bmap = null; int maxField = fld.length; if (emitBitMap()) { ISOBitMap bitmap = new ISOBitMap(-1); getBitMapfieldPackager().unpack(bitmap, in); bmap = (BitSet) bitmap.getValue(); if (logger != null) evt.addMessage("<bitmap>" + bmap.toString() + "</bitmap>"); m.set(bitmap); maxField = Math.min(maxField, bmap.size()); } for (int i = getFirstField(); i < maxField; i++) { if (bmap == null && fld[i] == null) continue; if (bmap == null || bmap.get(i)) { if (fld[i] == null) throw new ISOException("field packager '" + i + "' is null"); ISOComponent c = fld[i].createComponent(i); fld[i].unpack(c, in); if (logger != null) { evt.addMessage( "<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">"); if (c.getValue() instanceof ISOMsg) evt.addMessage(c.getValue()); else evt.addMessage(" <value>" + c.getValue().toString() + "</value>"); evt.addMessage("</unpack>"); } m.set(c); } } if (bmap != null && bmap.get(65) && fld.length > 128 && fld[65] instanceof ISOBitMapPackager) { bmap = (BitSet) ((ISOComponent) m.getChildren().get(65)).getValue(); for (int i = 1; i < 64; i++) { if (bmap == null || bmap.get(i)) { ISOComponent c = fld[i + 128].createComponent(i); fld[i + 128].unpack(c, in); if (logger != null) { evt.addMessage("<unpack fld=\"" + i + 128 + "\" packager=\"" + fld[i + 128].getClass().getName() + "\">"); evt.addMessage(" <value>" + c.getValue().toString() + "</value>"); evt.addMessage("</unpack>"); } m.set(c); } } } } catch (ISOException e) { evt.addMessage(e); throw e; } catch (EOFException e) { throw e; } catch (Exception e) { evt.addMessage(e); throw new ISOException(e); } finally { Logger.log(evt); } }
From source file:org.rifidi.edge.adapter.alien.Alien9800ReaderSession.java
/** * This method sets the External Output high for the given ports * /*from w w w . j av a 2 s .c om*/ * @param ports * The ports to set high */ public void setOutputPort(BitSet ports) { int value = 0; for (int i = 0; i < 8; i++) { int bit = 0; if (ports.size() > i + 1) bit = ports.get(i) ? 1 : 0; value = value | bit << i; } if (value > 255) { throw new IllegalArgumentException("No more than 8 ports allowed"); } ((Alien9800Reader) this.getSensor()).setExternalOutput(value); ((Alien9800Reader) this.getSensor()).applyPropertyChanges(); }
From source file:org.wso2.andes.kernel.router.TopicRoutingMatcher.java
/** * Removing a storageQueue from the structure. * * @param storageQueue The storageQueue to remove *//*from w w w .j a v a 2 s . c o m*/ public void removeStorageQueue(StorageQueue storageQueue) { int queueIndex = storageQueueList.indexOf(storageQueue); if (queueIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed storageQueue removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == queueIndex) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the storageQueue from storageQueue list storageQueueList.remove(queueIndex); } else { log.warn("Storage queue for with name : " + storageQueue.getName() + " is not found to " + "remove"); } }
From source file:org.wso2.andes.subscription.ClusterSubscriptionBitMapHandler.java
/** * Removing a subscription from the structure. * * @param subscription The subscription to remove *//*w w w . j a va2 s.c om*/ @Override public void removeWildCardSubscription(AndesSubscription subscription) { int subscriptionIndex = wildCardSubscriptionList.indexOf(subscription); if (subscriptionIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed subscription removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == i) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the subscription from subscription list wildCardSubscriptionList.remove(subscriptionIndex); } else { log.warn("Subscription for destination : " + subscription.getSubscribedDestination() + " is not found to " + "remove"); } }
From source file:org.wso2.andes.subscription.TopicSubscriptionBitMapStore.java
/** * Removing a subscription from the structure. * * @param subscription The subscription to remove *//*from ww w. j a v a2 s.c om*/ @Override public void removeSubscription(AndesSubscription subscription) { int subscriptionIndex = subscriptionList.indexOf(subscription); if (subscriptionIndex > -1) { for (Map<String, BitSet> constituentTable : constituentTables) { for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { // For every row create a new BitSet with the values for the removed subscription removed String constituent = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); BitSet newBitSet = new BitSet(); int bitIndex = 0; for (int i = 0; i < bitSet.size(); i++) { if (bitIndex == i) { // If the this is the index to remove then skip this round bitIndex++; } newBitSet.set(i, bitSet.get(bitIndex)); bitIndex++; } constituentTable.put(constituent, newBitSet); } } // Remove the subscription from subscription list subscriptionList.remove(subscriptionIndex); } else { log.warn("Subscription for destination : " + subscription.getSubscribedDestination() + " is not found to " + "remove"); } }