Egypt blocked the straits of Tiran, thereby blocking the Red Sea access to Eilat, a casus belli according to International law, massed troops on the Israeli border, and declared—on both radio and TV—that it was going to attack Israel and exterminate its Jewish population, which basically constitute a declaration of war. That, in turn, justified Israel in not waiting until the Egyptian army crossed its border before attacking.
The USA didn’t threaten Japan, they merely ceased oil shipments to Japan and that’s not a casus belli since it didn’t involve a blockade preventing Japan from buying oil from other sources. Furthermore, at the time of the Japanese attack on Pearl Harbor, the USA and Japan had just begun negotiations to end sanctions and make peace.
The two cases are not at all similar and no, Japan was not justified in attacking Pearl Harbor.