List of usage examples for java.util BitSet get
public boolean get(int bitIndex)
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef, MutableInt currentClusterId) {//from www. j av a2 s . c o m // only replicate operator has multiple outputs int outputIndex = 0; if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE) { ReplicateOperator rop = (ReplicateOperator) opRef.getValue(); List<Mutable<ILogicalOperator>> outputs = rop.getOutputs(); for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) { if (outputs.get(outputIndex).equals(parentRef)) { break; } } } AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue(); Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue()); List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); if (labels.second[outputIndex] == 1 && labels.first[i] == 0) { // 1 -> 0 if (labels.second.length == 1) { clusterMap.put(opRef, currentClusterId); // start a new cluster MutableInt newClusterId = new MutableInt(++lastUsedClusterId); computeClusters(opRef, inputRef, newClusterId); BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue()); if (waitForList == null) { waitForList = new BitSet(); clusterWaitForMap.put(currentClusterId.getValue(), waitForList); } waitForList.set(newClusterId.getValue()); } } else { // 0 -> 0 and 1 -> 1 MutableInt prevClusterId = clusterMap.get(opRef); if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) { clusterMap.put(opRef, currentClusterId); computeClusters(opRef, inputRef, currentClusterId); } else { // merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId for (BitSet bs : clusterWaitForMap.values()) { if (bs.get(currentClusterId.getValue())) { bs.clear(currentClusterId.getValue()); bs.set(prevClusterId.getValue()); } } currentClusterId.setValue(prevClusterId.getValue()); } } } }
From source file:org.rifidi.edge.adapter.alien.Alien9800ReaderSession.java
/** * This method sets the External Output high for the given ports * /*from www . jav a 2 s . c o m*/ * @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:net.solarnetwork.node.control.modbus.toggle.ModbusToggler.java
/** * Get the values of the discreet values, as a Boolean. * //from www . java 2 s . c o m * @return Boolean for the switch status */ private synchronized Boolean currentValue() throws IOException { BitSet result = performAction(new ModbusConnectionAction<BitSet>() { @Override public BitSet doWithConnection(ModbusConnection conn) throws IOException { return conn.readDiscreetValues(new Integer[] { address }, 1); } }); if (log.isInfoEnabled()) { log.info("Read {} value: {}", controlId, result.get(0)); } return result.get(0); }
From source file:no.ntnu.idi.socialhitchhiking.utility.ShareOnFacebook.java
@SuppressWarnings("deprecation") @Override//www . j av a 2 s .co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentRoute = getApp().getSelectedRoute(); facebook = new Facebook(APP_ID); restoreCredentials(facebook); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.facebook_dialog); //Intitialize TripOption string values String formatedDate = formatDate(getApp().getSelectedJourney().getStart()); String formatedTime = formatTime(getApp().getSelectedJourney().getStart()); date = "Date: " + formatedDate; time = "Start time: " + formatedTime; seats = "Seats available: " + getApp().getSelectedJourney().getTripPreferences().getSeatsAvailable(); // String extras = "Extras: "+ getApp().getSelectedJourney().getTripPreferences().toString(); BitSet sExtras = getApp().getSelectedJourney().getTripPreferences().getExtras(); extras = "Preferences: "; String[] items = { "Music", "Animals", "Breaks", "Talking", "Smoking" }; for (int i = 0; i < sExtras.length(); i++) { if (sExtras.get(i)) { if (i == sExtras.length() - 1) extras = extras + items[i] + "."; else { if (i == sExtras.length() - 2) extras = extras + items[i] + " and "; else extras = extras + items[i] + ", "; } } } String facebookMessage = ""; isDriver = getIntent().getExtras().getBoolean("isDriver"); if (isDriver) { facebookMessage = "I have created a new drive on FreeRider\n" + date + "\n" + time + "\n" + seats + "\n" + extras; } else { facebookMessage = "I am hitchhiking on a new ride on FreeRider\n" + date + "\n" + time + "\n" + seats + "\n" + extras; ; } messageToPost = facebookMessage; }
From source file:org.jax.haplotype.analysis.EMMAAssociationTest.java
/** * Perform a scan on the given chromosome using EMMA * @param chrDataSource//from ww w . j av a 2 s.c om * the chromosome data source * @param phenotypeDataSource * the phenotype data source * @param kinship * the kinship matrix (if null it's calculated based on data) * @return * the p-values * @throws IOException */ public double[] emmaScan(ChromosomeDataSource chrDataSource, PhenotypeDataSource phenotypeDataSource, double[] kinship) throws IOException { int snpCount = (int) chrDataSource.getSnpPositionInputStream().getSnpCount(); Map<String, List<Double>> phenotypeDataMap = phenotypeDataSource.getPhenotypeData(); phenotypeDataMap.keySet().retainAll(chrDataSource.getAvailableStrains()); String[] commonStrains = phenotypeDataMap.keySet().toArray(new String[0]); Arrays.sort(commonStrains); int strainCount = commonStrains.length; String[] sortedCommonStrains = phenotypeDataMap.keySet().toArray(new String[phenotypeDataMap.size()]); Arrays.sort(sortedCommonStrains); double[] genos = new double[snpCount * strainCount]; SdpInputStream sdpStream = chrDataSource.getSdpInputStream(commonStrains); // TODO FIXME for (int snpIndex = 0; snpIndex < snpCount; snpIndex++) { BitSet currSDP = sdpStream.getNextSdp(); for (int strainIndex = 0; strainIndex < strainCount; strainIndex++) { double currCall = currSDP.get(strainIndex) ? 1.0 : 0.0; genos[snpIndex * strainCount + strainIndex] = currCall; } } if (kinship == null) { kinship = calculateKinship(strainCount, genos); } double[] phenotypeMeans = new double[strainCount]; for (int strainIndex = 0; strainIndex < strainCount; strainIndex++) { phenotypeMeans[strainIndex] = StatisticUtilities .calculateMean(phenotypeDataMap.get(commonStrains[strainIndex])); } return emmaScan(strainCount, phenotypeMeans, genos, kinship); }
From source file:org.jax.haplotype.analysis.EMMAAssociationTest.java
/** * Calculate the kinship values//from w ww . j ava 2 s .c o m * @param genoData * the genotype data to base it on * @param strains * a map of strain names * @return * the kinship * @throws * IOException */ public double[] calculateKinship(GenomeDataSource genoData, Set<String> strains) throws IOException { strains = new HashSet<String>(strains); strains.retainAll(genoData.getAvailableStrains()); String[] commonStrains = strains.toArray(new String[0]); Arrays.sort(commonStrains); int strainCount = commonStrains.length; int snpCount = 0; for (ChromosomeDataSource currChr : genoData.getChromosomeDataSources().values()) { snpCount += currChr.getSnpPositionInputStream().getSnpCount(); } double[] genos = new double[snpCount * strainCount]; int currStartIndex = 0; for (ChromosomeDataSource currChr : genoData.getChromosomeDataSources().values()) { SdpInputStream sdpStream = currChr.getSdpInputStream(commonStrains); int currSnpCount = (int) currChr.getSnpPositionInputStream().getSnpCount(); for (int i = 0; i < currSnpCount; i++) { int currSnp = currStartIndex + i; BitSet currSdp = sdpStream.getNextSdp(); for (int strainIndex = 0; strainIndex < strainCount; strainIndex++) { double currCall = currSdp.get(strainIndex) ? 1.0 : 0.0; genos[currSnp * strainCount + strainIndex] = currCall; } } } return calculateKinship(strainCount, genos); }
From source file:org.apache.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef, MutableInt currentClusterId) {/*from www .j av a 2 s . c o m*/ // only replicate operator has multiple outputs int outputIndex = 0; if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE) { ReplicateOperator rop = (ReplicateOperator) opRef.getValue(); List<Mutable<ILogicalOperator>> outputs = rop.getOutputs(); for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) { if (outputs.get(outputIndex).equals(parentRef)) { break; } } } AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue(); Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue()); List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); if (labels.second[outputIndex] == 1 && labels.first[i] == 0) { // 1 -> 0 if (labels.second.length == 1) { clusterMap.put(opRef, currentClusterId); // start a new cluster MutableInt newClusterId = new MutableInt(++lastUsedClusterId); computeClusters(opRef, inputRef, newClusterId); BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue()); if (waitForList == null) { waitForList = new BitSet(); clusterWaitForMap.put(currentClusterId.getValue(), waitForList); } waitForList.set(newClusterId.getValue()); } } else { // 0 -> 0 and 1 -> 1 MutableInt prevClusterId = clusterMap.get(opRef); if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) { clusterMap.put(opRef, currentClusterId); computeClusters(opRef, inputRef, currentClusterId); } else { // merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId for (BitSet bs : clusterWaitForMap.values()) { if (bs.get(currentClusterId.getValue())) { bs.clear(currentClusterId.getValue()); bs.set(prevClusterId.getValue()); } } clusterWaitForMap.remove(currentClusterId.getValue()); currentClusterId.setValue(prevClusterId.getValue()); } } } }
From source file:com.rockagen.commons.util.CommUtil.java
/** * Create a BitSet instance,start index is 0 * <p>/* ww w . jav a 2 s.c o m*/ * example: * </p> * <pre> * byte: 50 * binary: 0b110010 * bitSet.toString(): {2, 3, 6} * * +--------+---+---+---+---+---+---+---+---+ * | bitset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * +--------+---+---+---+---+---+---+---+---+ * | bits | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | * +--------+---+---+---+---+---+---+---+---+ * * </pre> * * @param bitSet BitSet * @return bytes */ public static byte[] bitValue(BitSet bitSet) { if (bitSet == null) { return null; } byte[] bytes = new byte[bitSet.size() / 8]; int index, offset; for (int i = 0; i < bitSet.size(); i++) { index = i / 8; offset = 7 - i % 8; bytes[index] |= (bitSet.get(i) ? 1 : 0) << offset; } return bytes; }
From source file:au.org.ala.delta.io.BinaryKeyFile.java
protected List<Integer> bitSetToInts(BitSet set, int numValues) { List<Integer> values = new ArrayList<Integer>(); int i = 0;/* w w w.j av a 2 s.c o m*/ while (i < numValues) { int value = 0; while (i < numValues && (i - 32 * values.size()) / 32 == 0) { if (set.get(i)) { value |= 1 << i % 32; } i++; } values.add(value); } return values; }
From source file:org.rifidi.edge.adapter.awid.awid2010.gpio.AwidGPIOSession.java
/** * //w w w.j av a2s. c om * @param ports * @param finalPorts * @param timeOn * @param timeOff * @param repeat * @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 { for (int i = 0; i < 4; i++) { if (ports.get(i)) { flashOutputPort((byte) i, (byte) timeOn, (byte) timeOff, (byte) repeat); } } setOutputPort(finalPorts); } catch (CannotExecuteException e) { logger.warn("Cannot Flash Output: " + e.getMessage()); } } }); t.start(); }