List of usage examples for java.util BitSet BitSet
public BitSet()
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 ww w .j a v a 2 s . 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:org.wso2.andes.kernel.router.TopicRoutingMatcher.java
/** * Add a new constituent row for the given constituent index table and fill values for already available * queues.// w ww. jav a2s .c o m * * @param constituent The constituent to add * @param constituentIndex The index of the constituent */ private void addConstituentRow(String constituent, int constituentIndex) { Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); BitSet bitSet = new BitSet(); for (int i = 0; i < queueConstituents.size(); i++) { String[] constituentsOfQueue = queueConstituents.get(i); if (constituentIndex < constituentsOfQueue.length) { // Get the i'th queue's [constituentIndex]'th constituent String queueConstituent = constituentsOfQueue[constituentIndex]; if (queueConstituent.equals(constituent) || multiLevelWildCard.equals(queueConstituent) || singleLevelWildCard.equals(queueConstituent)) { // The new constituent matches the queues i'th constituent bitSet.set(i); } else { // The new constituent does not match the i'th queues [constituentIndex] constituent bitSet.set(i, false); } } else { // The queue does not have a constituent for this index // If the last constituent of the queue is multiLevelWildCard we match else false if (multiLevelWildCard.equals(constituentsOfQueue[constituentsOfQueue.length - 1])) { bitSet.set(i); } else { bitSet.set(i, false); } } } constituentTable.put(constituent, bitSet); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testBitSetSerialization() throws Exception { //Gson gson = new Gson(); BitSet bits = new BitSet(); bits.set(1);/*from w ww . ja v a2s .c om*/ bits.set(3, 6); bits.set(9); String json = oson.toJson(bits); assertEquals("[0,1,0,1,1,1,0,0,0,1]", json); }
From source file:org.apache.mele.embedded.HadoopQueueEmbedded.java
private boolean ackCheck() throws IOException { LOG.info("Starting ack check"); BitSet bitSet = new BitSet(); FileSystem fileSystem = null; try {/*from w w w .j a v a 2 s . c om*/ _ackLock.lock(); _ackOutputStream.close(); fileSystem = newFileSystem(_file); FileStatus fileStatus = fileSystem.getFileStatus(_file); long dataLength = fileStatus.getLen(); long totalAckLength = getTotalAckLength(fileSystem); if (!couldContainAllAcks(totalAckLength)) { LOG.info("Existing early [" + totalAckLength + "] because [" + totalAckLength % 12 + "]"); return false; } for (Path ackFile : _ackFiles) { LOG.info("Starting ack check for file [" + ackFile + "]"); DFSInputStream inputStream = null; try { inputStream = getDFS(fileSystem.open(ackFile)); long length = inputStream.getFileLength(); DataInputStream dataInputStream = new DataInputStream(inputStream); while (length > 0) { int pos = (int) dataInputStream.readLong(); // @TODO check position // 4 bytes for storing the length of the message int len = dataInputStream.readInt() + 4; bitSet.set(pos, pos + len); length -= 12; } if (bitSet.cardinality() == dataLength) { return true; } } finally { if (inputStream != null) { inputStream.close(); } } } return false; } finally { reopenAckFile(fileSystem); _ackLock.unlock(); if (fileSystem != null) { fileSystem.close(); } } }
From source file:org.lockss.util.NumberUtil.java
/** * Increment an alphabetical string by the given delta, considering the string * to represent a value in base-26 using the characters a-z or A-Z - the * string is treated case-insensitively. For example, with a delta of 1: * <ul>/* ww w.j a va2 s. c om*/ * <li>aaa to aab</li> * <li>aaz to aba</li> * <li>zzy to zzz</li> * <li>zyz to zza</li> * </ul> * <p> * Note that after 'z' comes 'ba', because 'a' corresponds to 0 and is so * every number is implicitly preceded by 'a'. This may not be what is desired * for some sequences, in which case this may need to be adapted. * <p> * The string is lower cased before the increment is applied, and then each * character position that was upper case in the original string is upper * cased before returning. An exception will be thrown if any character is * outside of a-z after lower casing. If the value limit for the string length * is reached, the returned string will be longer; the extra characters will * be lower cased, which may be unwanted. * * @param s a purely alphabetical string * @return a string incremented according to base-26 * @throws NumberFormatException if the string contains inappropriate characters or cannot be incremented */ public static String incrementBase26String(String s, int delta) throws NumberFormatException { // Track the case of each character, so we can reset them before returning BitSet cases = new BitSet(); for (int i = 0; i < s.length(); i++) { cases.set(i, Character.isUpperCase(s.charAt(i))); } // Convert, increment, convert back String res = toBase26(fromBase26(s.toLowerCase()) + delta); // Pad the string to the correct length with 'a' res = StringUtils.leftPad(res, s.length(), 'a'); // Re-case the chars - using an offset in case the new string is longer char[] carr = res.toCharArray(); int offset = carr.length - s.length(); for (int pos = 0; pos < s.length(); pos++) { if (cases.get(pos)) carr[offset + pos] = Character.toUpperCase(carr[offset + pos]); } return new String(carr); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testBitSetDeserialization() throws Exception { BitSet expected = new BitSet(); expected.set(0);/*from ww w . ja va2s .c om*/ expected.set(2, 6); expected.set(8); String json = oson.toJson(expected); assertEquals(expected, oson.fromJson(json, BitSet.class)); json = "[1,0,1,1,1,1,0,0,1,0,0,0]"; assertEquals(expected, oson.fromJson(json, BitSet.class)); json = "[\"1\",\"0\",\"1\",\"1\",\"1\",\"1\",\"0\",\"0\",\"1\"]"; assertEquals(expected, oson.fromJson(json, BitSet.class)); json = "[true,false,true,true,true,true,false,false,true,false,false]"; assertEquals(expected, oson.fromJson(json, BitSet.class)); }
From source file:com.jefftharris.passwdsafe.PasswdSafe.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { final BitSet options = new BitSet(); options.set(MENU_BIT_HAS_CLOSE);/*w w w. j a va2 s .c o m*/ itsFileDataFrag.useFileData(new PasswdFileDataUser() { @Override public void useFileData(@NonNull PasswdFileData fileData) { boolean fileEditable = fileData.canEdit(); switch (itsCurrViewMode) { case VIEW_LIST: { options.set(MENU_BIT_CAN_ADD, fileEditable); options.set(MENU_BIT_HAS_SEARCH, true); if (fileEditable) { options.set(MENU_BIT_HAS_FILE_OPS, true); options.set(MENU_BIT_HAS_FILE_CHANGE_PASSWORD, fileData.isNotYubikey()); options.set(MENU_BIT_HAS_FILE_PROTECT, true); options.set(MENU_BIT_PROTECT_ALL, itsLocation.getGroups().isEmpty()); } if (fileData.canDelete()) { options.set(MENU_BIT_HAS_FILE_OPS, true); options.set(MENU_BIT_HAS_FILE_DELETE, true); } break; } case VIEW_RECORD: { options.set(MENU_BIT_CAN_ADD, fileEditable); break; } case INIT: case FILE_OPEN: case FILE_NEW: case VIEW_ABOUT: case VIEW_EXPIRATION: case VIEW_POLICY_LIST: case VIEW_PREFERENCES: { break; } case EDIT_RECORD: case CHANGING_PASSWORD: { options.set(MENU_BIT_HAS_CLOSE, false); break; } } } }); MenuItem item = menu.findItem(R.id.menu_add); if (item != null) { item.setVisible(options.get(MENU_BIT_CAN_ADD)); } item = menu.findItem(R.id.menu_close); if (item != null) { item.setVisible(options.get(MENU_BIT_HAS_CLOSE)); } item = menu.findItem(R.id.menu_file_ops); if (item != null) { item.setVisible(options.get(MENU_BIT_HAS_FILE_OPS)); } item = menu.findItem(R.id.menu_file_change_password); if (item != null) { item.setEnabled(options.get(MENU_BIT_HAS_FILE_CHANGE_PASSWORD)); } if (options.get(MENU_BIT_HAS_FILE_OPS)) { boolean hasProtect = options.get(MENU_BIT_HAS_FILE_PROTECT); boolean viewProtectAll = options.get(MENU_BIT_PROTECT_ALL); item = menu.findItem(R.id.menu_file_protect_records); if (item != null) { item.setEnabled(hasProtect); item.setTitle(viewProtectAll ? R.string.protect_all : R.string.protect_group); } item = menu.findItem(R.id.menu_file_unprotect_records); if (item != null) { item.setEnabled(hasProtect); item.setTitle(viewProtectAll ? R.string.unprotect_all : R.string.unprotect_group); } item = menu.findItem(R.id.menu_file_delete); if (item != null) { item.setEnabled(options.get(MENU_BIT_HAS_FILE_DELETE)); } } item = menu.findItem(R.id.menu_search); if (item != null) { item.setVisible(options.get(MENU_BIT_HAS_SEARCH)); } return super.onPrepareOptionsMenu(menu); }
From source file:org.wso2.andes.subscription.ClusterSubscriptionBitMapHandler.java
/** * Add a new constituent row for the given constituent index table and fill values for already available * subscriptions.//from w w w . j av a 2s . c o m * * @param constituent The constituent to add * @param constituentIndex The index of the constituent */ private void addConstituentRow(String constituent, int constituentIndex) { Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); BitSet bitSet = new BitSet(); for (int i = 0; i < subscriptionConstituents.size(); i++) { String[] constituentsOfSubscription = subscriptionConstituents.get(i); if (constituentIndex < constituentsOfSubscription.length) { // Get the i'th subscription's [constituentIndex]'th constituent String subscriptionConstituent = constituentsOfSubscription[constituentIndex]; if (subscriptionConstituent.equals(constituent) || multiLevelWildCard.equals(subscriptionConstituent) || singleLevelWildCard.equals(subscriptionConstituent)) { // The new constituent matches the subscriptions i'th constituent bitSet.set(i); } else { // The new constituent does not match the i'th subscriptions [constituentIndex] constituent bitSet.set(i, false); } } else { // The subscription does not have a constituent for this index // If the last constituent of the subscription is multiLevelWildCard we match else false if (multiLevelWildCard.equals(constituentsOfSubscription[constituentsOfSubscription.length - 1])) { bitSet.set(i); } else { bitSet.set(i, false); } } } constituentTable.put(constituent, bitSet); }
From source file:org.rifidi.edge.adapter.alien.Alien9800ReaderSession.java
/** * This method flashes the given output ports high for a given amount of * time. This method executes in a separate thread, so it returns * immediately.// w w w. java2 s . c o m * * @param ports * The ports to set to high * @param finalPorts * The configuration of the ports after the flashes are done * @param timeOn * The time in seconds to set the ports high * @param timeOff * The time in seconds to set the port low * @param repeat * The number of times to reapeat the flashes. * @throws CannotExecuteException */ public void flashOutput(final BitSet ports, final BitSet finalPorts, final int timeOn, final int timeOff, final int repeat) throws CannotExecuteException { Thread t = new Thread(new Runnable() { @Override public void run() { try { setOutputPort(new BitSet()); for (int i = 0; i < repeat; i++) { setOutputPort(ports); Thread.sleep(timeOn * 1000); setOutputPort(new BitSet()); Thread.sleep(timeOff * 1000); } setOutputPort(finalPorts); } catch (InterruptedException e) { logger.warn("Could not complete flash output"); Thread.currentThread().interrupt(); } catch (Exception e) { logger.warn("Could not complete flash output"); } } }); t.start(); }
From source file:org.apache.openjpa.kernel.DetachManager.java
/** * Detach.//from w w w.jav a 2s . c o m */ private Object detachInternal(Object toDetach) { if (toDetach == null) return null; // already detached? if (_detached != null) { Object detached = _detached.get(toDetach); if (detached != null) return detached; } StateManagerImpl sm = _broker.getStateManagerImpl(toDetach, true); if (_call != null && (_call.processArgument(OpCallbacks.OP_DETACH, toDetach, sm) & OpCallbacks.ACT_RUN) == 0) return toDetach; if (sm == null) return toDetach; // Call PreDetach first as we can't tell if the new system // fired an event or just did not fail. _broker.fireLifecycleEvent(toDetach, null, sm.getMetaData(), LifecycleEvent.BEFORE_DETACH); if (!_flushed) { if (_flushBeforeDetach) { // any dirty instances cause a flush to occur flushDirty(sm); } _flushed = true; } BitSet fields = new BitSet(); preDetach(_broker, sm, fields, _full, _reloadOnDetach); // create and store new object before copy to avoid endless recursion PersistenceCapable pc = sm.getPersistenceCapable(); PersistenceCapable detachedPC; if (_copy) detachedPC = pc.pcNewInstance(null, true); else detachedPC = pc; if (_detached != null) _detached.put(toDetach, detachedPC); // detach fields and set detached variables DetachedStateManager detSM = null; if (_opts.getDetachedStateManager() && useDetachedStateManager(sm, _opts) && !(sm.isNew() && !sm.isDeleted() && !sm.isFlushed())) detSM = new DetachedStateManager(detachedPC, sm, fields, _opts.getAccessUnloaded(), _broker.getMultithreaded()); if (_full) { _fullFM.setStateManager(sm); if (_copy || _reloadOnDetach) { _fullFM.detachVersion(); } _fullFM.reproxy(detSM); _fullFM.setStateManager(null); } else { InstanceDetachFieldManager fm = new InstanceDetachFieldManager(detachedPC, detSM); fm.setStateManager(sm); fm.detachFields(fields); } if (!Boolean.FALSE.equals(sm.getMetaData().usesDetachedState())) detachedPC.pcSetDetachedState(getDetachedState(sm, fields)); if (!_copy) sm.release(false, true); if (detSM != null) detachedPC.pcReplaceStateManager(detSM); return detachedPC; }