List of usage examples for java.util BitSet BitSet
private BitSet(long[] words)
From source file:com.joliciel.jochre.graphics.ShapeFillerImplTest.java
@Test public void testFillBitSet(@NonStrict final Shape shape) { final int threshold = 100; final int width = 8; final int height = 8; new NonStrictExpectations() { {// ww w . j av a 2s. co m shape.getHeight(); returns(height); shape.getWidth(); returns(width); int[] pixels = { 0, 1, 1, 0, 0, 1, 1, 1, // row 0 0, 1, 0, 1, 0, 1, 0, 1, // row 1 0, 0, 1, 1, 0, 0, 1, 1, // row 2 0, 0, 1, 1, 0, 1, 1, 0, // row 3 0, 0, 0, 1, 0, 1, 1, 0, // row 4 0, 0, 0, 1, 1, 1, 0, 0, // row 5 0, 0, 1, 0, 1, 0, 0, 0, // row 6 1, 1, 0, 1, 1, 0, 0, 0, // row 7 }; BitSet bitset = new BitSet(height * width); for (int x = -1; x <= width; x++) for (int y = -1; y <= height; y++) { if (x >= 0 && x < width && y >= 0 && y < height && pixels[y * width + x] == 1) bitset.set(y * width + x); shape.isPixelBlack(x, y, threshold); if (x >= 0 && x < width && y >= 0 && y < height) returns(pixels[y * width + x] == 1); else returns(false); if (x >= 0 && x < width && y >= 0 && y < height) { shape.getAbsolutePixel(x, y); if (pixels[y * width + x] == 1) returns(0); else returns(255); } } shape.getBlackAndWhiteBitSet(threshold); returns(bitset); } }; ShapeFillerImpl shapeFiller = new ShapeFillerImpl(); BitSet filledBitSet = shapeFiller.fillBitSet(shape, shape.getBlackAndWhiteBitSet(threshold), 5); for (int y = 0; y < height; y++) { StringBuilder line = new StringBuilder(); for (int x = 0; x < width; x++) { if (filledBitSet.get(y * width + x)) line.append("x"); else line.append("o"); } LOG.debug(line.toString()); } }
From source file:org.apache.pig.backend.local.executionengine.LocalPigLauncher.java
private int runPipeline(POStore[] leaves, PigContext pc) throws IOException, ExecException { BitSet bs = new BitSet(leaves.length); int failed = 0; while (true) { if (bs.cardinality() == leaves.length) { break; }// ww w. j a va 2 s . com for (int i = bs.nextClearBit(0); i < leaves.length; i = bs.nextClearBit(i + 1)) { Result res = leaves[i].getNext(DUMMYTUPLE); switch (res.returnStatus) { case POStatus.STATUS_NULL: // good null from store means keep at it. continue; case POStatus.STATUS_OK: // ok shouldn't happen store should have consumed it. // fallthrough case POStatus.STATUS_ERR: leaves[i].cleanUp(); leaves[i].tearDown(); failed++; failedStores.add(leaves[i].getSFile()); if ("true".equalsIgnoreCase(pc.getProperties().getProperty("stop.on.failure", "false"))) { int errCode = 6017; String msg = "Execution failed, while processing " + leaves[i].getSFile().getFileName(); throw new ExecException(msg, errCode, PigException.REMOTE_ENVIRONMENT); } bs.set(i); break; case POStatus.STATUS_EOP: leaves[i].tearDown(); succeededStores.add(leaves[i].getSFile()); // fallthrough default: bs.set(i); break; } } } return failed; }
From source file:org.apache.hadoop.mapred.split.TestGroupedSplits.java
@Test(timeout = 10000) public void testFormat() throws Exception { JobConf job = new JobConf(defaultConf); Random random = new Random(); long seed = random.nextLong(); LOG.info("seed = " + seed); random.setSeed(seed);/*w w w . ja v a 2s . c o m*/ localFs.delete(workDir, true); FileInputFormat.setInputPaths(job, workDir); final int length = 10000; final int numFiles = 10; createFiles(length, numFiles, random); // create a combined split for the files TextInputFormat wrappedFormat = new TextInputFormat(); wrappedFormat.configure(job); TezGroupedSplitsInputFormat<LongWritable, Text> format = new TezGroupedSplitsInputFormat<LongWritable, Text>(); format.setConf(job); format.setDesiredNumberOfSplits(1); format.setInputFormat(wrappedFormat); LongWritable key = new LongWritable(); Text value = new Text(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(length / 20) + 1; LOG.info("splitting: requesting = " + numSplits); InputSplit[] splits = format.getSplits(job, numSplits); LOG.info("splitting: got = " + splits.length); // we should have a single split as the length is comfortably smaller than // the block size assertEquals("We got more than one splits!", 1, splits.length); InputSplit split = splits[0]; assertEquals("It should be TezGroupedSplit", TezGroupedSplit.class, split.getClass()); // check the split BitSet bits = new BitSet(length); LOG.debug("split= " + split); RecordReader<LongWritable, Text> reader = format.getRecordReader(split, job, voidReporter); try { int count = 0; while (reader.next(key, value)) { int v = Integer.parseInt(value.toString()); LOG.debug("read " + v); if (bits.get(v)) { LOG.warn("conflict with " + v + " at position " + reader.getPos()); } assertFalse("Key in multiple partitions.", bits.get(v)); bits.set(v); count++; } LOG.info("splits=" + split + " count=" + count); } finally { reader.close(); } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }
From source file:org.openecomp.sdnc.sli.aai.AAIRequest.java
public static void setProperties(Properties props, AAIService aaiService) { AAIRequest.configProperties = props; AAIRequest.aaiService = aaiService;//w ww . j a v a 2 s. c o m try { URL url = null; Bundle bundle = FrameworkUtil.getBundle(AAIServiceActivator.class); if (bundle != null) { BundleContext ctx = bundle.getBundleContext(); if (ctx == null) return; url = ctx.getBundle().getResource(AAIService.PATH_PROPERTIES); } else { url = aaiService.getClass().getResource("/aai-path.properties"); } InputStream in = url.openStream(); Reader reader = new InputStreamReader(in, "UTF-8"); Properties properties = new Properties(); properties.load(reader); LOG.info("loaded " + properties.size()); Set<String> keys = properties.stringPropertyNames(); int index = 0; Set<String> resourceNames = new TreeSet<String>(); for (String key : keys) { String[] tags = key.split("\\|"); for (String tag : tags) { if (!resourceNames.contains(tag)) { resourceNames.add(tag); tagValues.put(tag, Integer.toString(++index)); } } BitSet bs = new BitSet(256); for (String tag : tags) { String value = tagValues.get(tag); Integer bitIndex = Integer.parseInt(value); bs.set(bitIndex); } String path = properties.getProperty(key); LOG.info(String.format("bitset %s\t\t%s", bs.toString(), path)); bitsetPaths.put(bs, path); } LOG.info("loaded " + resourceNames.toString()); } catch (Exception e) { LOG.error("Caught exception", e); } }
From source file:org.apache.mahout.benchmark.VectorBenchmarks.java
private void setUpVectors(int cardinality, int numNonZeros, int numVectors) { for (int i = 0; i < numVectors; i++) { Vector v = new SequentialAccessSparseVector(cardinality, numNonZeros); // sparsity! BitSet featureSpace = new BitSet(cardinality); int[] indexes = new int[numNonZeros]; double[] values = new double[numNonZeros]; int j = 0; while (j < numNonZeros) { double value = r.nextGaussian(); int index = r.nextInt(cardinality); if (!featureSpace.get(index) && value != 0) { featureSpace.set(index); indexes[j] = index;//from w w w .j a va 2 s .c o m values[j++] = value; v.set(index, value); } } randomVectorIndices.add(indexes); randomVectorValues.add(values); randomVectors.add(v); } }
From source file:org.springframework.kafka.listener.KafkaMessageListenerContainerTests.java
@Test public void testSlowListener() throws Exception { logger.info("Start " + this.testName.getMethodName()); Map<String, Object> props = KafkaTestUtils.consumerProps("slow1", "false", embeddedKafka); // props.put(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG, 6); // 2 per poll DefaultKafkaConsumerFactory<Integer, String> cf = new DefaultKafkaConsumerFactory<Integer, String>(props); ContainerProperties containerProps = new ContainerProperties(topic1); final CountDownLatch latch = new CountDownLatch(6); final BitSet bitSet = new BitSet(6); containerProps.setMessageListener((MessageListener<Integer, String>) message -> { logger.info("slow1: " + message); bitSet.set((int) (message.partition() * 3 + message.offset())); try {//w w w .j a v a 2 s. c o m Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } latch.countDown(); }); containerProps.setPauseAfter(100); KafkaMessageListenerContainer<Integer, String> container = new KafkaMessageListenerContainer<>(cf, containerProps); container.setBeanName("testSlow1"); container.start(); Consumer<?, ?> consumer = spyOnConsumer(container); ContainerTestUtils.waitForAssignment(container, embeddedKafka.getPartitionsPerTopic()); Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka); ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<Integer, String>(senderProps); KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf); template.setDefaultTopic(topic1); template.sendDefault(0, "foo"); template.sendDefault(2, "bar"); template.sendDefault(0, "baz"); template.sendDefault(2, "qux"); template.flush(); Thread.sleep(300); template.sendDefault(0, "fiz"); template.sendDefault(2, "buz"); template.flush(); assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue(); assertThat(bitSet.cardinality()).isEqualTo(6); verify(consumer, atLeastOnce()).pause(anyObject()); verify(consumer, atLeastOnce()).resume(anyObject()); container.stop(); logger.info("Stop " + this.testName.getMethodName()); }
From source file:org.apache.hyracks.dataflow.std.join.OptimizedHybridHashJoin.java
public OptimizedHybridHashJoin(IHyracksTaskContext ctx, int memForJoin, int numOfPartitions, String probeRelName, String buildRelName, int[] probeKeys, int[] buildKeys, IBinaryComparator[] comparators, RecordDescriptor probeRd, RecordDescriptor buildRd, ITuplePartitionComputer probeHpc, ITuplePartitionComputer buildHpc, IPredicateEvaluator predEval, boolean isLeftOuter, IMissingWriterFactory[] nullWriterFactories1) { this.ctx = ctx; this.memForJoin = memForJoin; this.buildRd = buildRd; this.probeRd = probeRd; this.buildHpc = buildHpc; this.probeHpc = probeHpc; this.buildKeys = buildKeys; this.probeKeys = probeKeys; this.comparators = comparators; this.buildRelName = buildRelName; this.probeRelName = probeRelName; this.numOfPartitions = numOfPartitions; this.buildRFWriters = new RunFileWriter[numOfPartitions]; this.probeRFWriters = new RunFileWriter[numOfPartitions]; this.accessorBuild = new FrameTupleAccessor(buildRd); this.accessorProbe = new FrameTupleAccessor(probeRd); this.predEvaluator = predEval; this.isLeftOuter = isLeftOuter; this.isReversed = false; this.spilledStatus = new BitSet(numOfPartitions); this.nonMatchWriters = isLeftOuter ? new IMissingWriter[nullWriterFactories1.length] : null; if (isLeftOuter) { for (int i = 0; i < nullWriterFactories1.length; i++) { nonMatchWriters[i] = nullWriterFactories1[i].createMissingWriter(); }/*from w w w .j a v a2 s. c o m*/ } }
From source file:org.apache.kylin.invertedindex.model.IIDesc.java
public void init(MetadataManager metadataManager) { config = metadataManager.getConfig(); if (this.modelName == null || this.modelName.length() == 0) { throw new RuntimeException("The cubeDesc '" + this.getName() + "' doesn't have data model specified."); }// w w w . j a v a 2 s.c o m this.model = MetadataManager.getInstance(config).getDataModelDesc(this.modelName); if (this.model == null) { throw new RuntimeException("No data model found with name '" + modelName + "'."); } timestampDimension = timestampDimension.toUpperCase(); // capitalize IIDimension.capicalizeStrings(bitmapDimensions); IIDimension.capicalizeStrings(valueDimensions); StringUtil.toUpperCaseArray(metricNames, metricNames); // retrieve all columns and all tables, and make available measure to ii HashSet<String> allTableNames = Sets.newHashSet(); measureDescs = Lists.newArrayList(); measureDescs.add(makeCountMeasure()); for (IIDimension iiDimension : Iterables.concat(bitmapDimensions, valueDimensions)) { TableDesc tableDesc = this.getTableDesc(iiDimension.getTable()); for (String column : iiDimension.getColumns()) { ColumnDesc columnDesc = tableDesc.findColumnByName(column); allColumns.add(new TblColRef(columnDesc)); measureDescs.add(makeHLLMeasure(columnDesc, null)); } if (!allTableNames.contains(tableDesc.getIdentity())) { allTableNames.add(tableDesc.getIdentity()); allTables.add(tableDesc); } } for (String column : metricNames) { TableDesc tableDesc = this.getTableDesc(this.getFactTableName()); ColumnDesc columnDesc = tableDesc.findColumnByName(column); allColumns.add(new TblColRef(columnDesc)); measureDescs.add(makeNormalMeasure("SUM", columnDesc)); measureDescs.add(makeNormalMeasure("MIN", columnDesc)); measureDescs.add(makeNormalMeasure("MAX", columnDesc)); if (!allTableNames.contains(tableDesc.getIdentity())) { allTableNames.add(tableDesc.getIdentity()); allTables.add(tableDesc); } } // indexing for each type of columns bitmapCols = new int[IIDimension.getColumnCount(bitmapDimensions)]; valueCols = new int[IIDimension.getColumnCount(valueDimensions)]; metricsCols = new int[metricNames.length]; metricsColSet = new BitSet(this.getTableDesc(this.getFactTableName()).getColumnCount()); int totalIndex = 0; for (int i = 0; i < bitmapCols.length; ++i, ++totalIndex) { bitmapCols[i] = totalIndex; } for (int i = 0; i < valueCols.length; ++i, ++totalIndex) { valueCols[i] = totalIndex; } for (int i = 0; i < metricsCols.length; ++i, ++totalIndex) { metricsCols[i] = totalIndex; metricsColSet.set(totalIndex); } // partitioning column tsCol = -1; for (int i = 0; i < allColumns.size(); ++i) { TblColRef col = allColumns.get(i); if (col.isSameAs(this.getFactTableName(), this.timestampDimension)) { tsCol = i; break; } } if (tsCol < 0) throw new RuntimeException("timestamp_dimension is not in bitmapDimensions or valueDimensions"); }
From source file:com.netspective.commons.acl.AccessControlListTest.java
/** * This test makes sure that an ACL is read properly from a file containing just a single <access-control-list> * tag with the default name of "acl"/*from w ww . j a v a 2 s .co m*/ */ public void testSingleACLDataModelSchemaImportFromXmlValid() throws PermissionNotFoundException, DataModelException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException, RoleNotFoundException { AccessControlListsComponent aclc = (AccessControlListsComponent) XdmComponentFactory.get( AccessControlListsComponent.class, new Resource(AccessControlListTest.class, RESOURCE_NAME_ONE), XdmComponentFactory.XDMCOMPFLAGS_DEFAULT); // Verify _something_ was loaded... assertNotNull(aclc); // Verify exactly _one_ ACL was loaded... AccessControlListsManager aclm = aclc.getItems(); assertNotNull("Expected: AccessControlListsManager object, Found: null", aclm); AccessControlLists acls = aclm.getAccessControlLists(); Integer expectedNumACLs = new Integer(1); assertNotNull("Expected: AccessControlLists object, Found: null", acls); assertEquals("Expected: " + expectedNumACLs + " ACL, Found: " + acls.size(), expectedNumACLs.intValue(), acls.size()); // Verify the defaultAcl and the acl named "acl" are the same AccessControlList defaultAcl = aclm.getDefaultAccessControlList(); AccessControlList aclAcl = aclm.getAccessControlList("acl"); assertNotNull("Expected: Non-Null Default ACL, Found: null", defaultAcl); assertNotNull("Expected: Non-Null Default ACL, Found: null", aclAcl); assertEquals("Expected: ACL with name 'acl', Found: ACL with name " + defaultAcl.getName(), aclAcl, defaultAcl); // Verify number of permissions Map aclPermissions = defaultAcl.getPermissionsByName(); assertEquals("Expected: Total permissions = 7, Found: Total permissions = " + aclPermissions.size(), 7, aclPermissions.size()); // Verify number of roles Map aclRoles = defaultAcl.getRolesByName(); assertEquals("Expected: Total roles = 3, Found: Total roles = " + aclRoles.size(), 3, aclRoles.size()); // Verify the index of the /acl/role/normal-user permission is 2 Role normalUser = defaultAcl.getRole("/acl/role/normal-user"); assertEquals("Expected: Id for /acl/role/normal-user = 2, Found: " + normalUser.getId(), 2, normalUser.getId()); // Verify the set of permissions for /acl/role/normal-user are exactly what we expect BitSet normalUserPermissionSet = normalUser.getPermissions(); BitSet expectedPermissionSet = new BitSet(11); expectedPermissionSet.set(1); expectedPermissionSet.set(2); expectedPermissionSet.set(3); expectedPermissionSet.set(4); expectedPermissionSet.set(5); assertEquals("Expected: Permissions for /acl/role/normal-user = " + expectedPermissionSet + ", Found: " + normalUserPermissionSet, expectedPermissionSet, normalUserPermissionSet); aclc.printErrorsAndWarnings(); }
From source file:org.apache.openjpa.datacache.AbstractDataCache.java
public BitSet containsAll(Collection<Object> keys) { if (keys.isEmpty()) return EMPTY_BITSET; BitSet set = new BitSet(keys.size()); int i = 0;/*w ww . ja v a 2s . com*/ for (Iterator<Object> iter = keys.iterator(); iter.hasNext(); i++) if (contains(iter.next())) set.set(i); return set; }