List of usage examples for java.util BitSet set
public void set(int fromIndex, int toIndex)
From source file:org.caleydo.vis.lineup.model.CategoricalRankColumnModel.java
@Override protected void updateMask(BitSet todo, List<IRow> data, BitSet mask) { for (int i = todo.nextSetBit(0); i >= 0; i = todo.nextSetBit(i + 1)) { CATEGORY_TYPE v = this.data.apply(data.get(i)); if (v == null && filterNA) mask.set(i, false); else/*w ww . ja v a 2 s . c o m*/ mask.set(i, v == null ? true : selection.contains(v)); } }
From source file:at.tuwien.mnsa.smssender.SMSPDUConverter.java
/** * Right shift a bitset/* w ww . j ava 2 s .c o m*/ * @param bitset * @param positions * @return */ private BitSet rightShiftBitset(BitSet bitset, int positions) { for (int j = 0; j < positions; j++) { for (int i = bitset.length(); i > 0; i--) { bitset.set(i, bitset.get(i - 1)); } bitset.set(j, false); } return bitset; }
From source file:org.caleydo.vis.lineup.model.MultiCategoricalRankColumnModel.java
@Override protected void updateMask(BitSet todo, List<IRow> data, BitSet mask) { for (int i = todo.nextSetBit(0); i >= 0; i = todo.nextSetBit(i + 1)) { Set<CATEGORY_TYPE> v = this.data.apply(data.get(i)); if ((v == null || v.isEmpty()) && filterNA) mask.set(i, false); else//from w ww.j a va 2 s .c om mask.set(i, v == null ? true : Iterables.any(v, Predicates.in(selection))); } }
From source file:com.joliciel.jochre.graphics.VectorizerImplTest.java
@Test public void testGetLongestLines(@NonStrict final Shape shape) { final int threshold = 100; final int maxLines = 60; final int whiteGapFillFactor = 5; new NonStrictExpectations() { {// ww w . java 2 s . com shape.getHeight(); returns(8); shape.getWidth(); returns(8); int[] pixels = { 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 }; for (int x = -1; x <= 8; x++) for (int y = -1; y <= 8; y++) { shape.isPixelBlack(x, y, threshold, whiteGapFillFactor); if (x >= 0 && x < 8 && y >= 0 && y < 8) returns(pixels[y * 8 + x] == 1); else returns(false); } } }; BitSet outline = new BitSet(64); int[] outlinePixels = { 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 }; for (int x = 0; x < 8; x++) for (int y = 0; y < 8; y++) { outline.set(y * 8 + x, outlinePixels[y * 8 + x] == 1); } VectorizerImpl vectorizer = new VectorizerImpl(); GraphicsServiceInternal graphicsService = new GraphicsServiceImpl(); vectorizer.setGraphicsService(graphicsService); vectorizer.setWhiteGapFillFactor(whiteGapFillFactor); List<LineSegment> lines = vectorizer.getLongestLines(shape, outline, maxLines, threshold); assertEquals(maxLines, lines.size()); }
From source file:at.tuwien.mnsa.smssender.SMSPDUConverter.java
/** * Add a byte to a bitset/*from w ww. j av a2s . c o m*/ * @param b the byte * @param bitset the bitset * @param startpositionBitset where to start inserting in the bitset * @param startpositionByte where to start inserting from the byte * @param len how many bits of the byte have to be inserted */ private void addByteToBitset(byte b, BitSet bitset, int startpositionBitset, int startpositionByte, int len) { b = (byte) (b << startpositionByte); for (int i = startpositionByte; i < (startpositionByte + len); i++) { boolean bit = (b & 0x80) != 0; bitset.set(startpositionBitset + (i - startpositionByte), bit); //set the most significant bit of the byte; 0x80 == 1000.000 b = (byte) (b << 1); } }
From source file:flink.iso8583.MessageFactory.java
/** Creates a new message instance from the buffer, which must contain a valid ISO8583 * message. If the factory is set to use binary messages then it will try to parse * a binary message./* w w w . j a va2s . c o m*/ * @param buf The byte buffer containing the message. Must not include the length header. * @param isoHeaderLength The expected length of the ISO header, after which the message type * and the rest of the message must come. */ public IsoMessage parseMessage(byte[] buf, int isoHeaderLength) throws ParseException { IsoMessage m = new IsoMessage(isoHeaderLength > 0 ? new String(buf, 0, isoHeaderLength) : null); //TODO it only parses ASCII messages for now int type = 0; if (useBinary) { type = ((buf[isoHeaderLength] & 0xff) << 8) | (buf[isoHeaderLength + 1] & 0xff); } else { type = ((buf[isoHeaderLength] - 48) << 12) | ((buf[isoHeaderLength + 1] - 48) << 8) | ((buf[isoHeaderLength + 2] - 48) << 4) | (buf[isoHeaderLength + 3] - 48); } m.setType(type); //Parse the bitmap (primary first) BitSet bs = new BitSet(64); int pos = 0; if (useBinary) { for (int i = isoHeaderLength + 2; i < isoHeaderLength + 10; i++) { int bit = 128; for (int b = 0; b < 8; b++) { bs.set(pos++, (buf[i] & bit) != 0); bit >>= 1; } } //Check for secondary bitmap and parse if necessary if (bs.get(0)) { for (int i = isoHeaderLength + 10; i < isoHeaderLength + 18; i++) { int bit = 128; for (int b = 0; b < 8; b++) { bs.set(pos++, (buf[i] & bit) != 0); bit >>= 1; } } pos = 18 + isoHeaderLength; } else { pos = 10 + isoHeaderLength; } } else { for (int i = isoHeaderLength + 4; i < isoHeaderLength + 20; i++) { int hex = Integer.parseInt(new String(buf, i, 1), 16); bs.set(pos++, (hex & 8) > 0); bs.set(pos++, (hex & 4) > 0); bs.set(pos++, (hex & 2) > 0); bs.set(pos++, (hex & 1) > 0); } //Check for secondary bitmap and parse it if necessary if (bs.get(0)) { for (int i = isoHeaderLength + 20; i < isoHeaderLength + 36; i++) { int hex = Integer.parseInt(new String(buf, i, 1), 16); bs.set(pos++, (hex & 8) > 0); bs.set(pos++, (hex & 4) > 0); bs.set(pos++, (hex & 2) > 0); bs.set(pos++, (hex & 1) > 0); } pos = 36 + isoHeaderLength; } else { pos = 20 + isoHeaderLength; } } //Parse each field Integer itype = new Integer(type); Map parseGuide = (Map) parseMap.get(itype); List index = (List) parseOrder.get(itype); for (Iterator iter = index.iterator(); iter.hasNext();) { Integer i = (Integer) iter.next(); FieldParseInfo fpi = (FieldParseInfo) parseGuide.get(i); if (bs.get(i.intValue() - 1)) { IsoValue val = useBinary ? fpi.parseBinary(buf, pos) : fpi.parse(buf, pos); m.setField(i.intValue(), val); if (useBinary && !(val.getType() == IsoType.ALPHA || val.getType() == IsoType.LLVAR || val.getType() == IsoType.LLLVAR)) { pos += (val.getLength() / 2) + (val.getLength() % 2); } else { pos += val.getLength(); } if (val.getType() == IsoType.LLVAR) { pos += useBinary ? 1 : 2; } else if (val.getType() == IsoType.LLLVAR) { pos += useBinary ? 2 : 3; } } } return m; }
From source file:org.intermine.bio.postprocess.CreateIntronFeaturesProcess.java
/** * Return a set of Intron objects that don't overlap the Locations * in the locationSet argument. The caller must call ObjectStoreWriter.store() on the * Intron, its chromosomeLocation and the synonym in the synonyms collection. * @param locationSet a set of Locations for the exons on a particular transcript * @param transcript Transcript that the Locations refer to * @param tranLoc The Location of the Transcript * @param gene gene for the transcript//w w w. j a v a2 s .com * @return a set of Intron objects * @throws ObjectStoreException if there is an ObjectStore problem */ protected int createIntronFeatures(Set<Location> locationSet, SequenceFeature transcript, Location tranLoc, Gene gene) throws ObjectStoreException { if (locationSet.size() == 1 || tranLoc == null || transcript == null || transcript.getLength() == null) { return 0; } final BitSet bs = new BitSet(transcript.getLength().intValue()); Chromosome chr = transcript.getChromosome(); int tranStart = tranLoc.getStart().intValue(); for (Location location : locationSet) { bs.set(location.getStart().intValue() - tranStart, (location.getEnd().intValue() - tranStart) + 1); } int prevEndPos = 0; int intronCount = 0; while (prevEndPos != -1) { intronCount++; int nextIntronStart = bs.nextClearBit(prevEndPos + 1); int intronEnd; int nextSetBit = bs.nextSetBit(nextIntronStart); if (nextSetBit == -1) { intronEnd = transcript.getLength().intValue(); } else { intronEnd = nextSetBit - 1; } if (nextSetBit == -1 || intronCount == (locationSet.size() - 1)) { prevEndPos = -1; } else { prevEndPos = intronEnd; } int newLocStart = nextIntronStart + tranStart; int newLocEnd = intronEnd + tranStart; String identifier = "intron_chr" + chr.getPrimaryIdentifier() + "_" + Integer.toString(newLocStart) + ".." + Integer.toString(newLocEnd); if (intronMap.get(identifier) == null) { Class<?> intronCls = model.getClassDescriptorByName("Intron").getType(); Intron intron = (Intron) DynamicUtil.createObject(Collections.singleton(intronCls)); Location location = (Location) DynamicUtil.createObject(Collections.singleton(Location.class)); intron.setChromosome(chr); intron.setOrganism(chr.getOrganism()); intron.addDataSets(dataSet); intron.setPrimaryIdentifier(identifier); intron.setGenes(Collections.singleton(gene)); location.setStart(new Integer(newLocStart)); location.setEnd(new Integer(newLocEnd)); location.setStrand(tranLoc.getStrand()); location.setFeature(intron); location.setLocatedOn(transcript); location.addDataSets(dataSet); intron.setChromosomeLocation(location); osw.store(location); int length = location.getEnd().intValue() - location.getStart().intValue() + 1; intron.setLength(new Integer(length)); addToIntronTranscripts(intron, transcript); intronMap.put(identifier, intron); } else { SequenceFeature intron = intronMap.get(identifier); addToIntronTranscripts(intron, transcript); intronMap.put(identifier, intron); } } return intronCount; }
From source file:net.solarnetwork.node.control.sma.pcm.ModbusPCMController.java
private synchronized boolean setPCMStatus(Integer desiredValue) { final BitSet bits = new BitSet(4); final int v = desiredValue; for (int i = 0; i < 4; i++) { bits.set(i, ((v >> i) & 1) == 1); }//from w w w . j a va 2 s . c o m log.info("Setting PCM status to {} ({}%)", desiredValue, percentValueForIntegerValue(desiredValue)); final Integer[] addresses = new Integer[] { d1Address, d2Address, d3Address, d4Address }; try { return performAction(new ModbusConnectionAction<Boolean>() { @Override public Boolean doWithConnection(ModbusConnection conn) throws IOException { return conn.writeDiscreetValues(addresses, bits); } }); } catch (IOException e) { log.error("Error communicating with PCM: {}", e.getMessage()); } return false; }
From source file:eu.crisis_economics.utilities.EnumDistribution.java
public static <T extends Enum<T>> EnumDistribution<T> // Immutable create(Class<T> token, String sourceFile) throws IOException { if (token == null) throw new NullArgumentException(); if (!token.isEnum()) throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum."); if (token.getEnumConstants().length == 0) throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum."); EnumDistribution<T> result = new EnumDistribution<T>(); result.values = token.getEnumConstants(); result.probabilities = new EnumMap<T, Double>(token); Map<String, T> converter = new HashMap<String, T>(); final int numberOfValues = result.values.length; int[] valueIndices = new int[numberOfValues]; double[] valueProbabilities = new double[numberOfValues]; BitSet valueIsComitted = new BitSet(numberOfValues); {/* w ww . ja v a 2 s . c o m*/ int counter = 0; for (T value : result.values) { valueIndices[counter] = counter++; result.probabilities.put(value, 0.); converter.put(value.name(), value); } } BufferedReader reader = new BufferedReader(new FileReader(sourceFile)); try { String newLine; while ((newLine = reader.readLine()) != null) { if (newLine.isEmpty()) continue; StringTokenizer tokenizer = new StringTokenizer(newLine); final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t"); if (tokenizer.hasMoreTokens()) throw new ParseException( "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0); final double p = Double.parseDouble(pStr); if (p < 0. || p > 1.) throw new IOException(pStr + " is not a valid probability for the value " + name); result.probabilities.put(converter.get(name), p); final int ordinal = converter.get(name).ordinal(); if (valueIsComitted.get(ordinal)) throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0); valueProbabilities[converter.get(name).ordinal()] = p; valueIsComitted.set(ordinal, true); } { // Check sum of probabilities double sum = 0.; for (double p : valueProbabilities) sum += p; if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.)) throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting " + "probaility sum (value " + sum + ") is not equal to 1."); } } catch (Exception e) { throw new IOException(e.getMessage()); } finally { reader.close(); } result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities); return result; }
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 a2 s . c o m } } 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); } }