Giter Club home page Giter Club logo

Comments (2)

javadev avatar javadev commented on April 28, 2024

Hi,
You may try to add import for underscore library and call for method intersection.

import com.github.underscore.$;

public class Main {
  public static void main(String[] args) {
    List<String> result = $.intersection(...);
  }
}

from underscore-java.

wirelesss avatar wirelesss commented on April 28, 2024

Thanks,

I found poor performance compared traditional method.

This is my suggestion:
Add intersection and notIntersection methods (2):

import static java.util.Arrays.asList;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.github.underscore.$;

import utils.TiempoEnum;
import utils.UtilsTiempo;

public class TestUnderscore2 {

public static <T> List<T> intersection(List<T> list1, List<T> list2) {
    List<T> list = new ArrayList<T>();
    for (T t : list1) {
        if(list2.contains(t)) {
            list.add(t);
        }
    }
    return list;
}

public static <T> List<T> intersection(List<T> list1, List<T> list2) {
    List<T> list = new ArrayList<T>();
    for (T t : list1) {
        if(!list2.contains(t)) {
            list.add(t);
        }
    }
    return list;
}

public static void main(String[] args){
    Date fecha1;
    Date fecha2;
    List<String> resultado;
    fecha1 = new Date();        
    resultado = $.intersection(asList("101", "2", "1", "10"), asList("2", "1"));
    fecha2 = new Date();
    System.out.println("Diff time ms underscore:"+UtilsTiempo.diferenciaEntreFechasMensaje(fecha1, fecha2, TiempoEnum.CTE_TIPO_TIEMPO_MILISEGUNDOS, TiempoEnum.CTE_FORMATO_TIEMPO_EN_UNIDAD));
    System.out.println("resultado100:");
    System.out.println(resultado.toString());

    fecha1 = new Date();        
    resultado = intersection(asList("102", "3", "2", "11"), asList("3", "2"));
    fecha2 = new Date();
    System.out.println("Diff time ms traditional:"+UtilsTiempo.diferenciaEntreFechasMensaje(fecha1, fecha2, TiempoEnum.CTE_TIPO_TIEMPO_MILISEGUNDOS, TiempoEnum.CTE_FORMATO_TIEMPO_EN_UNIDAD));             
    System.out.println("resultado100:");
    System.out.println(resultado.toString());
}

}

I hope you accept this improvement.
Regards.

from underscore-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.