As much as we would like to always be happy, when you are around those who aren't for long periods of time, it gets you in their particular mood. If you see those who are in a bad mood try to help them get in a better mood. It might make you feel good to help them. If you find that there is nothing that you can do then get out of the situation. Its not worth putting you in a bad mood too!
An opinion of mine..... Sometimes there are those friends who will always come to you to tell all their problems to. You should be sure to tell that friend when they cross the line. Sometimes enough is enough and you are not their personal sponge to suck up all their issues. If they seem to cross the line you will know. If it is leaving you to feel stressed out and if you begin to feel negative then that is when they crossed the line. Just as they are trying to talk to you about their problems, you should be able to talk to them when they made their problem yours. You want to be a friend, but they are not being a good friend if they are making you stress.