« first day (1356 days earlier)      last day (3584 days later) » 

12:00 AM
you can't assign operand to anything, it's been set already
in your class you can assign it
Umm I think I explained this once on SO, let me find the answer
7
A: Java code snippet - playing with variable final - explanation required

KylarOk, let's start with this: final Integer a = 1; You've created a final reference to an Integer object, which was autoboxed from a primitive int. This reference can be assigned exactly once, and never again. Integer b = a; here you've created a second reference to the same object, but this ...

 
oh the variable itself becomes unassignable
 
so if you do this:
 
final Object myObj = new Object();
you can't ever reassign myObj
Yeah
 
ok so in the method
i cant reassign a value to operand?
public void addThis(final int operand){
     operand = 100; // this would not work?
}
 
12:03 AM
right
it won't work at all
 
gotcha
awww yisss we are making progrissss
:D
 
but in java, you should never reassign an object that was passed into a method
that's really poor OO design
and whats more, primitives are passed by value, not reference
and references are copied for method invocations
 
ok i see
primitives like integers?
 
what about String types? are they considered primitives in java?
 
12:05 AM
No
String is an Object
 
ok
so its like C#
in that sense
 
only the very basics are primitives: int, char, byte, long
Integer, Character, Byte, Long, String are all object types
 
right on
 
My work day is rapidly drawing to a close
5 more mins and I'm out of here
 
nice, i hate waiting for the timer to be up
why not leave 5 early? fuck it :P
 
12:11 AM
Where in TO do you live
I lived there for a while in college
Went to school in Hamilton
 
I live in North York
just north of Toronto
ah The Hammer, did you go to UWaterloo?
 
Mohawk
UWaterloo is in Waterloo ;)
McMaster is in Hamilton
 
oh my goodness
im so sorry i meant McMaster
 
LOL
 
LOL
 
12:13 AM
My sister went there
 
sorry man
hahaha
 
Ahaha, I'm not the one embarrassed by his lack of geographical knowledge
 
i have a buddy whos up at McMaster right now, he loves it cuz Rogers is paying for his education :)
you know what it is? for some reason that hash in my mind didnt map hamilton to mcmaster
it mapped hamilton to waterloo hahahahaha
where do you live now?
 
Silicon Valley, California
Ok I'm out. TTYL peeps
 
ah, you went for the money
:P
alright man
 
12:18 AM
and glory. There's nowhere better to work
 
thanks so much! it was a pleasure talking to you! thanks again sir
 
and weather
 
:D
 
and money
;)
 
yes but i would so miss my family and friends
you cant pay for friends like mine!!!
 
12:18 AM
Vivé la revolucion!
Ask Stephanie. She wants to move to California already.
 
lol :D:D
 
>:)
 
hahaha nice u checked out my site?
she most definitely does not ill tell u that much lol
 
la revedere!
 
pa!
toate bunele!
 
1:01 AM
@Kylar LOL
 
hey whats so funny lol
 
Click the back arrow in my comment to see what I'm responding to. Made me laugh :)
Good evening.
 
good evening sir
hmm did you see the answer he wrote to me?
it doesnt work on a corner case i just discovered
hashMap.put("blog", "a");
hashMap.put("blog", "b");
hashMap.put("blag", "a");
that breaks it
cuz of blog now having two entries in the reverse hash
so still you need to iterate the reverse hash to remove a -> blog when updating with blog -> b
 
A map by definiton may not have duplicate keys
Perhaps you need the value to be a list of something?
Map<String,List<String>>
Then you can duplicate to your heart's content.
The single key refers to multiple values. Works with reverse maps too.
 
oh its not that - the restriction is that...
two keys cant have the same value
putting a->b and then c->b would result in a hash set with only c->b
but this is for a preinterview screening question so i KNOW there must be an elegant solution somehow
you know what i mean?
so i must make a HashMap thats basically a reverse hash map
 
1:11 AM
Map<String,List<String>> mapMain = new HashMap<String,List<String>>();
mapMain.put("blog", Arrays.asList(new String[]{"a"});
mapMain.put("blag", Arrays.asList(new String[]{"a"});
mapMain.get("blog").add("b");

Map<String,List<String>> mapReverse = new HashMap<String,List<String>>();
mapReverse.put("a", Arrays.asList(new String[]{"blog"});
mapReverse.get("a").add("blag");
mapReverse.put("b", Arrays.asList(new String[]{"blog"});
Handles duplicates on both sides of the reverse map.
Follow me?
(Arrays.asList actually returns an immutable list. Should actually be
 
you made the first mapping but i dont understand why you must map a record to two values in the array
this can get really tricky when you extend it to just a class like
static class UniqueHashMap<K, V> extends HashMap<K, V>
{
you know what i mean?
 
new ArrayList<String>(Arrays.asList(new String[]{"a"})))
Perhaps I'm missing something.
 
the datatype has to be UniqueHashMap<K, V>
 
You said "putting a->b and then c->b would result in a hash set with only c->b"
 
yes
 
1:18 AM
Using a list as the value in both the main and reverse maps can avoid this--it can allow both to have duplicates. key is a string, value is a list of strings.
You'll need to give me more background.
 
the datatype i have to implement takes <K, V> where V is not necessarily a list, so technically yes i could do it that way and have my datatype contain another map inside of it but it might be tricky
 
The value is forbidden to be a list then? It might be, but it must be allowed to be something else?
 
yes
 
So the keys in the reverse map are the values in the main map and vice versa. So you need duplicate keys, but a map by definition can't have duplicate keys.
That's a pickle.
 
right
so my idea was something like this
Put, for example would be:

public V put(K key, V value) {
            if (containsValue(value)) {
                Iterator iterator = entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry pairs = (Map.Entry)iterator.next();
                    if (value.equals(pairs.getValue())){
                        remove(pairs.getKey());
                        break;
                    }
                }
            }
            return super.put(key, value);
is that the correct way to iterate a HashSet for a certain value? seems to work just fine when i run it
but does it "look" like bad Java code?
 
1:29 AM
How is that any different than what a map already does? And how does that solve your problem of requiring duplicate keys (keys in the reverse map, which are values in the main map)?
 
its different because it removes keys with the same values as the ones you are trying to enter
which a map does not do
a map can have both "a"->"b" and "b"->"b" in it. my solution forces it to only contain one value
only contain unique values*
 
Ohhh. So you need a map where both the keys and values are unique?
How about, instead of overriding the put function, use a reverse map to do this for you.
Note that put returns the previous value, or null if there was none (assuming null is not a legal value).
 
yeah exactly
ok the problem with a reverse map is this
 
So use a reverse map as a filter.
 
i add "a"->"b", reverse map will then have "b"->"a" in it right?
 
1:39 AM
Right.
 
Now...if i add..."a"->"c", main map will not have ("a"->"c") in it, but the reverse map will have ("b"->"a", "c"->"a") in it...UNLESS i do the same thing i did in the code i sent you and checked that values are the same...
see you always wanna make sure the reverse map is identical to the reverse of the original map
otherwise youll have issues
 
Then do away with maps altogether, unless it's a requirement.
 
its not actually a requirement
so that i could do
but what would be the best most elegant solution here
i feel stumped!
the one time ive ever felt stumped on a programming problem lol
 
Seems darn complicated to mash this into maps.
 
on the most unrealistic problem ever...literally no applications
 
1:43 AM
What exactly are your requirements here? Give me some context.
 
they just want a 1-to-1 list essentially
requirements are to provide an implementation that provides all the features and behavior of HashMap EXCEPT it should...have unique values
that is all! lol
 
Well. That's all then.
 
maybe
theres a way to concat
the key and the value together
since its 1-to-1
ah fuck no, nevermind that wouldnt work...
 
Then how about two maps, where the value is a list.
 
or maybe its just easier to have two hashes, one with keys, one with values
 
1:46 AM
Just kidding.
Let me think.
 
lol
:D
 
A set contains the key portion only of a map, and requires no duplicates.
 
yeah
 
So, first step is to have a "key set" and a "value set". That handles the unique requirement.
Now, to associate them...
Do you need to reverse lookup? Given a value, find its key?
 
if HashMap has it
 
1:51 AM
Wait a minute. Why not have two maps? Main and reverse?
 
then i need to have it
well like i said earlier
 
Just check both maps. If the key is in the main, or value in the reverse, don't add it.
 
ok but when adding new values
you'd have to keep the reverse up to date
which would still require me to iterate through all the values of the reverse
 
17
Q: Java Collection - Unique Key and Unique Value

javacavajI need a collection that can lookup a value based on the key and vice versa. For every value there is one key and for every key there is one value. Is there a ready to use data structure out there that does this?

You don't need to iterate through anything.
If the value is the key in the reverse map, then don't add that pair to either map.
Wouldn't that fit the bill?
 
hmm
ill try to work that out but im not sure if it works
:(
i mean, i cant use a custom datatype from that question thats for sure, i have to implement it myself to demonstrate my skills
 
1:57 AM
Hell, then just override the put function like you said. But instead of iterating the values, use an internal value-set (or reverse-map) to hold the unique values for you.
What's this for? An interview?
 
yeah
 
Interesting problem. Hope I helped a teensy bit.
 
yeah i know lol
:P
such a nightmare
hey
if i have a HashMap<Character, Integer> hash
say my hash contains "a"->1
what code would i write to increment 1 by a value of 1 to get "a"->2 in my hash?
like, with actually doing an addition
on it
 
map.put('a', map.get('a')++)
Gotta go.
Nice talking to you @Alexandru. Good luck. in the interview.
 
thanks brother!
thanks :) haha
hope i solve this puzzle
 
 
2 hours later…
4:15 AM
Hi
 
@Alexandru Yes? Still working on your UniqueHashMap?
 
Alright, so I didn't actually want to drop my code to the public and this will probably get deleted at some point in time (its for a pre-interview screening question)
yes
here it is
static class UniqueHashMap<K, V> extends HashMap<K, V>
    {

        public HashMap<V, K> ReverseMap = new HashMap<V, K>();

        @Override
        public V put(final K key, final V value) {
            K matchesOnReverseKey = ReverseMap.get(value);
            if (matchesOnReverseKey != null)
            {
                super.remove(matchesOnReverseKey);
            }
            V matchOnMainValue = super.get(key);
            if (matchOnMainValue != null)
            {
                ReverseMap.remove(matchOnMainValue);
its basically a Bidirectional hash
so
all keys and all values are unique
i just started getting into java today since like 8 years so bear with me :)
so its different from a normal hash because a normal hash ensures all keys are unique, but im ensuring that keys are unique and that values are unique as well. and any new adds will drop old values, much like how the standard hash works
anyways, i just want putAll to actually iterate through the set and put each individual value in the hash
since...well, its the simplest thing i can think of
 
You should be getting an error on `@Override
public V remove(final Object key)` That's a raw key type.
 
no errors with that method
:P
runs just fine, and even calling it
not sure if it matters but im using javaSE 7
im also coding on this website which uses the javac compiler: compileonline.com/compile_java_online.php
 
I could rewrite it to something sensible, but using a Map<V, K> wouldn't be it. Why not use a Set<V> to store currently stored Values internally (and don't add a value that's also in your Set). Additionally, your method requires K and V to override hashCode(). There may be other issues with your code. That's very difficult to follow (and while you may have been away from java, I've done little else for about 15 years).
 
4:23 AM
because hashes are fast
thats why i didnt use a set
its bi-directional, its easy to say that using a Set would work but once you start implementing it and see how interesting of a problem it is
 
Hashes are not universally fast. If every object has the same hashcode they're a slower List.
 
then it becomes truly fun and hard
 
They generally have O(1) operations, but the constant can be quite large.
 
why is it such a huge problem to iterate through a K,V set?
 
Why do you think that's the problem?
 
4:25 AM
well my code works, all but putAll
ive tested everything else
except i just have problems implementing the putAll method
 
Great. But putAll does not work. And your other code seems to work for you, that's not the same as saying it works.
 
That's like if I were Einstein, and I had just found the theory of relativity, yet, i could not produce one experiment with it, but all the others worked, would that imply that the theory is not true? no
and the only reason why i coulodnt produce that experiment is because i didnt have a tool for it that i needed
i need putAll
 
Hello Java!
 
hi Appu
Elliot, is there no way for me to make putAll work in this light?
heres something that does compile for me:
but im not sure about the logistics (havent tested)
@Override
        public void putAll(final Map<? extends K,? extends V> m) {
            Iterator iterator = m.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry pairs = (Map.Entry)iterator.next();
                put((K)pairs.getKey(), (V)pairs.getValue());
            }
        }
 
@Alexandru I just updated my answer. Go take a look at your question.
 
4:32 AM
but it has some issues
Note: HelloWorld.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
ah what a relief
sigh
thanks so much
 
@Alexandru Make sure you accept the answer then! ;)
 
youre a breath of fresh air, Elliot, i was stuck on this one piece i see what you did there
i will :) haha
ill also add you on LinkedIn
cuz youre a cool cat
woot woot
alright so i just destroyed this interview screening
that was the final piece and trust me - making this bidirectional hash
took me all of the past 5 hours banging my head over it
testing, retesting, recording, major surgery headaches, trials & tribulations
bimap
but i didnt cheat, never looked at that source all that much :P
totally different implementation in my crazy mind
 
@Alexandru Good luck!
 
thanks!
 
4:53 AM
@Alexandru Where is your question?
 
 
8 hours later…
12:58 PM
Good morning.
 
1:24 PM
Why yes it is
 
Good morning, Java!
 
 
1 hour later…
2:35 PM
If either of you guys like Billy Joel: goo.gl/ZZOwyx and mediafire.com/download/rfdcdax2ufw8dbs/…
 
2:47 PM
Hello again!
 
 
1 hour later…
4:00 PM
HI
 
 
3 hours later…
6:50 PM
Hello room. Anyone still here?
I have a Servlet question.
 
I'll bite.
 
I'm trying to implement a shared resource for concurrency purposes.
The basic premise is that I'm using the doPost() method in a HTTPServlet
Requests come in and I get the Parameter values that are sent.
With those values, I perform some API calls which require first connecting to a server and then performing an action. I'd like to share this server connection between all requests so that I eliminate the need to connect/disconnect for every Request that comes in.
the API call I'm referring to looks something like this: api.setUser("user"), api.setPass("password"), api.Connect(), api.PerformAction(Parameter)
I'd like to have the connection be persistent and Thread safe so that every request that comes in can skip right to the api.PerformAction(Parameter) step and bypass all the connection overhead
Hopefully this makes sense... In researching this it seems like I should use Connection Pooling within Tomcat + JNDI. However most of the tutorials aren't very detailed and usually revolve around database connections and not an API connection like my case.
 
7:16 PM
So... you need a database, right?
as a caching layer
Or maybe Ehcache
 
No not a database. I just need to share an API connection between all the Requests my Servlet receives.
So that I can reduce the connection overhead and make it Thread safe.
 
Right, you need a proxy layer.
The underlying storage could be anything
Oh, so you don't need to share the results.
 
I need to configure Shared Resource, Connection Pool, JNDI in Tomcat.
 
You just need it to manage the threadpool of concurrent API requests on a single connection.
 
7:21 PM
ok, that's beyond me.
 
me too..
 
Haven't needed to mess with that.
 
Most of the examples are about sharing a database connection between servlet requests.
In my case its an API connection.
I'm unable to configure it properly.
Oh well. Elance, here I come.
 
 
1 hour later…
8:48 PM
@Alexandru I missed one step in that BiMap
 
9:14 PM
@Kylar There were a couple places!
But I implemented it in the end :)
woot woot
but u gave me a great idea
thanks mein broseph
 
10:09 PM
hey guys, getting a cannot invoke primite type error here: on this line first.matches("[^a-z0-9 ]")
 
Can you give the whole error, as well as what you're calling it from?
 
sure
Cannot invoke matches(String) on the primitive type char
first is an instance char variable. this is in the main method.
 
There should be a stack trace
and you should post your code in a past bin or fiddle
 
ok
ermm I don't know how to get the stack trace
 
You're calling matches() on a char type.
char is a primitive, not an object, you can't call methods on it
are you trying to see if the char first matches that regex?
Cause you're definitely doing it wrong
 
10:23 PM
yes
 
But in a larger point, you're trying to find the index of the first character that DOESN'T match that?
 
yeah, i don't want it to print the special characters
 
what about uppercase
A-Z not just a-z
 
yeah it's uppercase only
no need for the a-z i guess
 
spaces are OK?
 
10:25 PM
no
i'm trying to print off only the numbers and letters by incrementing. I don't want it to print off special chars, say if first = '5' , if incremented. it'll go 5,6,7,8,9,0,<,?
not sure if the special char print in that order. but I think you get my point
 
There's lots of special cases for that: Character.isAlphabetic() is probably what you want:
if(Character.isAlphabetic(first)){
//do something
}
 
what about numeric?
 
Numvers are considered Alphabetic
 
numeric && special cas
oh
did not know that
thank you
 
or isLetterOrDigit()
might be what you want
look at the JavaDoc:
 
10:29 PM
ok. thank you for the help Kylar :)
 
NP
 
10:55 PM
i am looking for actionScript3 help here. can i ask here?
 

« first day (1356 days earlier)      last day (3584 days later) »