private void triggerOnAnchorChanged(Map<AnchorKey, ? extends String> oldValues, Map<AnchorKey, ? extends String> newValues) { // Get old values. If a component didn't change use its current value. String oldAnchorWavelet = (oldValues.containsKey(AnchorKey.WAVELET)) ? oldValues.get(AnchorKey.WAVELET) : anchor.get(AnchorKey.WAVELET); String oldAnchorBlipId = (oldValues.containsKey(AnchorKey.BLIP)) ? oldValues.get(AnchorKey.BLIP) : anchor.get(AnchorKey.BLIP); // Get new/current values from the underlying state. If a component didn't // change it will not be present in newValues. String newAnchorWavelet = anchor.get(AnchorKey.WAVELET); String newAnchorBlipId = anchor.get(AnchorKey.BLIP); AnchorData oldAnchor = new AnchorData(oldAnchorWavelet, oldAnchorBlipId); AnchorData newAnchor = new AnchorData(newAnchorWavelet, newAnchorBlipId); if (!oldAnchor.equals(newAnchor)) { for (Listener l : listeners) { l.onAnchorChanged(oldAnchor, newAnchor); } } } }
@Override public void setAnchor(AnchorData newAnchor) { anchor.set(CollectionUtils.immutableMap(AnchorKey.WAVELET, newAnchor.getConversationId(), AnchorKey.BLIP, newAnchor.getBlipId())); }
assertEquals("waveletid", anchor.getConversationId()); assertEquals("blipid", anchor.getBlipId()); target.setAnchor(new AnchorData("newwavelet", "newblip")); verify(anchorValue).set(CollectionUtils.immutableMap(AnchorKey.WAVELET, "newwavelet", AnchorKey.BLIP, "newblip")); CollectionUtils.immutableMap(AnchorKey.WAVELET, "newwavelet", AnchorKey.BLIP, "newblip")); verify(manifestListener).onAnchorChanged(new AnchorData("waveletid", "blipid"), new AnchorData("newwavelet", "newblip"));
@Override public AnchorData getAnchor() { return new AnchorData(anchor.get(AnchorKey.WAVELET), anchor.get(AnchorKey.BLIP)); }
private String getAnchorBlipId() { return manifest.getAnchor().getBlipId(); }
private WaveletId getAnchorWaveletId() { // may be null String anchorWaveletId = manifest.getAnchor().getConversationId(); return widFor(anchorWaveletId); }
assertEquals("waveletid", anchor.getConversationId()); assertEquals("blipid", anchor.getBlipId()); target.setAnchor(new AnchorData("newwavelet", "newblip")); verify(anchorValue).set(CollectionUtils.immutableMap(AnchorKey.WAVELET, "newwavelet", AnchorKey.BLIP, "newblip")); CollectionUtils.immutableMap(AnchorKey.WAVELET, "newwavelet", AnchorKey.BLIP, "newblip")); verify(manifestListener).onAnchorChanged(new AnchorData("waveletid", "blipid"), new AnchorData("newwavelet", "newblip"));
@Override public void setAnchor(Anchor newAnchor) { checkIsUsable(); if (newAnchor != null) { Preconditions.checkArgument(newAnchor.getConversation().getClass() == getClass(), "Anchor must not refer to a different conversation class"); Preconditions.checkArgument(newAnchor.getConversation() != this, "Anchor must not refer to a different anchored conversation"); WaveletBasedConversation conv = (WaveletBasedConversation) newAnchor.getConversation(); String blipId = newAnchor.getBlip().getId(); manifest.setAnchor(new AnchorData(idFor(conv.getWaveletId()), blipId)); } else { manifest.setAnchor(new AnchorData(null, null)); } }
private void triggerOnAnchorChanged(AnchorData oldMAnchor, AnchorData newMAnchor) { WaveletId oldWaveletId = maybeMakeWaveletId(oldMAnchor.getConversationId()); WaveletId newWaveletId = maybeMakeWaveletId(newMAnchor.getConversationId()); Anchor oldAnchor = maybeMakeAnchor(oldWaveletId, oldMAnchor.getBlipId()); Anchor newAnchor = maybeMakeAnchor(newWaveletId, newMAnchor.getBlipId()); triggerOnAnchorChanged(oldAnchor, newAnchor); }