List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.apache.openejb.util.classloader.URLClassLoaderFirst.java
public static Enumeration<URL> filterResources(final String name, final Enumeration<URL> result) { if (isFilterableResource(name)) { final Collection<URL> values = Collections.list(result); if (values.size() > 1) { // remove openejb one final URL url = URLClassLoaderFirst.class.getResource("/" + name); if (url != null) { values.remove(url);// www. j a v a 2 s.c om } } return Collections.enumeration(values); } return result; }
From source file:com.jsmartframework.web.manager.BeanHandler.java
void finalizeWebBeans(ServletContext servletContext) { List<String> names = Collections.list(servletContext.getAttributeNames()); for (String name : names) { Object bean = servletContext.getAttribute(name); if (bean == null) { continue; }//from w ww. j a v a2s. c o m if (bean.getClass().isAnnotationPresent(WebBean.class)) { finalizeWebBean(bean, servletContext); } } }
From source file:com.netscape.cmscore.usrgrp.UGSubsystem.java
/** * builds a User instance. Set all attributes retrieved from * LDAP server and set them on User./*from w w w . ja v a 2s . c o m*/ * * @return the User entity. */ protected IUser buildUser(LDAPEntry entry) throws EUsrGrpException { LDAPAttribute uid = entry.getAttribute("uid"); if (uid == null) { throw new EUsrGrpException("No Attribute UID in LDAP Entry " + entry.getDN()); } IUser id = createUser(this, (String) uid.getStringValues().nextElement()); LDAPAttribute cnAttr = entry.getAttribute("cn"); if (cnAttr != null) { String cn = (String) cnAttr.getStringValues().nextElement(); if (cn != null) { id.setFullName(cn); } } String userdn = entry.getDN(); if (userdn != null) { id.setUserDN(userdn); } else { // the impossible log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_BUILD_USER", userdn)); throw new EUsrGrpException(CMS.getUserMessage("CMS_INTERNAL_ERROR")); } /* LDAPAttribute certdnAttr = entry.getAttribute(LDAP_ATTR_CERTDN); if (certdnAttr != null) { String cdn = (String)certdnAttr.getStringValues().nextElement(); if (cdn != null) { id.setCertDN(cdn); } } */ LDAPAttribute mailAttr = entry.getAttribute("mail"); if (mailAttr != null) { @SuppressWarnings("unchecked") Enumeration<String> en = mailAttr.getStringValues(); if (en != null && en.hasMoreElements()) { String mail = en.nextElement(); if (mail != null) { id.setEmail(mail); } } } if (id.getEmail() == null) { id.setEmail(""); // safety net } LDAPAttribute pwdAttr = entry.getAttribute("userpassword"); if (pwdAttr != null) { String pwd = (String) pwdAttr.getStringValues().nextElement(); if (pwd != null) { id.setPassword(pwd); } } LDAPAttribute phoneAttr = entry.getAttribute("telephonenumber"); if (phoneAttr != null) { @SuppressWarnings("unchecked") Enumeration<String> en = phoneAttr.getStringValues(); if (en != null && en.hasMoreElements()) { String phone = en.nextElement(); if (phone != null) { id.setPhone(phone); } } } if (id.getPhone() == null) { id.setPhone(""); // safety net } LDAPAttribute userTypeAttr = entry.getAttribute("usertype"); if (userTypeAttr == null) id.setUserType(""); else { @SuppressWarnings("unchecked") Enumeration<String> en = userTypeAttr.getStringValues(); if (en != null && en.hasMoreElements()) { String userType = en.nextElement(); if ((userType != null) && (!userType.equals("undefined"))) id.setUserType(userType); else id.setUserType(""); } } LDAPAttribute userStateAttr = entry.getAttribute("userstate"); if (userStateAttr == null) id.setState(""); else { @SuppressWarnings("unchecked") Enumeration<String> en = userStateAttr.getStringValues(); if (en != null && en.hasMoreElements()) { String userState = en.nextElement(); if (userState != null) id.setState(userState); else id.setState(""); } } LDAPAttribute certAttr = entry.getAttribute(LDAP_ATTR_USER_CERT); if (certAttr != null) { Vector<X509Certificate> certVector = new Vector<X509Certificate>(); @SuppressWarnings("unchecked") Enumeration<byte[]> e = certAttr.getByteValues(); try { for (; e != null && e.hasMoreElements();) { X509Certificate cert = new X509CertImpl(e.nextElement()); certVector.addElement(cert); } } catch (Exception ex) { throw new EUsrGrpException(CMS.getUserMessage("CMS_INTERNAL_ERROR")); } if (certVector != null && certVector.size() != 0) { // Make an array of certs X509Certificate[] certArray = new X509Certificate[certVector.size()]; Enumeration<X509Certificate> en = certVector.elements(); int i = 0; while (en.hasMoreElements()) { certArray[i++] = en.nextElement(); } id.setX509Certificates(certArray); } } LDAPAttribute profileAttr = entry.getAttribute(LDAP_ATTR_PROFILE_ID); if (profileAttr != null) { @SuppressWarnings("unchecked") Enumeration<String> profiles = profileAttr.getStringValues(); id.setTpsProfiles(Collections.list(profiles)); } return id; }
From source file:io.smartspaces.system.bootstrap.osgi.GeneralSmartSpacesSupportActivator.java
/** * Get the IP address for the system.//from w w w . ja v a2 s . c om * * @param systemConfiguration * The system configuration * * @return host IP address */ private String getHostAddress(Configuration systemConfiguration) { try { String hostname = systemConfiguration .getPropertyString(SmartSpacesEnvironment.CONFIGURATION_NAME_HOST_NAME); if (hostname != null) { InetAddress address = InetAddress.getByName(hostname); return address.getHostAddress(); } String hostInterface = systemConfiguration .getPropertyString(SmartSpacesEnvironment.CONFIGURATION_NAME_HOST_INTERFACE); if (hostInterface != null) { spaceEnvironment.getLog().formatInfo("Using network interface with name %s", hostInterface); NetworkInterface networkInterface = NetworkInterface.getByName(hostInterface); if (networkInterface != null) { for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { if (inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress(); } } } else { spaceEnvironment.getLog().formatWarn("No network interface with name %s from configuration %s", hostInterface, SmartSpacesEnvironment.CONFIGURATION_NAME_HOST_INTERFACE); } } // See if a single network interface. If so, we will use it. List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); if (interfaces.size() == 1) { for (InetAddress inetAddress : Collections.list(interfaces.get(0).getInetAddresses())) { if (inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress(); } } } return null; } catch (Exception e) { spaceEnvironment.getLog().error("Could not obtain IP address", e); return UNKNOWN_HOST_ADDRESS; } }
From source file:org.eiichiro.bootleg.AbstractRequest.java
/** * Returns the Web endpoint method parameter from query string. * /*from w w w . ja v a 2 s .com*/ * @param type The parameter type. * @param name The parameter name. * @return The Web endpoint method parameter from the HTTP request's query * string. */ protected Object query(Type type, String name) { return parameter(type, name, new Function<String, Object>() { public Object apply(String name) { return context.request().getParameter(name); } }, new Function<String, Collection<Object>>() { @SuppressWarnings("unchecked") public Collection<Object> apply(String name) { HttpServletRequest request = context.request(); Map<String, Object> map = new TreeMap<String, Object>(); for (Object object : Collections.list(request.getParameterNames())) { String key = (String) object; if (key.startsWith(name + "[")) { map.put(key, request.getParameter(key)); } } return (map.isEmpty()) ? null : map.values(); } }); }
From source file:com.jsmartframework.web.manager.BeanHandler.java
void finalizeBeans(HttpSession session) { synchronized (session) { List<String> names = Collections.list(session.getAttributeNames()); for (String name : names) { Object bean = session.getAttribute(name); if (bean == null) { continue; }/* w ww. j a v a 2s. c o m*/ if (bean.getClass().isAnnotationPresent(WebBean.class)) { finalizeWebBean(bean, session); } else if (bean.getClass().isAnnotationPresent(AuthBean.class)) { finalizeAuthBean(bean, session); } } } }
From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java
/** * Go through the ruleSet and populate the JList * * @param ruleToBeSelected The path to the rule that should be selected * after populating the tree *//*w w w . j av a 2s .c o m*/ void populateRuleTree(String ruleToBeSelected) { TreePath ttt = new TreePath(rootNode); Enumeration<TreePath> expandedDescendants = trRuleList.getExpandedDescendants(ttt); expandedNodes = (expandedDescendants == null ? new ArrayList<>() : Collections.list(expandedDescendants)); if (rootNode != null) { rootNode.removeAllChildren(); } for (Rule rule : exportRuleSet.getRules().values()) { String ruleName = rule.getName(); DefaultMutableTreeNode ruleNode = new DefaultMutableTreeNode( new Item(ruleName, ROOTNODE, ItemType.RULE)); rootNode.add(ruleNode); FileMIMETypeCondition fileMIMETypeCondition = rule.getFileMIMETypeCondition(); if (fileMIMETypeCondition != null) { ruleNode.add( new DefaultMutableTreeNode(new Item("MIME Type", ruleName, ItemType.MIME_TYPE_CLAUSE))); } List<FileSizeCondition> fileSizeConditions = rule.getFileSizeConditions(); for (FileSizeCondition fsc : fileSizeConditions) { ruleNode.add(new DefaultMutableTreeNode(new Item("File Size", ruleName, ItemType.SIZE_CLAUSE))); } for (Rule.ArtifactCondition artifact : rule.getArtifactConditions()) { DefaultMutableTreeNode clauseNode = new DefaultMutableTreeNode( new Item(artifact.getTreeDisplayName(), ruleName, ItemType.ARTIFACT_CLAUSE)); ruleNode.add(clauseNode); } } ((DefaultTreeModel) trRuleList.getModel()).reload(); // Re-expand any rules that were open previously and that still exist for (TreePath e : expandedNodes) { TreePath treePath = findTreePathByRuleName(e.getLastPathComponent().toString()); trRuleList.expandPath(treePath); } expandedNodes.clear(); // select the rule to leave the cursor in a logical place if (ruleToBeSelected != null) { TreePath treePath = findTreePathByRuleName(ruleToBeSelected); treeSelectionModel.setSelectionPath(treePath); trRuleList.expandPath(treePath); } }
From source file:com.twinsoft.convertigo.engine.Context.java
public Map<String, List<String>> getRequestHeaders() { if (requestHeaders == null) { requestHeaders = new HashMap<String, List<String>>(); if (httpServletRequest != null) { for (String name : Collections .list(GenericUtils.<Enumeration<String>>cast(httpServletRequest.getHeaderNames()))) { String lowName = name.toLowerCase(); for (String value : Collections .list(GenericUtils.<Enumeration<String>>cast(httpServletRequest.getHeaders(name)))) { List<String> values = requestHeaders.get(lowName); if (values == null) { values = new LinkedList<String>(); requestHeaders.put(lowName, values); }//from ww w . j a v a 2 s. co m values.add(value); } } } requestHeaders = Collections.unmodifiableMap(requestHeaders); } return requestHeaders; }
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
private static Permission[] expandUmbrella(Permission[] perms) { PermissionCollection pc = new Permissions(); for (Permission p : perms) { pc.add(p);//from www . j a va2 s . c o m } if (pc.implies(new UmbrellaGrantPermission())) { List l = Collections.list(pc.elements()); pc.add(new GrantPermission((Permission[]) l.toArray(new Permission[l.size()]))); } List<Permission> permList = new ArrayList<Permission>(); for (Enumeration<Permission> en = pc.elements(); en.hasMoreElements();) { permList.add(en.nextElement()); } return permList.toArray(new Permission[0]); }
From source file:moa.classifiers.rules.GeRules.java
public static void main(String[] args) throws Exception { // TODO Auto-generated method stub //ArffFileStream arffFileStream = new ArffFileStream("resources/UCI_KDD/nominal/cmc.arff", -1); // read arff file WEKA way DataSource source = new DataSource("data/cmc.arff"); // stream generator RandomTreeGenerator treeGenerator = new RandomTreeGenerator(); treeGenerator.numClassesOption.setValue(5); treeGenerator.numNumericsOption.setValue(0); treeGenerator.prepareForUse();//from ww w.j a va2 s .c o m // HoeffdingRules classifier GeRules gErules = new GeRules(); gErules.prepareForUse(); // load data into instances set Instances data = source.getDataSet(); // setting class attribute if the data format does not provide this information // For example, the XRFF format saves the class attribute information as well if (data.classIndex() == -1) data.setClassIndex(data.numAttributes() - 1); // Using Prism classifier //hoeffdingRules.learnRules(Collections.list(data.enumerateInstances())); for (Instance instance : Collections.list(data.enumerateInstances())) { gErules.trainOnInstanceImpl(instance); gErules.correctlyClassifies(instance); } Instance anInstance = Collections.list(data.enumerateInstances()).get(10); System.out.println(anInstance); for (Rule aRule : gErules.RulesCoveredInstance(anInstance)) { System.out.println(aRule.printRule()); } for (Rule aRule : gErules.rulesList) { System.out.println(aRule.printRule()); } }