Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Yotam Ohayon

Greenhorn
+ Follow
since Dec 31, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Yotam Ohayon

Hi guys i'm almost done writing my code and i'm stuck with this stupid thing. I can identify cases in which there's a unary minus before brackets (-[4 + 4]). here's my code:



it long i know. Expression object could be a constant, a variable or a function such as MAX{3,2} which is 3. expression() uses a tokenizer i have built to parse text into an expression, and sumExpression() uses expression() to create a new Expression which is a combination of two Expression object according to the right operator.

i hope its clear. as i said before i can't figure out how to identify the unary minus (-[4] would be -4) thing. i didn't put my tokenizer code, didn't think its necessary.

thanks!

P.S. the order of calculations is defined to be left to right with no regards to type of operator.
8 years ago
hi there... i am building a small scale interpreter. so far i have the capability to calculate mathematical expressions including
variables and several functions (such as MOD, MAX etc...). i need to add two capabilities:

Online Operator Overloading
Operator overloading is a term which refers to the creation of new operators which have the functionality of one
of your existing functions

so for example after typing overload *# POW, 3 *# 2 will result 9.

Inline Function Creation
In addition to operator overloading, you will also need to support inline function creation4. In other words, you
will support the creation of new functions, using the following syntax:
inline _FUNC{@arg1, @arg2, ...} <function code>

So, i have no idea where to start. If anyone can link me somewhere i can read about known techniques or existing java tools
that might help me, that would be very helpfull. I don't even know what to look for. thanks!
8 years ago
hi
i know i throw an exception when a method is not able to handle it,
but what should i consider when i decide where to catch it?
its a very general question i know, but i have only just began reading about it.
thanks!
8 years ago
hi
i have a little program here that gets a directory from the command line and adds all the files in this directory and its sub-folders.. so here's the code:

now when i run it on certain folders with not many files in them everything is okay, but when i feed it folders with a lot of files i get:


any idea as for why it happens? thanks!
p.s. i marked line numbers!
8 years ago
of course... as you might have understood i am trying to create objects (filters) according to the text i read
AFTER and GREATER are filters, NOT is not a filter. here's the code:

8 years ago
okay i've been studying regex for the past few hours and i'm getting there but not yet i have another problem now:
here's my text:



i want AFTER and GREATER, so i have the following regex:



at first its okay and i get AFTER, but the second time i get the entire line.
i tried add '?' before and after to turn it reluctant, also i tried \G to turn it global.
nothing works for me. in other times i used regex it has automatically started searching where last stopped, but not this time.
any suggestions?
thanks, Yotam
8 years ago
well
i went with TreeSet eventually
thanks!
8 years ago
i don't REALLY know them and what are their advantages. until i sort the file, i want them all in one data structure so i can iterate through them and filter them.
i was wondering if there is something faster then a TreeSet to do so, as TreeSet sorts by definition.
8 years ago
so
my program gets a directory, filter the files according to different filters, then perform several actions and return the files in a desired order.
i thought it is not necessary to order before i filter because then i would sort a lot of files for nothing. after the files are sorted i return them in a TreeSet.

so, my question is, what would be the best data structure to store the files before i put them in order? by best i mean in terms of run time of course.
thanks, yotam
8 years ago
i have indeed. here's my text:


and here's the code i worte down:


finally the output is :


so i can locate the name (ie AFTER GREATER BEFORE) but can't locate the condition (ie date or size) as it keeps reading to the next name (GREATER)
8 years ago
hi
i've been trying for some time now, but can't fully understand what i'm reading.
i want to create a regex pattern that will match any substring that starts with an underline '_' and ends with either a white space or end of line.

also, i've created this pattern "[A-Z]+" to look for words that contains ONLY capital letters. is this right?

thank you very much
YOtam
8 years ago
when you use a file.lastModified() method it returns a long value counting the time from 1970 or someting like that. is there any method you know
that can parse this long value into a date? i was looking for one but couldn't find it
8 years ago
i took a brief look at the API and it seems like it would do the job, only i now know we are instructed to use SimpleDateFormat
8 years ago
hi
i have two date, one of type long (retrieved from file.lastModified()) and the other date is a String object.
i was trying to figure out exactly how to parse them to the same form and compre them. i need to know which is after the other.
i was looking at SimpleDateFormat, DateFormat and Date and yet i still didn't manage to do it.
any suggestions?

thanks,
Yotam
8 years ago