List of usage examples for java.util BitSet set
public void set(int bitIndex)
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 name "main".//w w w. j a va2s . c o m */ public void testSingleACLNonDefaultDataModelSchemaImportFromXmlValid() throws RoleNotFoundException, PermissionNotFoundException, DataModelException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException { AccessControlListsComponent aclc = (AccessControlListsComponent) XdmComponentFactory.get( AccessControlListsComponent.class, new Resource(AccessControlListTest.class, RESOURCE_NAME_TWO), 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 there is no defaultAcl and that it returns a null AccessControlList defaultAcl = aclm.getDefaultAccessControlList(); assertNull("Expected: Default ACL = null, Found: Non-Null ACL", defaultAcl); AccessControlList mainAcl = aclm.getAccessControlList("main"); assertNotNull("Expected: ACL named 'main', Found: null", mainAcl); assertEquals("Expected: ACL named 'main', Found: ACL named '" + mainAcl.getName() + "'", "main", mainAcl.getName()); // Verify exactly _eleven_ permissions were loaded in this acl Map aclPermissions = mainAcl.getPermissionsByName(); assertNotNull("Expected: List of Permissions for ACL, Found: null", aclPermissions); assertEquals("Expected: Total permissions = 8, Found: Total permissions = " + aclPermissions.size(), 8, aclPermissions.size()); // Verify exactly _two_ roles were loaded in this acl Map aclRoles = mainAcl.getRolesByName(); assertNotNull(aclRoles); assertEquals(3, aclRoles.size()); // Verify the /main/app/orders/edit_order permission has the right values Permission editOrder = mainAcl.getPermission("/main/app/orders/edit_order"); assertEquals(4, editOrder.getId()); assertEquals(2, editOrder.getAncestorsCount()); assertEquals(" /main/app/orders/edit_order = 4 {4}\n", editOrder.toString()); // Verify the /acl/role/normal-user has the proper id Role normalUser = mainAcl.getRole("/main/role/normal-user"); assertEquals("Expected: Id for /main/role/normal-user = 2, Found: " + normalUser.getId(), 2, normalUser.getId()); assertEquals(1, normalUser.getAncestorsCount()); assertEquals(" /main/role/normal-user = 2 {1, 2, 3, 4, 5}\n", normalUser.toString()); // 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 /main/role/normal-user = " + expectedPermissionSet + ", Found: " + normalUserPermissionSet, expectedPermissionSet, normalUserPermissionSet); aclc.printErrorsAndWarnings(); }
From source file:org.apache.openjpa.datacache.AbstractDataCache.java
public BitSet pinAll(Collection<Object> keys) { if (keys.isEmpty()) return EMPTY_BITSET; BitSet set = new BitSet(keys.size()); int i = 0;//from w w w.ja v a 2 s. c o m for (Iterator<Object> iter = keys.iterator(); iter.hasNext(); i++) if (pin(iter.next())) set.set(i); return set; }
From source file:org.apache.openjpa.datacache.AbstractDataCache.java
public BitSet unpinAll(Collection<Object> keys) { if (keys.isEmpty()) return EMPTY_BITSET; BitSet set = new BitSet(keys.size()); int i = 0;//from w w w. ja va2s. co m for (Iterator<Object> iter = keys.iterator(); iter.hasNext(); i++) if (unpin(iter.next())) set.set(i); return set; }
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;/*ww w. j a v a2 s. co m*/ for (Iterator<Object> iter = keys.iterator(); iter.hasNext(); i++) if (contains(iter.next())) set.set(i); return set; }
From source file:org.wso2.andes.kernel.router.TopicRoutingMatcher.java
/** * Run through each constituentTable and insert a new column for a new storage queue filling it's values * by comparing constituents.//ww w .j a va 2 s . c o m * <p/> * This will only fill values for the already available constituents. Will not add new constituents. * * @param bindingKey The newly subscribed destination */ private void addStorageQueueColumn(String bindingKey, int queueIndex) throws AndesException { String[] bindingKeyConstituents = queueConstituents.get(queueIndex); // Create a mock destination with two constituents for 'other' wildcard matching String matchDestinationForOther = OTHER_CONSTITUENT + constituentsDelimiter + OTHER_CONSTITUENT; // Create a mock destination with three constituents for 'null' wildcard matching String matchDestinationForNull = NULL_CONSTITUENT + constituentsDelimiter + NULL_CONSTITUENT + constituentsDelimiter + NULL_CONSTITUENT; // Loop through each constituent table for the new constituents for (int constituentIndex = 0; constituentIndex < bindingKeyConstituents.length; constituentIndex++) { String currentConstituent = bindingKeyConstituents[constituentIndex]; Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); // Loop through each constituent row in the table and fill values for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { String constituentOfCurrentRow = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); if (constituentOfCurrentRow.equals(currentConstituent)) { bitSet.set(queueIndex); } else if (NULL_CONSTITUENT.equals(constituentOfCurrentRow)) { // Check if this constituent being null matches the destination if we match it with // a null constituent String wildcardDestination = NULL_CONSTITUENT + constituentsDelimiter + currentConstituent; bitSet.set(queueIndex, isMatchForProtocolType(wildcardDestination, matchDestinationForNull)); // } } else if (OTHER_CONSTITUENT.equals(constituentOfCurrentRow)) { // Check if other is matched by comparing wildcard through specific wildcard matching // Create a mock destinations with current constituent added last and check if it match with a // non-wildcard destination match with the corresponding matching method String wildCardDestination = OTHER_CONSTITUENT + constituentsDelimiter + currentConstituent; bitSet.set(queueIndex, isMatchForProtocolType(wildCardDestination, matchDestinationForOther)); } else if (singleLevelWildCard.equals(currentConstituent) || multiLevelWildCard.equals(currentConstituent)) { // If there is any wildcard at this position, then this should match. bitSet.set(queueIndex); } else { bitSet.set(queueIndex, false); } } } int noOfMaxConstituents = constituentTables.size(); if (noOfMaxConstituents > bindingKeyConstituents.length) { // There are more constituent tables to be filled. Wildcard matching is essential here. boolean matchingOthers = true; // The OTHER_CONSTITUENT is added here to represent any constituent if (!multiLevelWildCard.equals(bindingKeyConstituents[bindingKeyConstituents.length - 1])) { String otherConstituentComparer = bindingKey + constituentsDelimiter + OTHER_CONSTITUENT; matchingOthers = isMatchForProtocolType(bindingKey, otherConstituentComparer); } // Else matchingOthers will be true for (int constituentIndex = bindingKeyConstituents.length; constituentIndex < noOfMaxConstituents; constituentIndex++) { Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); // Loop through each constituent row in the table and fill values for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { String constituentOfCurrentRow = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); if (NULL_CONSTITUENT.equals(constituentOfCurrentRow)) { // Null constituent is always true here bitSet.set(queueIndex); } else { bitSet.set(queueIndex, matchingOthers); } } } } }
From source file:org.apache.openjpa.datacache.AbstractDataCache.java
public BitSet removeAll(Collection<Object> keys) { if (keys.isEmpty()) return EMPTY_BITSET; BitSet set = new BitSet(keys.size()); int i = 0;// ww w . j a va2 s .c o m for (Iterator<Object> iter = keys.iterator(); iter.hasNext(); i++) if (remove(iter.next()) != null) set.set(i); return set; }
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 w w w . j a v a2 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:org.wso2.andes.subscription.TopicSubscriptionBitMapStore.java
/** * Run through each constituentTable and insert a new column for a new subscription filling it's values * by comparing constituents.// ww w.j a v a 2 s. c o m * <p/> * This will only fill values for the already available constituents. Will not add new constituents. * * @param subscribedDestination The newly subscribed destination */ private void addSubscriptionColumn(String subscribedDestination, int subscriptionIndex) throws AndesException { String[] subscribedDestinationConstituents = subscriptionConstituents.get(subscriptionIndex); // Create a mock destination with two constituents for 'other' wildcard matching String matchDestinationForOther = OTHER_CONSTITUENT + constituentsDelimiter + OTHER_CONSTITUENT; // Create a mock destination with three constituents for 'null' wildcard matching String matchDestinationForNull = NULL_CONSTITUENT + constituentsDelimiter + NULL_CONSTITUENT + constituentsDelimiter + NULL_CONSTITUENT; // Loop through each constituent table for the new constituents for (int constituentIndex = 0; constituentIndex < subscribedDestinationConstituents.length; constituentIndex++) { String currentConstituent = subscribedDestinationConstituents[constituentIndex]; Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); // Loop through each constituent row in the table and fill values for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { String constituentOfCurrentRow = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); if (constituentOfCurrentRow.equals(currentConstituent)) { bitSet.set(subscriptionIndex); } else if (NULL_CONSTITUENT.equals(constituentOfCurrentRow)) { // Check if this constituent being null matches the destination if we match it with // a null constituent String wildcardDestination = NULL_CONSTITUENT + constituentsDelimiter + currentConstituent; bitSet.set(subscriptionIndex, isMatchForProtocolType(wildcardDestination, matchDestinationForNull)); // } } else if (OTHER_CONSTITUENT.equals(constituentOfCurrentRow)) { // Check if other is matched by comparing wildcard through specific wildcard matching // Create a mock destinations with current constituent added last and check if it match with a // non-wildcard destination match with the corresponding matching method String wildCardDestination = OTHER_CONSTITUENT + constituentsDelimiter + currentConstituent; bitSet.set(subscriptionIndex, isMatchForProtocolType(wildCardDestination, matchDestinationForOther)); } else if (singleLevelWildCard.equals(currentConstituent) || multiLevelWildCard.equals(currentConstituent)) { // If there is any wildcard at this position, then this should match. bitSet.set(subscriptionIndex); } else { bitSet.set(subscriptionIndex, false); } } } int noOfMaxConstituents = constituentTables.size(); if (noOfMaxConstituents > subscribedDestinationConstituents.length) { // There are more constituent tables to be filled. Wildcard matching is essential here. boolean matchingOthers = true; // The OTHER_CONSTITUENT is added here to represent any constituent if (!multiLevelWildCard .equals(subscribedDestinationConstituents[subscribedDestinationConstituents.length - 1])) { String otherConstituentComparer = subscribedDestination + constituentsDelimiter + OTHER_CONSTITUENT; matchingOthers = isMatchForProtocolType(subscribedDestination, otherConstituentComparer); } // Else matchingOthers will be true for (int constituentIndex = subscribedDestinationConstituents.length; constituentIndex < noOfMaxConstituents; constituentIndex++) { Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); // Loop through each constituent row in the table and fill values for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { String constituentOfCurrentRow = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); if (NULL_CONSTITUENT.equals(constituentOfCurrentRow)) { // Null constituent is always true here bitSet.set(subscriptionIndex); } else { bitSet.set(subscriptionIndex, matchingOthers); } } } } }
From source file:hivemall.dataset.LogisticRegressionDataGeneratorUDTF.java
private void generateSparseData() throws HiveException { float label = rnd1.nextFloat(); float sign = (label <= prob_one) ? 1.f : 0.f; labels[position] = classification ? sign : label; String[] features = featuresArray[position]; assert (features != null); final BitSet used = new BitSet(n_dimensions); int searchClearBitsFrom = 0; for (int i = 0, retry = 0; i < n_features; i++) { int f = rnd2.nextInt(n_dimensions); if (used.get(f)) { if (retry < 3) { --i;// ww w . j a v a 2s. c o m ++retry; continue; } searchClearBitsFrom = used.nextClearBit(searchClearBitsFrom); f = searchClearBitsFrom; } used.set(f); float w = (float) rnd2.nextGaussian() + (sign * eps); String y = f + ":" + w; features[i] = y; retry = 0; } if (sort) { Arrays.sort(features, new Comparator<String>() { @Override public int compare(String o1, String o2) { int i1 = Integer.parseInt(o1.split(":")[0]); int i2 = Integer.parseInt(o2.split(":")[0]); return Primitives.compare(i1, i2); } }); } }
From source file:org.wso2.andes.subscription.ClusterSubscriptionBitMapHandler.java
/** * Run through each constituentTable and insert a new column for a new subscription filling it's values * by comparing constituents.//from w w w . j av a2 s.c om * <p/> * This will only fill values for the already available constituents. Will not add new constituents. * * @param subscribedDestination The newly subscribed destination */ private void addSubscriptionColumn(String subscribedDestination, int subscriptionIndex) throws AndesException { String[] subscribedDestinationConstituents = subscriptionConstituents.get(subscriptionIndex); // Create a mock destination with two constituents for 'other' wildcard matching String matchDestinationForOther = OTHER_CONSTITUENT + constituentsDelimiter + OTHER_CONSTITUENT; // Create a mock destination with three constituents for 'null' wildcard matching String matchDestinationForNull = NULL_CONSTITUENT + constituentsDelimiter + NULL_CONSTITUENT + constituentsDelimiter + NULL_CONSTITUENT; // Loop through each constituent table for the new constituents for (int constituentIndex = 0; constituentIndex < subscribedDestinationConstituents.length; constituentIndex++) { String currentConstituent = subscribedDestinationConstituents[constituentIndex]; Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); // Loop through each constituent row in the table and fill values for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { String constituentOfCurrentRow = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); if (constituentOfCurrentRow.equals(currentConstituent)) { bitSet.set(subscriptionIndex); } else if (NULL_CONSTITUENT.equals(constituentOfCurrentRow)) { // Check if this constituent being null matches the destination if we match it with // a null constituent String wildcardDestination = NULL_CONSTITUENT + constituentsDelimiter + currentConstituent; bitSet.set(subscriptionIndex, isMatchForSubscriptionType(wildcardDestination, matchDestinationForNull)); // } } else if (OTHER_CONSTITUENT.equals(constituentOfCurrentRow)) { // Check if other is matched by comparing wildcard through specific wildcard matching // Create a mock destinations with current constituent added last and check if it match with a // non-wildcard destination match with the corresponding matching method String wildCardDestination = OTHER_CONSTITUENT + constituentsDelimiter + currentConstituent; bitSet.set(subscriptionIndex, isMatchForSubscriptionType(wildCardDestination, matchDestinationForOther)); } else if (singleLevelWildCard.equals(currentConstituent) || multiLevelWildCard.equals(currentConstituent)) { // If there is any wildcard at this position, then this should match. bitSet.set(subscriptionIndex); } else { bitSet.set(subscriptionIndex, false); } } } int noOfMaxConstituents = constituentTables.size(); if (noOfMaxConstituents > subscribedDestinationConstituents.length) { // There are more constituent tables to be filled. Wildcard matching is essential here. boolean matchingOthers = true; // The OTHER_CONSTITUENT is added here to represent any constituent if (!multiLevelWildCard .equals(subscribedDestinationConstituents[subscribedDestinationConstituents.length - 1])) { String otherConstituentComparer = subscribedDestination + constituentsDelimiter + OTHER_CONSTITUENT; matchingOthers = isMatchForSubscriptionType(subscribedDestination, otherConstituentComparer); } // Else matchingOthers will be true for (int constituentIndex = subscribedDestinationConstituents.length; constituentIndex < noOfMaxConstituents; constituentIndex++) { Map<String, BitSet> constituentTable = constituentTables.get(constituentIndex); // Loop through each constituent row in the table and fill values for (Map.Entry<String, BitSet> constituentRow : constituentTable.entrySet()) { String constituentOfCurrentRow = constituentRow.getKey(); BitSet bitSet = constituentRow.getValue(); if (NULL_CONSTITUENT.equals(constituentOfCurrentRow)) { // Null constituent is always true here bitSet.set(subscriptionIndex); } else { bitSet.set(subscriptionIndex, matchingOthers); } } } } }