/** * Note: If there exist duplicate message ids in the {@code msgs} list, the first one wins. * However, the source paths from subsequent duplicates will be added to the source paths for the * message. * * @param localeString The language/locale string of this bundle of messages, or null if unknown. * Should only be null for bundles newly extracted from source files. Should always be set * for bundles parsed from message files/resources. * @param msgs The list of messages. List order will become the iteration order. */ public SoyMsgBundleImpl(@Nullable String localeString, List<SoyMsg> msgs) { this.localeString = localeString; SortedMap<Long, SoyMsg> tempMsgMap = Maps.newTreeMap(); for (SoyMsg msg : msgs) { checkArgument(Objects.equal(msg.getLocaleString(), localeString)); long msgId = msg.getId(); if (!tempMsgMap.containsKey(msgId)) { // new message id tempMsgMap.put(msgId, msg); } else { // duplicate message id SoyMsg existingMsg = tempMsgMap.get(msgId); for (String source : msg.getSourcePaths()) { existingMsg.addSourcePath(source); } } } msgMap = ImmutableMap.copyOf(tempMsgMap); }
checkArgument(Objects.equals(msg.getLocaleString(), localeString)); checkArgument( msg.getAltId() < 0, "RenderOnlySoyMsgBundleImpl doesn't support alternate ID's.");
/** * Note: If there exist duplicate message ids in the {@code msgs} list, the first one wins. * However, the source paths from subsequent duplicates will be added to the source paths for the * message. * * @param localeString The language/locale string of this bundle of messages, or null if unknown. * Should only be null for bundles newly extracted from source files. Should always be set for * bundles parsed from message files/resources. * @param msgs The list of messages. List order will become the iteration order. */ public SoyMsgBundleImpl(@Nullable String localeString, List<SoyMsg> msgs) { this.localeString = localeString; this.locale = localeString == null ? null : new ULocale(localeString); this.isRtl = BidiGlobalDir.forStaticLocale(localeString) == BidiGlobalDir.RTL; // Preserve the ordering of the input. Map<Long, SoyMsg> tempMsgMap = new LinkedHashMap<>(); for (SoyMsg msg : msgs) { checkArgument(Objects.equals(msg.getLocaleString(), localeString)); long msgId = msg.getId(); SoyMsg existingMsg = tempMsgMap.get(msgId); if (existingMsg == null) { // new message id tempMsgMap.put(msgId, msg); } else { // duplicate message id for (SourceLocation source : msg.getSourceLocations()) { existingMsg.addSourceLocation(source); } } } msgMap = ImmutableMap.copyOf(tempMsgMap); }
checkArgument(Objects.equals(msg.getLocaleString(), localeString)); checkArgument( msg.getAltId() < 0, "RenderOnlySoyMsgBundleImpl doesn't support alternate ID's.");
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof SoyMsg) { SoyMsg that = (SoyMsg) o; return ((this.localeString == null) ? (that.getLocaleString() == null) : this.localeString.equals(that.getLocaleString())) && (this.id == that.getId()) && (this.altId == that.getAltId()) && ((this.meaning == null) ? (that.getMeaning() == null) : this.meaning.equals(that.getMeaning())) && ((this.desc == null) ? (that.getDesc() == null) : this.desc.equals(that.getDesc())) && (this.hidden == that.isHidden()) && ((this.contentType == null) ? (that.getContentType() == null) : this.contentType.equals(that.getContentType())) && (this.plrselMsg == that.isPlrselMsg()) && (this.parts.equals(that.getParts())); } return false; }
checkArgument(Objects.equals(msg.getLocaleString(), localeString)); long msgId = msg.getId();
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
new PlrselMsgPartsVisitor(node, new ULocale(soyMsg.getLocaleString())) .visitPart((SoyMsgPluralPart) firstPart); new PlrselMsgPartsVisitor(node, new ULocale(soyMsg.getLocaleString())) .visitPart((SoyMsgSelectPart) firstPart);
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
/** Creates a new {@link Builder} based on the current instance. */ Builder toBuilder() { Builder builder = builder() .setId(getId()) .setIsHidden(isHidden()) .setParts(getParts()) .addAllSourceLocations(getSourceLocations()) .setIsPlrselMsg(isPlrselMsg()); if (getLocaleString() != null) { builder.setLocaleString(getLocaleString()); } if (getMeaning() != null) { builder.setMeaning(getMeaning()); } if (getDesc() != null) { builder.setDesc(getDesc()); } if (getAltId() != -1) { builder.setAltId(getAltId()); } if (getContentType() != null) { builder.setContentType(getContentType()); } return builder; }