List of usage examples for java.util BitSet BitSet
private BitSet(long[] words)
From source file:org.apache.flink.streaming.connectors.kafka.KafkaITCase.java
@Test public void tupleTestTopology() throws Exception { LOG.info("Starting KafkaITCase.tupleTestTopology()"); String topic = "tupleTestTopic"; createTestTopic(topic, 1, 1);// w w w . j a v a 2s .c o m final StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironment(1); // add consuming topology: DataStreamSource<Tuple2<Long, String>> consuming = env .addSource(new PersistentKafkaSource<Tuple2<Long, String>>(topic, new Utils.TypeInformationSerializationSchema<Tuple2<Long, String>>( new Tuple2<Long, String>(1L, ""), env.getConfig()), standardCC)); consuming.addSink(new RichSinkFunction<Tuple2<Long, String>>() { private static final long serialVersionUID = 1L; int elCnt = 0; int start = -1; BitSet validator = new BitSet(101); @Override public void invoke(Tuple2<Long, String> value) throws Exception { LOG.info("Got value " + value); String[] sp = value.f1.split("-"); int v = Integer.parseInt(sp[1]); assertEquals(value.f0 - 1000, (long) v); if (start == -1) { start = v; } Assert.assertFalse("Received tuple twice", validator.get(v - start)); validator.set(v - start); elCnt++; if (elCnt == 100) { // check if everything in the bitset is set to true int nc; if ((nc = validator.nextClearBit(0)) != 100) { throw new RuntimeException("The bitset was not set to 1 on all elements. Next clear:" + nc + " Set: " + validator); } throw new SuccessException(); } } @Override public void close() throws Exception { super.close(); Assert.assertTrue("No element received", elCnt > 0); } }); // add producing topology DataStream<Tuple2<Long, String>> stream = env.addSource(new SourceFunction<Tuple2<Long, String>>() { private static final long serialVersionUID = 1L; boolean running = true; @Override public void run(SourceContext<Tuple2<Long, String>> ctx) throws Exception { LOG.info("Starting source."); int cnt = 0; while (running) { ctx.collect(new Tuple2<Long, String>(1000L + cnt, "kafka-" + cnt++)); LOG.info("Produced " + cnt); try { Thread.sleep(100); } catch (InterruptedException ignored) { } } } @Override public void cancel() { LOG.info("Source got cancel()"); running = false; } }); stream.addSink(new KafkaSink<Tuple2<Long, String>>(brokerConnectionStrings, topic, new Utils.TypeInformationSerializationSchema<Tuple2<Long, String>>(new Tuple2<Long, String>(1L, ""), env.getConfig()))); tryExecute(env, "tupletesttopology"); LOG.info("Finished KafkaITCase.tupleTestTopology()"); }
From source file:org.alfresco.module.org_alfresco_module_rm.capability.RMAfterInvocationProvider.java
private Object[] decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object[] returnedObject) { // Assumption: value is not null BitSet incudedSet = new BitSet(returnedObject.length); List<ConfigAttributeDefintion> supportedDefinitions = extractSupportedDefinitions(config); if (supportedDefinitions.size() == 0) { return returnedObject; }// w w w.j ava 2 s .c o m for (int i = 0, l = returnedObject.length; i < l; i++) { Object current = returnedObject[i]; int parentReadCheck = checkRead(getParentReadCheckNode(current)); int childReadChek = checkRead(getChildReadCheckNode(current)); for (ConfigAttributeDefintion cad : supportedDefinitions) { incudedSet.set(i, true); NodeRef testNodeRef = null; if (cad.parent) { if (StoreRef.class.isAssignableFrom(current.getClass())) { testNodeRef = null; } else if (NodeRef.class.isAssignableFrom(current.getClass())) { testNodeRef = nodeService.getPrimaryParent((NodeRef) current).getParentRef(); } else if (ChildAssociationRef.class.isAssignableFrom(current.getClass())) { testNodeRef = ((ChildAssociationRef) current).getParentRef(); } else if (PermissionCheckValue.class.isAssignableFrom(current.getClass())) { NodeRef nodeRef = ((PermissionCheckValue) current).getNodeRef(); testNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); } else { throw new ACLEntryVoterException( "The specified parameter is recognized: " + current.getClass()); } } else { if (StoreRef.class.isAssignableFrom(current.getClass())) { testNodeRef = nodeService.getRootNode((StoreRef) current); } else if (NodeRef.class.isAssignableFrom(current.getClass())) { testNodeRef = (NodeRef) current; } else if (ChildAssociationRef.class.isAssignableFrom(current.getClass())) { testNodeRef = ((ChildAssociationRef) current).getChildRef(); } else if (PermissionCheckValue.class.isAssignableFrom(current.getClass())) { testNodeRef = ((PermissionCheckValue) current).getNodeRef(); } else { throw new ACLEntryVoterException( "The specified parameter is recognized: " + current.getClass()); } } if (logger.isDebugEnabled()) { logger.debug("\t" + cad.typeString + " test on " + testNodeRef + " from " + current.getClass().getName()); } if (isUnfiltered(testNodeRef)) { continue; } int readCheck = childReadChek; if (cad.parent) { readCheck = parentReadCheck; } if (incudedSet.get(i) && (testNodeRef != null) && (readCheck != AccessDecisionVoter.ACCESS_GRANTED)) { incudedSet.set(i, false); } } } if (incudedSet.cardinality() == returnedObject.length) { return returnedObject; } else { Object[] answer = new Object[incudedSet.cardinality()]; for (int i = incudedSet.nextSetBit(0), p = 0; i >= 0; i = incudedSet.nextSetBit(++i), p++) { answer[p] = returnedObject[i]; } return answer; } }
From source file:com.netspective.commons.acl.AccessControlListTest.java
public void testAuthenticatedUsersPermissions() throws DataModelException, InvocationTargetException, InstantiationException, NoSuchMethodException, IllegalAccessException, IOException, PermissionNotFoundException, RoleNotFoundException { AccessControlListsComponent aclc = (AccessControlListsComponent) XdmComponentFactory.get( AccessControlListsComponent.class, new Resource(AccessControlListTest.class, RESOURCE_NAME_THREE), XdmComponentFactory.XDMCOMPFLAGS_DEFAULT); // Verify _something_ was loaded... assertNotNull(aclc);//from www. ja va 2 s .c o m AccessControlListsManager aclm = aclc.getItems(); assertNotNull(aclm); AccessControlList defaultAcl = aclm.getDefaultAccessControlList(); assertNotNull(defaultAcl); assertEquals(7, defaultAcl.getPermissionsByName().size()); // Independently created User... ValueContext vcTwo = ValueSources.getInstance().createDefaultValueContext(); MutableAuthenticatedUser userTwo = new BasicAuthenticatedUser(); userTwo.setUserId("admin"); userTwo.setUserName("Administrator"); // Experiment with AuthenticatedUsers and Roles/Permissions assertNull(userTwo.getUserRoleNames()); String[] userTwoRoles = { "/acl/role/normal-user" }; userTwo.setRoles(aclm, userTwoRoles); assertEquals(userTwoRoles, userTwo.getUserRoleNames()); Role normalUser = defaultAcl.getRole("/acl/role/normal-user"); assertEquals(2, normalUser.getId()); BitSet aclNormalUserPermissionSet = new BitSet(defaultAcl.getHighestPermissionId()); aclNormalUserPermissionSet.set(1); aclNormalUserPermissionSet.set(2); aclNormalUserPermissionSet.set(3); aclNormalUserPermissionSet.set(4); aclNormalUserPermissionSet.set(5); assertEquals(normalUser.getPermissions(), userTwo.getUserPermissions()); assertEquals(aclNormalUserPermissionSet, userTwo.getUserPermissions()); userTwo.setPermissions(aclm, new String[] { "/acl/app/orders/create_order", "/acl/app/orders/view_order", "/acl/app/orders/delete_order" }); BitSet userTwoPermissionSet = new BitSet(defaultAcl.getHighestPermissionId()); userTwoPermissionSet.set(3); userTwoPermissionSet.set(5); userTwoPermissionSet.set(6); assertFalse(normalUser.getPermissions().equals(userTwo.getUserPermissions())); assertEquals(userTwoPermissionSet, userTwo.getUserPermissions()); }
From source file:com.opengamma.financial.analytics.model.volatility.cube.SABRNonLinearSwaptionVolatilityCubeFittingFunctionNew.java
private BitSet getFixedParameters(final ValueRequirement desiredSurface) { final BitSet fixed = new BitSet(4); final String useFixedAlpha = desiredSurface.getConstraint(PROPERTY_USE_FIXED_ALPHA); if (Boolean.parseBoolean(useFixedAlpha)) { fixed.set(0);/*from w ww . j a v a 2 s . c o m*/ } final String useFixedBeta = desiredSurface.getConstraint(PROPERTY_USE_FIXED_BETA); if (Boolean.parseBoolean(useFixedBeta)) { fixed.set(1); } final String useFixedRho = desiredSurface.getConstraint(PROPERTY_USE_FIXED_RHO); if (Boolean.parseBoolean(useFixedRho)) { fixed.set(2); } final String useFixedNu = desiredSurface.getConstraint(PROPERTY_USE_FIXED_NU); if (Boolean.parseBoolean(useFixedNu)) { fixed.set(3); } return fixed; }
From source file:com.cloudera.flume.handlers.thrift.ThriftFlumeEvent.java
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try {/*www. j av a 2 s.c o m*/ // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. __isset_bit_vector = new BitSet(1); read(new org.apache.thrift.protocol.TCompactProtocol( new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } }
From source file:org.onosproject.tetopology.management.impl.TeTopologyManager.java
private void updateMergedTopology(Map<Long, TeNode> teNodes, Map<TeLinkTpKey, TeLink> teLinks) { boolean newTopology = mergedTopology == null; BitSet flags = newTopology ? new BitSet(TeConstants.FLAG_MAX_BITS) : mergedTopology.flags(); flags.set(TeTopology.BIT_MERGED);// www .j av a2s .co m CommonTopologyData commonData = new CommonTopologyData( newTopology ? TeMgrUtil.toNetworkId(mergedTopologyKey) : mergedTopology.networkId(), OptimizationType.NOT_OPTIMIZED, flags, DeviceId.deviceId("localHost")); mergedTopology = new DefaultTeTopology(mergedTopologyKey, teNodes, teLinks, Long.toString(mergedTopologyKey.topologyId()), commonData); mergedNetwork = TeMgrUtil.networkBuilder(mergedTopology); log.info("Nodes# {}, Links# {}", mergedTopology.teNodes().size(), mergedTopology.teLinks().size()); }
From source file:com.netspective.commons.acl.AccessControlListTest.java
public void testAuthenticatedUsersPermissionErrors() throws DataModelException, InvocationTargetException, InstantiationException, NoSuchMethodException, IllegalAccessException, IOException, PermissionNotFoundException, RoleNotFoundException { AccessControlListsComponent aclc = (AccessControlListsComponent) XdmComponentFactory.get( AccessControlListsComponent.class, new Resource(AccessControlListTest.class, RESOURCE_NAME_THREE), XdmComponentFactory.XDMCOMPFLAGS_DEFAULT); // Verify _something_ was loaded... assertNotNull(aclc);/*from w w w . j a v a 2 s . c om*/ AccessControlListsManager aclm = aclc.getItems(); assertNotNull(aclm); AccessControlList defaultAcl = aclc.getItems().getDefaultAccessControlList(); assertNotNull(defaultAcl); // Independently created User... ValueContext vcTwo = ValueSources.getInstance().createDefaultValueContext(); MutableAuthenticatedUser userTwo = new BasicAuthenticatedUser(); userTwo.setUserId("admin"); userTwo.setUserName("Administrator"); // Experiment with AuthenticatedUsers and Roles/Permissions assertNull(userTwo.getUserRoleNames()); boolean exceptionThrown = true; try { userTwo.setRoles(aclm, new String[] { "/acl/role/invalid-user" }); exceptionThrown = false; } catch (RoleNotFoundException e) { assertTrue(exceptionThrown); } assertTrue(exceptionThrown); try { userTwo.setPermissions(aclm, new String[] { "/acl/app/orders/invalidate_order" }); exceptionThrown = false; } catch (PermissionNotFoundException e) { assertTrue(exceptionThrown); } assertTrue(exceptionThrown); // Verify proper behavior upon setting null roles or permissions userTwo.setRoles(aclm, null); assertNull(userTwo.getUserRoleNames()); assertNull(userTwo.getUserPermissions()); userTwo.setPermissions(aclm, null); assertNull(userTwo.getUserPermissions()); String[] userTwoRoles = { "/acl/role/normal-user" }; userTwo.setRoles(aclm, userTwoRoles); assertEquals(userTwoRoles, userTwo.getUserRoleNames()); Role normalUser = defaultAcl.getRole("/acl/role/normal-user"); // BitSet aclNormalUserPermissionSet = normalUser.getChildPermissions(); BitSet aclNormalUserPermissionSet = new BitSet(defaultAcl.getHighestPermissionId()); aclNormalUserPermissionSet.set(1); aclNormalUserPermissionSet.set(2); aclNormalUserPermissionSet.set(3); aclNormalUserPermissionSet.set(4); aclNormalUserPermissionSet.set(5); assertEquals(aclNormalUserPermissionSet, normalUser.getPermissions()); assertEquals(normalUser.getPermissions(), userTwo.getUserPermissions()); assertEquals(aclNormalUserPermissionSet, userTwo.getUserPermissions()); userTwo.setRoles(aclm, userTwoRoles); assertTrue(userTwo.hasAnyPermission(aclm, new String[] { "/acl/app/orders/create_order", "/acl/app/orders/view_order", "/acl/app/orders/edit_order" })); assertTrue(userTwo.hasAnyPermission(aclm, new String[] { "/acl/app/orders/delete_order", "/acl/app/orders/view_order", "/acl/app/orders/edit_order" })); assertFalse(userTwo.hasPermission(aclm, "/acl/app/orders/delete_order")); assertFalse(userTwo.hasAnyPermission(aclm, new String[] { "/acl/app/orders/delete_order" })); try { userTwo.hasAnyPermission(aclm, new String[] { "/acl/app/orders/invalidate_order", "/acl/app/orders/misplace_order" }); exceptionThrown = false; } catch (PermissionNotFoundException e) { assertTrue(exceptionThrown); } assertTrue(exceptionThrown); try { userTwo.hasPermission(aclm, "/acl/app/orders/invalidate_order"); exceptionThrown = false; } catch (PermissionNotFoundException e) { assertTrue(exceptionThrown); } assertTrue(exceptionThrown); assertTrue(userTwo.hasPermission(aclm, "/acl/app/orders/view_order")); }
From source file:com.joliciel.jochre.graphics.ShapeImpl.java
@Override public BitSet getBlackAndWhiteBitSet(int threshold) { String key = "" + threshold; BitSet bitset = this.bitsets.get(key); if (bitset == null) { bitset = new BitSet(this.getWidth() * this.getHeight()); int counter = 0; for (int j = 0; j < this.getHeight(); j++) for (int i = 0; i < this.getWidth(); i++) { int pixel = this.getPixel(i, j); bitset.set(counter++, pixel <= threshold); }/*www .j ava 2 s.c o m*/ this.bitsets.put(key, bitset); } return bitset; }
From source file:model.DecomposableModel.java
public BitSet findSab(GraphAction action) { int a = action.getV1(); int b = action.getV2(); BitSet Sab = null;/*www . j av a2 s.c om*/ for (CliqueGraphEdge e : graph.cg.edgeSet()) { BitSet clique1 = e.getClique1(); BitSet clique2 = e.getClique2(); if ((clique1.get(a) && clique2.get(b)) || (clique2.get(a) && clique1.get(b))) { Sab = e.getSeparator(); break; } } if (Sab == null) {// disconnected components Sab = new BitSet(dimensionsForVariables.length); } if (!Sab.equals(graph.getSeparator(a, b))) { System.err.println("Ouch"); } return Sab; }
From source file:itemsetmining.itemset.ItemsetTree.java
/** * Get the chi-squared of the given itemset. * * @param set// w w w .j av a2 s .com * the itemset * @return the chi-squared statistic. */ public double getChiSquaredOfItemset(final Itemset set, final Multiset<Integer> singletons) { // sort by descending support final int[] sortedItems = set.stream().sorted(itemComparator).mapToInt(i -> i).toArray(); return recursiveChiSquared(0, new BitSet(set.size()), sortedItems, singletons); }