Atitit. GroupBy LINQ Implementation (1)-----LINQ Framework Selection java. NET PHP

Source: Internet
Author: User
Tags stream api

Atitit. GroupBy LINQ Implementation (1)-----LINQ Framework Selection java. net PHP

The implementation method is as follows

1. Dsl/java8 Streams AP, targeted query API, recommended 1

2. Linq::: DSL 1 for like SQL

1.1. linq4j (JDK6 ok,jdk7 compilation error , horse jar download ) 1

1.2. Quaere: LINQon Java ( new sourcecode) 1

1.3. Josql is also API 2 similar to Quaere

1.4.. Net LINQ 2

3. SQL parsing 2

4. Lambda 2

5. GA Self-Implementation 3

1.5. LINQ4J Code 3

6. Apache Collections4 ( no , Trot on groupby) 3

7. Forest Bar ::: self DSL from Stream API jdk8 similar to 3

8. Stream API N LINQ different 3

9. Reference 3

Do report statistics Ah, there is a big problem. There is a whole collection of groupby Query Summary (Sum) No yo?? Already used linq4j,quaere,josql,,Ms to Map The dictionary does not work.

1. Dsl/java8 Streams AP, targeted query API, recommended

Persons1. GroupBy (A = a.name). Select (g = (New {name = G.key, Count

The advantage is that: Type-safe queries, and the ability to use smart tips!

2. Linq::: dsl1.1 of like SQL. LINQ4J (Jdk6 ok,jdk7Compile Error,another horse .JarDownload)

Linq4j d fun0, Fun1, fun2 is not a good DSL either.

Author :: Old Wow's paw attilax ayron,email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

1.2. Quaere:Javaon theLINQ(not new.sourcecode)

The following example obtains a list of product names from a product list:

List products = Arrays.aslist (Product.getallproducts ());
Iterable Productnames =
From ("P").
Select ("P.getproductname ()");

1.3.JosqlAlso withQuaeresimilar toAPI

This is a jar to download ... doesn't seem to support list (map), only list (bean)

caused by: java.lang.IllegalArgumentException : Cannot find method with Name:url in Class:java.util.Map

1.4.. NET LINQ

Statement Description: LINQ uses Group by and count to get the number of products in each CategoryID.

Description: First by CategoryID classification, remove the CategoryID value and the number of individual products.

1. Counting

1 var q =

2 from P in db. Products

3 Group p by P.categoryid into G

4 Select New {

5 G.key,

6 numproducts = g. Count ()

7};

3. SQL parsing

The disadvantage is that you cannot use the IDE smart hints

4. Lambda

5. GA Self-Realization

1.5. LINQ4J Code

linq4j. asEnumerable (emps)

            . GroupBy (

emp_deptno_selector , new Function0<< /c7>String>() {

public String apply() {

return null;

}

                 } &NBSP; new &NBSP; function2 < string &NBSP; employee &NBSP; string > ()  {

public string Apply (string /c8>v1, Employee e0) {

                    return v1 == NULL ? E0.name : (v1 + "+" + E0.name);

}

                 } &NBSP; new &NBSP; function2 < integer &NBSP; string &NBSP; string > ()  {

                    public   string &NBSP; apply ( integer  , v1 Span style= "COLOR: #707070" >  string   v2 )  {

return v1 + ":" + v2;

}

})

            . by (Functions.<String>identityselector())

            . toList ()

            . toString ();

6. Apache Collections4 (No, trot on GroupBy) 7. Lin Bar::: Own DSL from stream API jdk8 similar to 8. Stream API N LINQ differs

Stream is a lambda -based DSL, syntax not with a SQL Jas 10 ... This is more flexible . ...

Linq, Jas 10 DSL, walk Ten syntax with a SQL Jas 10 . LINQ is easier ...

9. Reference

How to convert a common LINQ expression to a Java 8 Streams API expression.

Linq uses Group by Experience summary -51cto.com.htm

Java8 How to perform stream,reduce,collection operations -51cto.com.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.