« first day (1473 days earlier)      last day (3451 days later) » 

3:09 AM
Quiet hours~
 
4:06 AM
@Unihedron, days later, I am thinking about the enum casting we talked about earlier and I was wondering
if I set something like fruit: 2 in my database. How can I set the enum from that? So that I know 2 corresponds to Apple.
if I had something like public enum Fruits {
Apple(2);
 
Hi
 
 
4 hours later…
8:10 AM
Hi morning
I have a surious problem "java.lang.NoSuchMethodError "
for(Endorsement endo:endos) {
				col.add(new TLPolicyTransactionExtractionAdapter(endo));
			}
herethe problem is "new TLPolicyTransactionExtractionAdapter(endo)"
when I debug and try to verifiy the construct it tell me cannot resolve the constructor whereas I made a constructor in "TLPolicyTransactionExtractionAdapter"
it exist
and I compile my programm with the java 7 I didn't change the compiler
 
9:04 AM
HackOverflow is now in commitment!
@KalaJ Then you need a constructor for Apple(2). You can do this with Fruits(int value) {}, and to assign that value to the enum object, you need to declare the field within the enum object, like private final int value;, then you can use in constructor this.value = value;.
The class would look like:
public enum Fruits {
  Apple(2);
  private final int value; // This is field in enum object Fruits.ENUMNAME
  Fruits(int value) { // This allows Apple(2) to be valid syntax
    this.value = value; // this writes to field
  }
}
 
morning @Unihedron
 
Morning @fahdijbeli!
Ohai @Appu!
 
can I use log4j to check the problem ?
 
@fahdijbeli Is the class present in your run environment?
Actually, if you compiled with the jar defined within build path but your actual jar isn't the same class, a NoSuchMethodError will be thrown for undefined method invocation. So maybe you gotta update some jars. Just a guess though.
 
yes I update my project from SVN and I use one jdk/jre in my pc and I compiled the whole project
and how I can check if a class exist in my run environment
@Unihedron
 
9:18 AM
@fahdijbeli You can use Class.forName() - I don't think it's what you want though.
Is TLPolicyTransactionExtractionAdapter a class in a jar outside your compiled program, or a class within it?
 
a class is exist in the project compiled with the project
 
And the constructor exists right?
 
yes
this is the problem
the constructor is exist
 
Can you show me the constructor signature?
 
@Unihedron Howdy!
 
9:48 AM
sorry @Unihedron I left :(
@Unihedron this the constructor : public TLPolicyTransactionExtractionAdapter(IEndorsement endorsement) {
this.endorsement = endorsement;
this.policy = endorsement.getEndorsedPolicy();
}
realy it's very strange :(
 
Are you sure you don't have any old .jars or .classes lying around? If that compiles then the constructor should be available
 
I deleted them and I recompiled
I haven't olds jar
 
If you're using Maven, mvn clean is mandatory.
 
Strange. The class itself should be available or you'd get "class not found"... The exception is really for a missing constructor?
 
That's what I thought.
Actually, happen to share the exception stack trace pls?
I'll also work on the chat bot in a bit. Hopefully we'll be able to deploy him by the end of the week. we'll see.
 
10:38 AM
Hi guys
 
@MarcinSanecki 'allo
 
I am stucking with some Swing problem ;)
is there anyone who knows Swing
 
Just ask it.
 
I have a JTable and in one column JCheckBoxes (boolean values)
now I need to detect the row, col in which the checkbox was modified
any idea? I have googled and find nothing helpful
:\
general the logik is: to disable some other column in the row in which the checkbox is not selected
I need to detect the row num actually.... I have the rest
 
So you want to find the changed checkbox when the checkbox selection event was fired?
 
10:46 AM
you could get the checkbox from the event it fires..
 
but the checkbox doesn't tell me anything.... it's about table
 
bind an eventListener and use ActionEvent.getComponent()
and if you set things up properly you can use the checkbox you got to grab it's parent...
for that you can use UIComponent's getParent()
shouldn't be that hard actually..
you don't even need the row-index...
 
but the Partent is the Container means Dialog, Frame etc and not the Table
 
????
getComponent() should return the Checkbox you checked..
 
I need the row number - that is the point
 
10:49 AM
if it doesn't try getSource()
that seems to be an XYProblem...
if you have the row, why would you need the row-number??
 
one moment...
I don not have the row
the is the problem
I need to detect the row in which the user selected the checkbox
 
So what do you actually have?
 
the checkbox is in the JTable
 
so far so good...
 
Ok once again
 
10:51 AM
that's probably wrong, but carry on ;)
 
Continue?
 
there is a Dialog
in the dialog there is a JTable
one of the column in the table has boolean values
default cellrenderer shows them as checkboxes
there is another column in the table
now depends on the checkbox selection in some row another column should be disable/enadbled for editing
 
quick thrown up stream::
 
@MarcinSanecki So really, you need to find which row in the table the checkbox you have lives in.
 
10:54 AM
table.getRows().stream().filter(r -> r.getBooleanColumn()).forEach(r -> r.otherColumn().disable());
 
\o/ lambda expression
 
I am in the Java 1.6 wolrd
 
@Unihedron two of them in fact...
 
:(
 
exactlly
 
10:55 AM
for (Row r : table.getRows()) {
   if (r.getBooleanColumn()) {
      r.getOtherColumn().disable();
   }
}
^^ equivalent.
 
I will try your idea...
;) thx
 
@MarcinSanecki usually I am too...
that's why I like doing lambdas and streams whenever possible
 
@Vogel612 where have you found table.getRows()?
table is type of.. .?
 
that's a conjecture..
 
1 message moved to Trash
 
10:59 AM
I assumed your JTable was named table..
 
yep, there is no getRows in the JTable.... or?
maybe model... I am trying
 
you could go trough the model..
int count = model.getRowCount();
for (int i = 0; i < count; i++) {
   if ((Boolean)model.getValueAt(i, BOOL_COLUMN)) {
       // i is your row-index
   }
}
 
@Vogel612 the row-index is the unknown
 
no more now...
i is the row-index you are looking for if the value at [i, (columnIndex)] is true
 
@Vogel612 that is right!
 
11:05 AM
2 mins ago, by Vogel612
int count = model.getRowCount();
for (int i = 0; i < count; i++) {
   if ((Boolean)model.getValueAt(i, BOOL_COLUMN)) {
       // i is your row-index
   }
}
 
I thought it will be easier
 
it should be...
 
I mean that api support it
 
actually the way around through the model is...
yea...
JTable should be more of a facade, and less of a real class...
 
anyway thx @Vogel61
 
fge
11:14 AM
Moo
 
Ago
morning. I want to implement gomoku game in JavaFX. something where human can play against computer (or comp vs comp etc). how should I get user input (click event on the table) if I want to follow MVC pattern?
I guess in short: how should I read user input in MVC?
the board itself is a view
 
meow
@Ago key input listeners?
you can't use a scanner stream, for sure
 
Ago
mouse event rather, user clicks on the board
I know how to do it in JavaFX
it's more of a design question
is there a shortcut to reply?
 
I don't know.
 
Ago
@Unihedron mouse click event
@Unihedron
oh ok :)
sry for spamming
 
fge
11:22 AM
I should try my hands at GUI programming some day
 
@fge if you can help it... don't..
it's a mess..
 
fge
@Vogel612 in regards to what?
 
@Ago usually the Controller is responsible for taking the events of actions performed on the view...
@fge GUI Programming??
in regards to everything..
 
fge
@Vogel612 yes
Uh
I cannot take that for an answer :p
 
you change a single small thing like: "I want a 1px border"
and everything breaks...
it's just like css..
 
fge
11:25 AM
@Vogel612 that's not what I'm talking about
The fine points of tuning your GUI you learn along the way
I was rather talking about coming with a sane project structure
 
oh.. you mean... things with a GUI in general?
 
Ago
ok, yes, I take the event and handle it in controller. now, how should I propagate for example computer move to the view?
 
yea.. that's the interesting part of it.
 
@Ago No worries.
 
Ago
I could call view.show() for example after computer's move
 
11:26 AM
@Ago usually you make the controller ask the model, and then have it send the model to the view for handling..
how you do that??
no idea...
~gone
 
fge
@Ago make your computer another event source
 
@Vogel612 Bye!
 
fge
Just like the user
 
Ago
user is like view, or the input comes from there
but this sounds actually good to have computer as a source
 
I like your idea. Makes it more modular.
 
Ago
11:28 AM
I would do something like interface Player with a method makeMove(). now with PC, makeMove() calculates a move. but HumanPlayer's makeMove() would do nothing?
I think I'm a bit wrong with my design in that part
 
fge
@Ago eh, yeah, that's the tricky part and where I have zero knowledge, can't help you more, sorry :p
 
Ago
@fge thanks anyway :)
@fge your idea to have computer as a source sounds cool
 
fge
@Ago what about computeMove()? In the case of a CPU, it does compute a move; in the case of a human, it waits for GUI events
 
Ago
@fg
 
fge
Then use the result of that method to trigger GUI changes
 
Ago
11:31 AM
@fge then I should bind my player with the view. I would like to keep them separated
@fge ok, I could have some other tool to have the link, yes
 
Too vague, not experienced enough to have any opinion to give :(
 
Ago
other class I mean
 
fge
@Ago the view? I'd have said the controller
But that's a hunch
 
Ago
with those design patterns, its either it works or it looks good (from the design's perspective)
@fge yes, was mistaken there
 
fge
@Ago design patterns are tools, not an exact science
 
Ago
11:38 AM
let's say 2 cpus are playing. I have a controller, which knows about the players. player class has a method makeMove. controller can call this method, gets a move and visualize it.
in case of human, player should somehow get this move from the keyboard/mouse whatever
I'm sure there is a solution which is ok. but somehow in my head I cannot come up with it
 
fge
Well, isn't the view supposed to forward events to the controller? I don't see where the problem is, apart from the fact that if it is a player you need to register an event
 
Ago
you mean for example: if (humnaPlayer): getMoveFromView(); else: cpuPlayer.getMove() ?
 
fge
No
 
Ago
well, getMoveFromView() isn't actually called. the event gets sent from the view to controller. but I cannot register events all the time. in my code, I will listen to the user events when it's player's turn
 
fge
I mean that the player should be an interface, with an implementation for a human which listens for events (using a BlockingQueue for instance) and an implementation for the computer which does the move computation
Meh, that's all mental masturbation anyway, like I said I never programmed a GUI ;)
 
Ago
11:45 AM
ok, but thanks for your ideas
if I listen to those, it makes sense
haven't done any serious GUI either
 
fge
11:57 AM
@Ago which means you did some GUI work before
I haven't
Not even display a simple window :p
I'm a "server side" developer
 
I'm a software dev as well, I got a "Hello World" webpage once, took me three hours to set up :)
 
fge
@Unihedron ah, there I have an edge on you since my "real" work is as a systems engineer :p
 
Oh cool! Do you work systems analysis as well?
 
fge
Well, that was my job; since then I am looking to switch to dev stuff
 
:) That's amazing to hear, thanks for sharing!
 
fge
12:03 PM
Amazing, amazing...
 
Yes, it's spectacular.
Eh, I'll be right back.
 
12:19 PM
New reference link for pre-built boilerplate lessons: Pounding A Nail: Old Shoe or Glass Bottle?
 
public enum Fruits {
Apple(2);
private final int value;
Fruits(int value) { // This allows Apple(2) to be valid syntax
this.value = value; // this writes to field
}
}
I have a question about what you wrote here
 
Then ask it? There's no significant need to duplicate the code.
 
fge
@KalaJ before you ask your question, bury this in your mind
 
'Cuz I remember everything I write to quote it later. It's like my speech rebuilds the bible.
 
fge
@KalaJ enums are regular classes
 
12:24 PM
@fge inb4 yet another "y me no cant cast enum to int" problem ;)
 
Can I do something like this?
public enum Fruits {
Apple(2, "Apple");
private final int value;
private final String string;
Fruits(int value, String string) {
this.value = value;
this.string= string;
}
}
 
fge
@KalaJ it just happens that they are a syntactic sugar to create only certain instances at init time (in a static way)
 
@KalaJ yes
 
fge
@KalaJ yes
@KalaJ since enums are classes, they have constructors
 
Congrats, you understand partially what enums are!
 
fge
12:25 PM
And they can also have methods in them
 
So that if I find the Apple value in the database is 2.
 
fge
(although the syntax is a little peculiar)
 
I can grab the value of 2
and say, it's an apple
by taking the string from the enum?
 
Eh, yeah, but you need a getter. Since the string is private.
 
or is that redundant?
 
fge
12:26 PM
@KalaJ you can do that but it requires some code
Namely, a mapping
 
Look, I'll show you the idiom for enum matching:
 
Basically, I want to be able to map the value of 2 saved in column fruit in the db and map it to apple because Apple has value of 2.
Something like that
 
fge
@KalaJ have a look at an example of an enum class with "more than the basics": github.com/fge/jackson-coreutils/blob/master/src/main/java/com/…
In particular, line 82
 
public enum Fruits {
  Apple(2, "Apple");

  private final int value;
  private final String string;

  Fruits(int value, String string) {
    this.value = value;
    this.string = string;
  }
  public static Fruits fromInt(int value) {
    for (Fruits fruit : values())
      if (fruit.value == value)
        return fruit;
    return null;
  }
  public static Fruits fromString(String string) {
    for (Fruit fruit : values())
      if (fruit.string.equals(string))
        return fruit;
    return null;
From there you can use Fruits.fromInt(2).getString(); or something.
 
fge
Well, it's a class so you can override .toString() with enums as well
(maybe .equals() and .hashCode(), never tried that; but it does not really make sense for enums anyway)
 
12:31 PM
What is values()?
 
fge
@KalaJ an array of all your declared enum instances
For an enum X, .values() will return a X[]
Order of elements in this array are the same as the order in which you declared the values in your source file
See also .ordinal()
 
oh so I have to create an array for my enums
 
fge
No you don't
This array is automatically generated for you
Similarly, enums automatically implement Comparable
 
When I try Unihedron's code above, it says method call expected for values()
 
fge
It is because of a mispelling ;)
 
12:33 PM
Oh? Where?
 
fge
@Unihedron: Fruit vs Fruits
 
:(
 
fge
(in .fromString())
 
You're confusing hacking with cracking. The difference is this: Hackers builds things, crackers breaks them. — Unihedron 6 secs ago
 
I think it still an error
 
fge
12:36 PM
@Unihedron agreed
 
I am still getting method call expected? What does that mean?
 
fge
@KalaJ pastebin the source, please
 
or hastebin or pastie or gist or whatever
 
oh wait, I think I know lol
 
12:40 PM
My question is
instead of value, in my code I have id
can I use ids()?
lol
 
@KalaJ Write that function, then we can talk.
 
Dhttp://pastebin.com/F5Akac6D
That's what I have
 
values() is a method that comes built-in with every enum.
 
fge
Heh, I love the technology behind lambdas
Gives plenty of ideas
 
oh so I should still use values()
 
12:44 PM
@fge Oh, enlighten me?
 
fge
@Unihedron on what?
 
About lambdas
 
on it seems to work if I do Fruits.values()
*oh
Thanks Unihedron! I will test soon :D
 
Which IDE are you using? There should virtually be no problems calling a static context from an static method.
 
me?
In any case, I am using IntelliJ IDEA
 
12:49 PM
@KalaJ cool, good luck!
 
fge
@Unihedron basically, the compiler will infer the functional interface (when it can), generate call sites and then call invokedynamic
 
Cool beans!
So it's a smarter usage of bytecodes when a lambda is used instead of a loop?
 
fge
@Unihedron which means, in most cases it will just be static linking, and since invokedynamic links only once in that case, the JVM can perform optimizations such as inlining etc
@Unihedron this can be programmed too: docs.oracle.com/javase/8/docs/api/java/lang/invoke/…
Which is why other JVM languages (Jython, JRuby etc) perform so well since Java 1.7
 
:O
 
fge
Lambdas are dealt with internally though, so they can apply even better optimizations
 
12:54 PM
It's a revolutionary change!
 
fge
Yeah, indy is revolutionary
And I can't wait to find the time to apply it to grappa
 
So is this::monitorRooms better or () -> monitorRooms()?
 
fge
@Unihedron that's only syntactic sugar
In this case I surmise the compiler will generate the same code
@Unihedron as always with Java: write correct code first, the JVM will handle optimizations for you ;)
 
@fge :)
Algorithm > everything > optimization
 
fge
@Unihedron have a look at this also: stackoverflow.com/q/22561614/1093528 -- this was a question of mine which got me kickstarted on what lambas really were
And then I stumbled upon this: youtube.com/watch?v=C_QbkGU_lqY
Starting from there I started researching indy a lot
 
12:59 PM
Wait, Java 8 was out in March?
 

« first day (1473 days earlier)      last day (3451 days later) »