Basic functional style question

mohan.radhakrishnan at polarisFT.com mohan.radhakrishnan at polarisFT.com
Tue Nov 26 22:38:33 PST 2013


Sent by mistake. The actual question is this.

The code in the previous mail works but when I use 'R' language this is 
accomplished by this line.

y <- apply( y, 1, function(z) str_extract(z,"Current.*?[/|]"))

I can again operate on the data structure like this.

z <- str_extract_all(y,"[0-9]+(/,|/|)")

I think this is possible using Streams and filters.

How should I use these lines without defining new Functional interfaces ?

        Scanner s = new Scanner( data );
        s.findInLine("Current.*?[/|]");
        System.out.println(s.match().group());

Thanks.



From:   Mohan Radhakrishnan/BSC31/polarisFT
To:     lambda-dev at openjdk.java.net
Date:   11/27/2013 11:57 AM
Subject:        Basic functional style question


Hi,

This is a question from a user. I am trying to jdk 8 to parse a file and 
apply a regex on it.

public class GCLogParser {

    private void readFile() throws IOException {

        Stream<String> s = Files.lines(get(("D:\\GC 
Analysis\\usage.txt")), UTF_8);
        s.forEach( this::parse  );
    }

    public static void parseDocument(  Parseable parser,
 String data){
        parser.apply(data);
    }
    private void parse( String data ){

        Scanner s = new Scanner( data );
        s.findInLine("Current.*?[/|]");
        System.out.println(s.match().group());
    }

    public static void main( String... argv ) throws IOException {
        new GCLogParser().readFile();
    }

    @FunctionalInterface
    public interface Parseable{
         void apply( String s);
    }
}



This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only.  If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately. You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit us at http://www.polarisFT.com


More information about the lambda-dev mailing list