List of usage examples for java.util HashSet size
public int size()
From source file:com.amalto.core.delegator.IItemCtrlDelegator.java
public void allowDelete(String clusterName, String concept, ComplexTypeMetadata.DeleteType deleteType) throws XtentisException { HashSet<String> roles; try {// w w w . j av a 2s . c om roles = getLocalUser().getRoles(); } catch (XtentisException e) { String message = "Unable to access user current roles."; //$NON-NLS-1$ LOGGER.error(message, e); throw new RuntimeException(message, e); } Server server = ServerContext.INSTANCE.get(); StorageAdmin storageAdmin = server.getStorageAdmin(); Storage storage = storageAdmin.get(clusterName, storageAdmin.getType(clusterName)); MetadataRepository repository = storage.getMetadataRepository(); ComplexTypeMetadata complexTypeMetadata = repository.getComplexType(concept); if (roles != null && roles.size() > 0) { if (ComplexTypeMetadata.DeleteType.LOGICAL.equals(deleteType)) { if (!Collections.disjoint(complexTypeMetadata.getDenyDelete(ComplexTypeMetadata.DeleteType.LOGICAL), roles)) { throw new XtentisException("Unauthorized. User '" + LocalUser.getLocalUser().getUsername() //$NON-NLS-1$ + "' has no logical delete permission on '" + clusterName + "." + concept + "'"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } } else if (ComplexTypeMetadata.DeleteType.PHYSICAL.equals(deleteType)) { if (!Collections.disjoint( complexTypeMetadata.getDenyDelete(ComplexTypeMetadata.DeleteType.PHYSICAL), roles)) { throw new XtentisException("Unauthorized. User '" + LocalUser.getLocalUser().getUsername() //$NON-NLS-1$ + "' has no physical delete permission on '" + clusterName + "." + concept + "'"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ } } } }
From source file:net.refractions.udig.catalog.internal.CatalogImpl.java
/** * Performs a search on this catalog based on the specified inputs. The pattern uses the * following conventions: use " " to surround a phase use + to represent 'AND' use - to * represent 'OR' use ! to represent 'NOT' use ( ) to designate scope The bbox provided shall be * in Lat - Long, or null if the search is not to be contained within a specified area. * /*from w ww . j av a 2s .co m*/ * @see net.refractions.udig.catalog.ICatalog#search(java.lang.String, * com.vividsolutions.jts.geom.Envelope) * @param pattern * @param bbox used for an intersection test * @return */ public synchronized List<IResolve> search(String pattern, Envelope bbox, IProgressMonitor monitor2) { IProgressMonitor monitor = monitor2; if (monitor == null) monitor = new NullProgressMonitor(); if ((pattern == null || "".equals(pattern.trim())) //$NON-NLS-1$ && (bbox == null || bbox.isNull())) { return new LinkedList<IResolve>(); } AST ast = null; if (pattern != null && !"".equals(pattern.trim())) //$NON-NLS-1$ ast = ASTFactory.parse(pattern); // TODO check cuncurrency issues here List<IResolve> result = new LinkedList<IResolve>(); HashSet<IService> tmp = new HashSet<IService>(); tmp.addAll(this.services); try { monitor.beginTask(Messages.CatalogImpl_finding, tmp.size() * 10); Iterator<IService> services = tmp.iterator(); if (services != null) { while (services.hasNext()) { IService service = services.next(); if (check(service, ast)) { result.add(service); } Iterator<? extends IGeoResource> resources; SubProgressMonitor submonitor = new SubProgressMonitor(monitor, 10); try { List<? extends IGeoResource> t = service.resources(submonitor); resources = t == null ? null : t.iterator(); while (resources != null && resources.hasNext()) { IGeoResource resource = resources.next(); if (check(resource, ast, bbox)) { result.add(resource); } } } catch (IOException e) { CatalogPlugin.log(null, e); } finally { submonitor.done(); } } } return result; } finally { monitor.done(); } }
From source file:org.apache.accumulo.server.init.Initialize.java
private static void addVolumes(VolumeManager fs) throws IOException { String[] volumeURIs = VolumeConfiguration.getVolumeUris(SiteConfiguration.getInstance()); HashSet<String> initializedDirs = new HashSet<String>(); initializedDirs.addAll(Arrays.asList(ServerConstants.checkBaseUris(volumeURIs, true))); HashSet<String> uinitializedDirs = new HashSet<String>(); uinitializedDirs.addAll(Arrays.asList(volumeURIs)); uinitializedDirs.removeAll(initializedDirs); Path aBasePath = new Path(initializedDirs.iterator().next()); Path iidPath = new Path(aBasePath, ServerConstants.INSTANCE_ID_DIR); Path versionPath = new Path(aBasePath, ServerConstants.VERSION_DIR); UUID uuid = UUID.fromString(ZooUtil.getInstanceIDFromHdfs(iidPath, SiteConfiguration.getInstance())); for (Pair<Path, Path> replacementVolume : ServerConstants.getVolumeReplacements()) { if (aBasePath.equals(replacementVolume.getFirst())) log.error(aBasePath + " is set to be replaced in " + Property.INSTANCE_VOLUMES_REPLACEMENTS + " and should not appear in " + Property.INSTANCE_VOLUMES + ". It is highly recommended that this property be removed as data could still be written to this volume."); }/*from ww w . j a va 2 s. c om*/ if (ServerConstants.DATA_VERSION != Accumulo.getAccumuloPersistentVersion( versionPath.getFileSystem(CachedConfiguration.getInstance()), versionPath)) { throw new IOException("Accumulo " + Constants.VERSION + " cannot initialize data version " + Accumulo.getAccumuloPersistentVersion(fs)); } initDirs(fs, uuid, uinitializedDirs.toArray(new String[uinitializedDirs.size()]), true); }
From source file:es.caib.seycon.ng.servei.AutoritzacioServiceImpl.java
protected Collection<AutoritzacioRol> handleGetDescriptionUserAuthorizations(String codiUsuari) throws Exception { Collection autoritzacionsRolUsuari = handleGetUserAuthorizations(codiUsuari); // IMPORTANT: la seva clau es el nom del rol + codiAutoritzacio + // descripci [valor_domini] HashMap<String, AutoritzacioRol> autoritzacionsSenseRepeticions = new HashMap(); // Afegim informaci addicional: if (autoritzacionsRolUsuari != null) { for (Iterator it = autoritzacionsRolUsuari.iterator(); it.hasNext();) { AutoritzacioRol auto = (AutoritzacioRol) it.next(); AutoritzacioSEU autoSEU = (AutoritzacioSEU) getAuthorizations().get(auto.getAutoritzacio()); if (autoSEU != null) { // formategem els valor de domini String valorDominiUsuari = ""; //$NON-NLS-1$ if (auto.getValorDominiRolUsuari() != null && auto.getValorDominiRolUsuari().size() > 0) { HashSet valors = new HashSet(); for (Iterator vit = auto.getValorDominiRolUsuari().iterator(); vit.hasNext();) { ValorDomini vd = (ValorDomini) vit.next(); valors.add(vd.getValor()); }/*from w w w . j av a 2s . c om*/ if (valors.size() == 1 && valors.contains("*")) //$NON-NLS-1$ ; else valorDominiUsuari = " " + valors.toString(); //$NON-NLS-1$ } auto.setDescripcio(autoSEU.getDescripcio() //$NON-NLS-1$ + valorDominiUsuari); auto.setTipusDomini(autoSEU.getTipusDomini()); auto.setScope(autoSEU.getScope()); auto.setAmbit(autoSEU.getAmbit()); auto.setHereta(autoSEU.getHereta()); // separat per comes autoritzacionsSenseRepeticions .put(auto.getRol().getNom() + auto.getAutoritzacio() + auto.getDescripcio(), auto); } } // Les ordenem LinkedList autosOrdenades = new LinkedList(autoritzacionsSenseRepeticions.values()); Collections.sort(autosOrdenades, new ComparaAutos()); return autosOrdenades; } return autoritzacionsSenseRepeticions.values(); }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.ServletHandler.java
/** Get Servlets. * @return Array of defined servlets// w w w . j a va 2 s. c o m */ public ServletHolder[] getServlets() { // Sort and Initialize servlets HashSet holder_set = new HashSet(_nameMap.size()); holder_set.addAll(_nameMap.values()); ServletHolder holders[] = (ServletHolder[]) holder_set.toArray(new ServletHolder[holder_set.size()]); java.util.Arrays.sort(holders); return holders; }
From source file:com.healthcit.cacure.businessdelegates.QuestionAnswerManager.java
public DuplicateResultBean hasShortNameDuplicates(List<String> collectedShortNames) { HashSet<String> uniqShortnamesSet = new HashSet<String>(collectedShortNames); HashSet<String> duplShortnamesSet = new HashSet<String>(); if (uniqShortnamesSet.size() != collectedShortNames.size()) { for (String uniqSn : uniqShortnamesSet) { collectedShortNames.remove(uniqSn); }/* w w w .j a va 2 s .c o m*/ duplShortnamesSet.addAll(collectedShortNames); } Set<String> exactQuestionsShortNames = qstDao.getQuestionsShortNamesLike(uniqShortnamesSet, true); duplShortnamesSet.addAll(exactQuestionsShortNames); Set<String> exactTableShortNames = teDao.getTableShortNamesLike(uniqShortnamesSet, true); duplShortnamesSet.addAll(exactTableShortNames); if (duplShortnamesSet.isEmpty()) { return new DuplicateResultBean(DuplicateResultType.OK, null); } else { return new DuplicateResultBean(DuplicateResultType.NOT_UNIQUE, duplShortnamesSet.toArray(new String[0])); } }
From source file:com.hellblazer.slp.anubis.EndToEndTest.java
public void testAsymmetricPartition() throws Exception { int minorPartitionSize = configs.length / 2; BitView A = new BitView(); BitView B = new BitView(); CountDownLatch latchA = new CountDownLatch(minorPartitionSize); List<TestNode> partitionA = new ArrayList<TestNode>(); CountDownLatch latchB = new CountDownLatch(minorPartitionSize); List<TestNode> partitionB = new ArrayList<TestNode>(); int i = 0;//from ww w.java2 s.co m for (TestNode member : partition) { if (i++ % 2 == 0) { partitionA.add(member); member.latch = latchA; member.cardinality = minorPartitionSize; A.add(member.getIdentity()); } else { partitionB.add(member); member.latch = latchB; member.cardinality = minorPartitionSize; B.add(member.getIdentity()); } } String memberIdKey = "test.member.id"; String roundKey = "test.round"; ServiceURL url = new ServiceURL("service:http://foo.bar/drink-me"); List<Listener> listeners = new ArrayList<Listener>(); for (ApplicationContext context : memberContexts) { Listener listener = new Listener(context, memberContexts.size()); listeners.add(listener); listener.register(getQuery("*")); } for (ApplicationContext context : memberContexts) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put(memberIdKey, context.getBean(Identity.class).id); properties.put(roundKey, 1); context.getBean(ServiceScope.class).register(url, properties); } for (Listener listener : listeners) { assertTrue(String.format("Listener: %s did not receive all events", listener), listener.await(60, TimeUnit.SECONDS)); } for (Listener listener : listeners) { assertEquals("listener <" + listener.member + "> has received an invalid number of notifications :" + listener.events, listeners.size(), listener.events.size()); HashSet<Integer> sent = new HashSet<Integer>(); for (ServiceEvent event : listener.events) { assertEquals(EventType.REGISTERED, event.getType()); assertEquals(url, event.getReference().getUrl()); sent.add((Integer) event.getReference().getProperties().get(memberIdKey)); assertEquals(event.getReference().getProperties().get(AnubisScope.MEMBER_IDENTITY), event.getReference().getProperties().get(memberIdKey)); } assertEquals("listener <" + listener.member + "> did not receive messages from all members: " + sent, listeners.size(), sent.size()); } i = 0; for (Listener listener : listeners) { if (i++ % 2 == 0) { listener.reset(A); } else { listener.reset(B); } } log.info("asymmetric partitioning: " + A); controller.asymPartition(A); log.info("Awaiting stabilty of minor partition A"); assertTrue("minor partition A did not stabilize", latchA.await(60, TimeUnit.SECONDS)); for (ApplicationContext context : memberContexts) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put(memberIdKey, context.getBean(Identity.class).id); properties.put(roundKey, 2); context.getBean(ServiceScope.class).register(url, properties); } for (Listener listener : listeners) { if (A.contains(listener.member)) { assertTrue(String.format("Listener: %s did not receive all events", listener), listener.await(60, TimeUnit.SECONDS)); } } for (Listener listener : listeners) { if (A.contains(listener.member)) { assertEquals("listener <" + listener.member + "> has received more notifications than expected :" + listener.events, A.cardinality(), listener.events.size()); HashSet<Integer> sent = new HashSet<Integer>(); for (ServiceEvent event : listener.events) { assertEquals(EventType.REGISTERED, event.getType()); assertEquals(url, event.getReference().getUrl()); sent.add((Integer) event.getReference().getProperties().get(memberIdKey)); assertEquals(event.getReference().getProperties().get(AnubisScope.MEMBER_IDENTITY), event.getReference().getProperties().get(memberIdKey)); } assertEquals( "listener <" + listener.member + "> did not receive messages from all members: " + sent, A.cardinality(), sent.size()); } } // reform CountDownLatch latch = new CountDownLatch(configs.length); for (TestNode node : partition) { node.latch = latch; node.cardinality = configs.length; } controller.clearPartitions(); log.info("Awaiting stabilty of reformed major partition"); assertTrue("reformed partition did not stabilize", latch.await(60, TimeUnit.SECONDS)); }
From source file:com.hellblazer.slp.anubis.EndToEndTest.java
public void testSymmetricPartition() throws Exception { int minorPartitionSize = configs.length / 2; BitView A = new BitView(); BitView B = new BitView(); CountDownLatch latchA = new CountDownLatch(minorPartitionSize); List<TestNode> partitionA = new ArrayList<TestNode>(); CountDownLatch latchB = new CountDownLatch(minorPartitionSize); List<TestNode> partitionB = new ArrayList<TestNode>(); int i = 0;//from www.j av a2s . c o m for (TestNode member : partition) { if (i++ % 2 == 0) { partitionA.add(member); member.latch = latchA; member.cardinality = minorPartitionSize; A.add(member.getIdentity()); } else { partitionB.add(member); member.latch = latchB; member.cardinality = minorPartitionSize; B.add(member.getIdentity()); } } String memberIdKey = "test.member.id"; String roundKey = "test.round"; ServiceURL url = new ServiceURL("service:http://foo.bar/drink-me"); List<Listener> listeners = new ArrayList<Listener>(); for (ApplicationContext context : memberContexts) { Listener listener = new Listener(context, memberContexts.size()); listeners.add(listener); listener.register(getQuery("*")); } for (ApplicationContext context : memberContexts) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put(memberIdKey, context.getBean(Identity.class).id); properties.put(roundKey, 1); context.getBean(ServiceScope.class).register(url, properties); } for (Listener listener : listeners) { assertTrue(String.format("Listener: %s did not receive all events", listener), listener.await(60, TimeUnit.SECONDS)); } for (Listener listener : listeners) { assertEquals("listener <" + listener.member + "> has received an invalid number of notifications: " + listener.events, listeners.size(), listener.events.size()); HashSet<Integer> sent = new HashSet<Integer>(); for (ServiceEvent event : listener.events) { assertEquals(EventType.REGISTERED, event.getType()); assertEquals(url, event.getReference().getUrl()); sent.add((Integer) event.getReference().getProperties().get(memberIdKey)); assertEquals(event.getReference().getProperties().get(AnubisScope.MEMBER_IDENTITY), event.getReference().getProperties().get(memberIdKey)); } assertEquals("listener <" + listener.member + "> did not receive messages from all members: " + sent, listeners.size(), sent.size()); } i = 0; for (Listener listener : listeners) { if (i++ % 2 == 0) { listener.reset(A); } else { listener.reset(B); } } log.info("symmetric partitioning: " + A); controller.symPartition(A); log.info("Awaiting stabilty of minor partition A"); boolean stability = latchA.await(60, TimeUnit.SECONDS); assertTrue("minor partition A did not stabilize", stability); log.info("Awaiting stabilty of minor partition B"); assertTrue("minor partition B did not stabilize", latchB.await(60, TimeUnit.SECONDS)); for (TestNode member : partitionA) { assertEquals(A, member.getPartition()); } for (TestNode member : partitionB) { assertEquals(B, member.getPartition()); } for (ApplicationContext context : memberContexts) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put(memberIdKey, context.getBean(Identity.class).id); properties.put(roundKey, 2); context.getBean(ServiceScope.class).register(url, properties); } for (Listener listener : listeners) { assertTrue(String.format("Listener: %s did not receive all events", listener), listener.await(60, TimeUnit.SECONDS)); } for (Listener listener : listeners) { assertEquals("listener <" + listener.member + "> has received more notifications than expected: " + listener.events, A.cardinality(), listener.events.size()); HashSet<Integer> sent = new HashSet<Integer>(); for (ServiceEvent event : listener.events) { assertEquals(EventType.REGISTERED, event.getType()); assertEquals(url, event.getReference().getUrl()); sent.add((Integer) event.getReference().getProperties().get(memberIdKey)); assertEquals(event.getReference().getProperties().get(AnubisScope.MEMBER_IDENTITY), event.getReference().getProperties().get(memberIdKey)); } assertEquals("listener <" + listener.member + "> did not receive messages from all members: " + sent, A.cardinality(), sent.size()); } // reform CountDownLatch latch = new CountDownLatch(configs.length); for (TestNode node : partition) { node.latch = latch; node.cardinality = configs.length; } controller.clearPartitions(); log.info("Awaiting stabilty of reformed major partition"); assertTrue("reformed partition did not stabilize", latch.await(60, TimeUnit.SECONDS)); }
From source file:org.apache.hadoop.hdfs.server.namenode.BlockPlacementPolicyConfigurable.java
/** * Chosses a machine within a window inside a rack * @param rack rack to choose from// w ww . ja v a 2 s . c om * @param firstMachine machine that starts window * @param windowSize size of machine window * @param excludedNodes nodes to avoid * @param blocksize size of a block * @param maxReplicasPerRack maximum number of replicas within the same rack * @param results list of results * @return */ protected boolean chooseMachine(String rack, int firstMachine, int windowSize, HashMap<Node, Node> excludedNodes, long blocksize, int maxReplicasPerRack, List<DatanodeDescriptor> results) { readLock(); try { HashSet<Integer> excludedMachines = new HashSet<Integer>(); RackRingInfo rackInfo = racksMap.get(rack); assert (rackInfo != null); int n = rackInfo.rackNodesMap.size(); List<Node> rackDatanodes = clusterMap.getDatanodesInRack(rack); if (rackDatanodes == null) { return false; } while (excludedMachines.size() < windowSize) { int newMachine = randomIntInWindow(firstMachine, windowSize, n, excludedMachines); if (newMachine < 0) return false; excludedMachines.add(newMachine); DatanodeDescriptor chosenNode = null; for (Node node : rackDatanodes) { DatanodeDescriptor datanode = (DatanodeDescriptor) node; Integer idx = rackInfo.findNode(datanode); if (idx != null && idx.intValue() == newMachine) { chosenNode = datanode; break; } } if (chosenNode == null) continue; Node oldNode = excludedNodes.put(chosenNode, chosenNode); if (oldNode == null) { // choosendNode was not in the excluded list if (isGoodTarget(chosenNode, blocksize, maxReplicasPerRack, results)) { results.add(chosenNode); return true; } } } return false; } finally { readUnlock(); } }
From source file:org.apache.phoenix.jdbc.SecureUserConnectionsIT.java
@Test public void testMultipleInvocationsBySameUserAreEquivalent() throws Exception { final HashSet<ConnectionInfo> connections = new HashSet<>(); final String princ1 = getUserPrincipal(1); final File keytab1 = getUserKeytabFile(1); UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(princ1, keytab1.getPath()); PrivilegedExceptionAction<Void> callable = new PrivilegedExceptionAction<Void>() { public Void run() throws Exception { String url = joinUserAuthentication(BASE_URL, princ1, keytab1); connections.add(ConnectionInfo.create(url).normalize(ReadOnlyProps.EMPTY_PROPS, EMPTY_PROPERTIES)); return null; }//from w w w .j a va 2s .com }; // Using the same UGI should result in two equivalent ConnectionInfo objects ugi.doAs(callable); assertEquals(1, connections.size()); verifyAllConnectionsAreKerberosBased(connections); ugi.doAs(callable); assertEquals(1, connections.size()); verifyAllConnectionsAreKerberosBased(connections); }