« first day (2040 days earlier)      last day (2892 days later) » 

3:47 AM
how does one write the logic for a sort. I feel damn retarded. I can do everything else except sort.
 
/javadoc Collections#sort
 
Which one do you mean? (type the number)
1. java.util.Arrays#sort(int[])
2. java.util.Arrays#sort(int[], int, int)
3. java.util.Arrays#sort(long[])
4. java.util.Arrays#sort(long[], int, int)
5. java.util.Arrays#sort(short[])
6. java.util.Arrays#sort(short[], int, int)
7. java.util.Arrays#sort(char[])
8. java.util.Arrays#sort(char[], int, int)
9. java.util.Arrays#sort(byte[])
10. java.util.Arrays#sort(byte[], int, int)
11. java.util.Arrays#sort(float[])
12. java.util.Arrays#sort(float[], int, int)
 
/javadoc Collections#sort
 
Which one do you mean? (type the number)
1. java.util.Collections#sort(List)
2. java.util.Collections#sort(List, Comparator)
 
@JohnnyCoder you have two options. Either implement Comparable or pass a Comparator to sort
Nice way is to pass your comparator as a Lambda
 List<Integer> list = Arrays.asList(10, 8, 2);
 Collections.sort(list, (a,b)->a-b);
(a,b) -> a - b is the lambda that represent the compare(T t, U u) in Comparator interface
 
 
2 hours later…
5:58 AM
@MadaraUchiha @fge @ItachiUchiha Sorry for the ping. I am learning Java 8 built-in functional interface. I know the most commonly used interfaces such as Supplier, Consumer, Predicate, BiPredicate, Function, etc I understand how they work. But I can't figureout When to use those. I mean, I try to build a simple problem by using them, i can't make a proper scenario. Can any of you help me to understand when to use those?
 
6:24 AM
@CrazyNinja The biggest use case is whenever you used to use anonymous classes with only one method
 
I am really struck when it comes to write a method to accept a Function<T,U>
 
@CrazyNinja Let's say you want to extract a certain property out of an object
But you don't know which property it is
 
ALright. I'm ready :)
 
You can request a Function<MyObject, TypeOfPropertyINeed> that will take the object, and return the value of the property you need
Effectively, you're asking for the caller from higher up the call stack to give you not only data, but also some of the logic to handle that data
 
public class Student{

String name; int admissionNo;

}
so, let's say that at some point, I need to get the name of a student, and at some point I need to get the admission no
are you talking about such a scenario?
 
6:28 AM
No, I'm talking about a scenario like "I have an Object in memory that si the result of JSON deserialization"
But I don't know the structure of the JSON in compile time
I want to get the "id"
 
hmm. okay
 
But I don't know how the property is named or how deep it is
I can offload that responsibility to someone who knows the specific details
And then my method can be a general "extract a property from a JSON object" method
 
But what I surely know is, that I can return the Id :)
 
@CrazyNinja Sometimes you need to make decisions in the lower level code based on higher level code. But you could only pass data in, not code.
So you'd resort to something like the Strategy Pattern, where you'd create objects with methods that do what you need
and use polymorphism so that you only need to care about which one in runtime
Lambda expression and functional interfaces are a more concise version of that.
(In Java, in other languages, higher order functions are used for more general abstraction purposes)
 
Can you do one more thing, can you show me an example where I can use a Predicate instead of using old Java?
I mean the advantage of using a Predicate over a old Java way
 
6:34 AM
@CrazyNinja Whenever you need to decide whether something is or isn't, but you don't want to know how to make that decision
 
While learning all these functional programming, I getting to know that, it has actually made the programs so much Flexible
 
I need to get ready to work
So maybe later I'll post an example
 
@CrazyNinja you can replace all if()inside a loop with filter() which accepts a Predicate
 
@MadaraUchiha appreciate your words! Sure, we'll talk this later. Tc
 
@CrazyNinja Its less verbose ;)
 
6:37 AM
@ItachiUchiha sorry. I haven't still came to filter(), but you are saying that, all if() can be replaced using Predicates?
 
Not really, Predicate have a method test() which take in a parameter and return either true or false.
/javadoc Predicate#apply
 
@ItachiUchiha boolean apply(Object input): Returns the result of applying this predicate to input. This method is generally expected, but not absolutely required, to have the following properties: Its execution does not cause any observable side effects. The computation is consistent with equals; that is, Objects.equal(a, b) implies that ...
predicate.apply(a) == predicate.apply(b)).
Which one do you mean? (type the number)
1. com.google.common.base.Predicate
2. java.util.function.Predicate
3. javax.persistence.criteria.Predicate
4. javax.sql.rowset.Predicate
5. org.mockito.cglib.core.Predicate
 
/javadoc Predicate
2
 
@ItachiUchiha java.util.function.Predicate: Represents a predicate (boolean-valued function) of one argument. @since 1.8 (1/2)
 
/javadoc Predicate#test
 
6:40 AM
@ItachiUchiha boolean test(Object t): Evaluates this predicate on the given argument.
 
yes
I understand those Interfaces, but can you please teach me, when to use those?
 
So, when we use it as a lambda expression, it knows that we want to invoke this method.
Can you write a small code to find all odd numbers between 1 - 100?
 
give me a sec
 
6:51 AM
public static void main(String[] ar){

List<Integer> numbers = new ArrayList<Integer>();

for (int i=0; i<100; i++)
numbers.add(i+1);

numbers.removeIf(n->checkEven(n));
numbers.forEach(System.out::println);

}

public static boolean checkEven(Integer n){
return n%2 == 0;
}
@ItachiUchiha am I using lambdas in correct manner?
 
numbers.removeIf(n->checkEven(n)); is using a Predicate internally
Moreover, it can be replaced by numbers.removeIf(n -> n%2 == 0);
 
woah. that sounds cool
 
@CrazyNinja Let's say you want to create a method that will filter an array to only contain odd numbers
You'd so something like
public int[] filterOdds(int[] in) {
  int[] result = new int[in.length];
  for (int i = 0; i < in.length; i++) {
    if (in[i] % 2 == 1) { result.push(in[i]); } // push? add? don't remember
  }
}
This is nice, but those well versed in functional programming would tell you that you're tightly coupled to your filtering check
And the solution is to pass the way to do the check into the function, like so:
public int[] filterGenerally(IntPredicate p, int[] in) {
  int[] result = new int[in.length];
  for (int i = 0; i < in.length; i++) {
    if (p.test[in[i]])) { result.push(in[i]); } // push? add? don't remember
  }
  return result;
}

public int[] filterOdds(int[] in) {
  return filterGeneral(i -> i % 2 == 1, in);
}
Now, your filtering function can filter any array of ints in any way you want
 
7:18 AM
@MadaraUchiha Great!!! Now I saw one real usage of Predicate. Thanks alot. But does gives more control to clients from the code
that means, doesn't it become more fragile?
 
@CrazyNinja It's a question of "responsibility"
Sometimes, you don't want low level code to know things about what the high level code wants to do.
Read about the strategy pattern, every time you think you want a strategy pattern, you probably want a functional expression of some sort.
 
In strategy, we just say, we want something to be happen, but without caring about how they do it
Concrete may return, but clients only deal with the Interface
 
@CrazyNinja Which is exactly how functional interfaces work
"I don't care how you decide whether or not this element fits your criteria, it's up to you to decide, I'm only working with the interface"
You could rewrite filterOdds like so:
public int[] filterOdds(int[] in) {
  return filterGeneral(new IntPredicate() {
    public boolean test(int i) {
      return i % 2 == 1;
    }
  }, in);
}
 
But this is more likely, asking customer(client programmer) to come to kitchen and make his ordered Cheese burger at Macdonals(Server-side programmer who accepts Lambda).
 
8:06 AM
morn
 
@CrazyNinja No
It's more like (and I know it's still a bad example from the food industry), "tell me how you order your lettuce/pickles/cheese/burger in your burger at home"
 
 
2 hours later…
9:46 AM
Hello all, using File("").getAbsolutePath is it possible to go one directory up?
String path = new File("").getAbsolutePath() + "/.././" + "/Core/src/main/resources/assets/images/level1.tmx";
I tried that but does not work
Because it is showing this:

C:/Users/........................./Dario2D/Dario2D/application/target/dario2d/Core/src/main/resources/assets/images/level1.tmx
what I want it to do is to go back to the same level as application and find Core in there
and as mentiod I tried using /.././ but it does not work
 
 
3 hours later…
12:54 PM
@Spiderix first... use java.nio.Path
second: use .getParent()
 
1:50 PM
    org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as assignation sequence: "${binding}" (fragments/quill_editor:9)
    quill_editor:9



    <div th:fragment="editor(binding)">
        <div class="ql-toolbar ql-snow" th:attr="${binding}">
    and here the replacement:

 <div th:replace="fragments/quill_editor :: editor(binding='data-bind=\'attr: {id: \'newsEntry_\'+ $parentContext.$index() +\'_lead_\' + $index() + \'_toolbar\'}\'')" >...</div>
 
Hi !
Have a quick question.
I need to write an existing file(not a text file) to directory. All of the examples, I have seen so far, require you to convert the file to byte array. Is it really necessary ?
 
2:24 PM
0
Q: How can I pass this string through thymeleaf th:replace?

PomeGranateOriginally my index.html looked like this: <div data-bind="attr: {id: 'newsEntry_'+ $parentContext.$index() +'_lead_' + $index() + '_toolbar'}"> ... </div> which works! I separated that part to an external edit.html file and includet it with thymeleafs th:replace to my ind...

 
hi
any observable list experts here?
i am trying to get the 3rd element from an observable list. how do i do that?
ObservableList<ArrivalRecord> selectedItems = arvtable.getSelectionModel().getSelectedItems();
 
@Zombievirus why would you need the third item? Can you even guarantee there is three items in the list?
 
the observable list has the entire row of a tableview saved inside of it.
 
but in general... ObservableList implements List... so you can just use that
 
there are 11 columns in the row
 
2:30 PM
@Zombievirus that's something completely different
you want the third column in the first record?
 
the observable list only saves the selected recorde
so there is only one record (row) saved in the list
and yes, the third column is what i want
 
soo.. why do you getSelectedItems()?
I assume you have your selection model in SelectionMode.SINGLE, right?
 
to get the entire row. so all the 11 columns at once
 
just use getSelectedItem()
which skips the whole ObservableList carp
 
ok and how do i get the specific column
 
2:32 PM
Well... how would I know?
 
Morning, Java!
 
it's a property on ArrivalRecord just use the getter on your bean
@OakBot you der?
 
@Vogel612 Type /help to see all my commands.
 
/javadoc ObservableList#get
 
Which one do you mean? (type the number)
1. javafx.collections.ObservableList#get(int)
2. android.databinding.ObservableList#get(int)
 
2:33 PM
1
 
@Vogel612 Object get(int index): Returns the element at the specified position in this list.
 
2:57 PM
well, it is just not working
how can i use a getter method on a specific cell of a non-specific row
for example get the value of the first cell in the selected row.
 
 
2 hours later…
4:38 PM
how do i determine whether to go with awt or swing?
i read up questions on SE explaining the differences between, still unsure
@CrazyNinja thanks!
i have to work on writing actual sort logic one of these days bc i suck at it :(
 
 
1 hour later…
5:44 PM
http://www.commitstrip.com/en/2016/05/24/training-the-newbie/
CommitStrip
Training the Newbie
CommitStrip
1464111752
 
6:39 PM
@JohnnyCoder the correct answer is neither
If you start a new Project, you should use JavaFX
 

« first day (2040 days earlier)      last day (2892 days later) »