Apple's biggest competitors are HP, Dell, Acer, and Sony. Microsoft supplies those companies, but does not produce a PC. Apple doesn't license an OS.
I probably should have said Apple's biggest competitor is the Microsoft ecosystem. True, hardware wise it's Apple versus HP, Dell, Sony, etc... but in terms of mindshare, it's Apple versus Microsoft.
Similarly with Sun, it wasn't Sun verus the nebulous Linux. It was Sun versus the Linux ecosystem. You could argue too that one problem with Sun was that they sold hardware and software, and that you could get them separately.
But Sun, on the other hand, had a whole other set of problems. Apple is a consumer facing company. Sun is a business facing company. Sun's biggest competitor was Linux on any-brand PC server. That's a big challenge. So, they fought open source the only way they knew how... join them. If your biggest competitor is free running on commodity boxes, you have to go to that space. Unfortunately, there wasn't enough of a difference between Solaris and Linux to matter to most people, so they went with Linux. There is some great open source stuff in Solaris (ZFS, DTrace), but ultimately, there just wasn't enough 'there' there.
And then once you've lost the OS war, all that was left was hardware. Which, while high-quality, just wasn't enough to keep _all_ of Sun afloat. Perhaps though, it would have been enough to support the hardware divisions of Sun.