java : filter list of map sample
package homeWork;import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;public class filterSample {
public static void main(String[] args) {
Listcountry = new HashMap
();
country.put( "name", "france" );
country.put( "currency", "EUR" );
country.put( "population", 65073482 );
countries.add( country );
country = new HashMap();
country.put( "name", "japan" );
country.put( "currency", "JPY" );
country.put( "population", 56000 );
countries.add( country );
country = new HashMap
();
country.put( "name", "spain" );
country.put( "currency", "EUR" );
country.put( "population", 44904000 );
countries.add( country );country = new HashMap
();
country.put( "name", "russia" );
country.put( "currency", "RUB" );
country.put( "population", 141903979 );
countries.add( country );
for(Mapct:countries) {
System.out.println(ct.get("name")+":"+ct.get("population"));
}
System.out.println("-----------------------");
List> filterdList
= countries.stream().filter(m -> ( ( Integer ) m.get("population")) < 100000).collect(Collectors.toList());
for(Mapct:filterdList) {
System.out.println(ct.get("name")+":"+ct.get("population"));
}
}
}
japan:127156000
france:65073482
japan:56000
spain:44904000
russia:141903979
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
japan:56000
java : sort list of map by multiple key
package homeWork;import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public class sortSample001 {
public static void main(String[] args) {
List> countries = new ArrayList >();
Mapcountry;
country = new HashMap();
country.put( "name", "japan" );
country.put( "currency", "JPY" );
country.put( "population", 127156000 );
countries.add( country );country = new HashMap
();
country.put( "name", "france" );
country.put( "currency", "EUR" );
country.put( "population", 65073482 );
countries.add( country );
country = new HashMap();
country.put( "name", "japan" );
country.put( "currency", "JPY" );
country.put( "population", 56000 );
countries.add( country );
country = new HashMap
();
country.put( "name", "spain" );
country.put( "currency", "EUR" );
country.put( "population", 44904000 );
countries.add( country );country = new HashMap
();
country.put( "name", "russia" );
country.put( "currency", "RUB" );
country.put( "population", 141903979 );
countries.add( country );
for(Mapct:countries) {
System.out.println(ct.get("name")+":"+ct.get("population"));
}
System.out.println("-----------------------");
Comparator> c1 =Comparator.comparing (m -> (String) m.get("name"));
Comparator> c2 =Comparator.comparing (m -> (Integer) m.get("population"));
Comparator> c = c1.thenComparing(c2);
countries.sort(c);
for(Mapct:countries) {
System.out.println(ct.get("name")+":"+ct.get("population"));
}
}
}result
japan:127156000
france:65073482
japan:56000
spain:44904000
russia:141903979
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
france:65073482
japan:56000
japan:127156000
russia:141903979
spain:44904000
ldap with c# 2
search way1)with protocol
SearchRequest findme = new SearchRequest();
findme.DistinguishedName = "ou=People,dc=example,dc=com"; //Find all People in this ou
findme.Filter = "(objectClass=person)"; //The type of entry we are looking for
findme.Scope = System.DirectoryServices.Protocols.SearchScope.Subtree; //We want all
//entries below this ou
SearchResponse results = (SearchResponse)ldapConn.SendRequest(findme); //Run the query
//and get results
SearchResultEntryCollection entries = results.Entries;
for (int i = 0; i < entries.Count; i++)//Iterate through the results
{
SearchResultEntry entry = entries[i];
IDictionaryEnumerator attribEnum = entry.Attributes.GetEnumerator();
while (attribEnum.MoveNext())//Iterate through the result attributes
{
//Attributes have one or more values so we iterate through all the values
//for each attribute
DirectoryAttribute subAttrib = (DirectoryAttribute)attribEnum.Value;
for (int ic = 0; ic < subAttrib.Count; ic++)
{
//Attribute Name below
attribEnum.Key.ToString();
//Attribute Sub Value below
subAttrib[ic].ToString();
}
}
}2)
DirectorySearcher search = new DirectorySearcher(dirEntry);
search.Filter = "(objectClass=person)";
search.SearchScope = System.DirectoryServices.SearchScope.Subtree;
SearchResultCollection searchResults = search.FindAll();
for (int i = 0; i < searchResults.Count; i++)
{System.Collections.IDictionaryEnumerator subColl =
searchResults[i].Properties.GetEnumerator();
while (subColl.MoveNext())
{
ResultPropertyValueCollection pc = (ResultPropertyValueCollection)subColl.Value;
System.Collections.IEnumerator subPcol = pc.GetEnumerator();
while (subPcol.MoveNext())
{
//Property Name
subColl.Key.ToString();
//Property Value
subPcol.Current.ToString();
}
}
}
ldap with c#
http://www.codeproject.com/Articles/34468/Talk-to-Sun-One-LDAP-with-NET-DirectoryServices
1)way 1
//Use the servername and port that you setup LDAP Directory Service on
//9605 is the example port here
LdapDirectoryIdentifier ldapDir = new LdapDirectoryIdentifier("servername", 9605);
LdapConnection ldapConn = new LdapConnection(ldapDir);
//You may need to try different types of Authentication depending on your setup
ldapConn.AuthType = AuthType.Basic;
//Update the next line to include the Fully Qualified LDAP name
// of the user along with that user's password
System.Net.NetworkCredential myCredentials =
new System.Net.NetworkCredential("uid=admin,ou=Administrators,
ou=TopologyManagement,o=netscapeRoot", "password");
//This is the actual Connection establishment here
ldapConn.Bind(myCredentials);
2)way 2
irectoryEntry dirEntry = new DirectoryEntry();
dirEntry.Path = @"LDAP://servername:9605/dc=example,dc=com";
dirEntry.Username = "uid=admin,ou=Administrators,
ou=TopologyManagement,o=netscapeRoot";
dirEntry.Password = "password";
dirEntry.AuthenticationType = AuthenticationTypes.ServerBind;
dirEntry.RefreshCache();