@Test public void mixedLanguageLiteralHandling() { Literal result = concatFunc.evaluate(vf, foo_nl, bar_en); assertThat(result.stringValue()).isEqualTo("foobar"); assertThat(result.getDatatype()).isEqualTo(XMLSchema.STRING); assertThat(result.getLanguage().isPresent()).isFalse(); }
@Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length == 0) { throw new ValueExprEvaluationException("CONCAT requires at least 1 argument, got " + args.length); } StringBuilder concatBuilder = new StringBuilder(); String commonLanguageTag = null; boolean useLanguageTag = true; for (Value arg : args) { if (arg instanceof Literal) { Literal lit = (Literal) arg; if (!QueryEvaluationUtil.isStringLiteral(lit)) { throw new ValueExprEvaluationException("unexpected datatype for CONCAT operand: " + lit); } if (useLanguageTag && Literals.isLanguageLiteral(lit)) { if (commonLanguageTag == null) { commonLanguageTag = lit.getLanguage().get(); } else if (!commonLanguageTag.equals(lit.getLanguage().orElse(null))) { commonLanguageTag = null; useLanguageTag = false; } } else { useLanguageTag = false; } concatBuilder.append(lit.getLabel()); } else { throw new ValueExprEvaluationException("unexpected argument type for CONCAT operator: " + arg); } } Literal result = null; if (useLanguageTag) { result = valueFactory.createLiteral(concatBuilder.toString(), commonLanguageTag); } else { result = valueFactory.createLiteral(concatBuilder.toString()); } return result; }
Concat implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length == 0) { throw new ValueExprEvaluationException("CONCAT requires at least 1 argument, got " + args.length); } StringBuilder concatBuilder = new StringBuilder(); String commonLanguageTag = null; boolean useLanguageTag = true; for (Value arg : args) { if (arg instanceof Literal) { Literal lit = (Literal) arg; if (!QueryEvaluationUtil.isStringLiteral(lit)) { throw new ValueExprEvaluationException("unexpected datatype for CONCAT operand: " + lit); } if (useLanguageTag && Literals.isLanguageLiteral(lit)) { if (commonLanguageTag == null) { commonLanguageTag = lit.getLanguage().get(); } else if (!commonLanguageTag.equals(lit.getLanguage().orElse(null))) { commonLanguageTag = null; useLanguageTag = false; } } else { useLanguageTag = false; } concatBuilder.append(lit.getLabel()); } else { throw new ValueExprEvaluationException("unexpected argument type for CONCAT operator: " + arg); } } Literal result = null; if (useLanguageTag) { result = valueFactory.createLiteral(concatBuilder.toString(), commonLanguageTag); } else { result = valueFactory.createLiteral(concatBuilder.toString()); } return result; } }
Concat implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length == 0) { throw new ValueExprEvaluationException("CONCAT requires at least 1 argument, got " + args.length); } StringBuilder concatBuilder = new StringBuilder(); String commonLanguageTag = null; boolean useLanguageTag = true; for (Value arg : args) { if (arg instanceof Literal) { Literal lit = (Literal) arg; if (!QueryEvaluationUtil.isStringLiteral(lit)) { throw new ValueExprEvaluationException("unexpected datatype for CONCAT operand: " + lit); } if (useLanguageTag && Literals.isLanguageLiteral(lit)) { if (commonLanguageTag == null) { commonLanguageTag = lit.getLanguage().get(); } else if (!commonLanguageTag.equals(lit.getLanguage().orElse(null))) { commonLanguageTag = null; useLanguageTag = false; } } else { useLanguageTag = false; } concatBuilder.append(lit.getLabel()); } else { throw new ValueExprEvaluationException("unexpected argument type for CONCAT operator: " + arg); } } Literal result = null; if (useLanguageTag) { result = valueFactory.createLiteral(concatBuilder.toString(), commonLanguageTag); } else { result = valueFactory.createLiteral(concatBuilder.toString()); } return result; }  }
Concat implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length == 0) { throw new ValueExprEvaluationException("CONCAT requires at least 1 argument, got " + args.length); } StringBuilder concatBuilder = new StringBuilder(); String commonLanguageTag = null; boolean useLanguageTag = true; for (Value arg : args) { if (arg instanceof Literal) { Literal lit = (Literal) arg; if (!QueryEvaluationUtil.isStringLiteral(lit)) { throw new ValueExprEvaluationException("unexpected datatype for CONCAT operand: " + lit); } if (useLanguageTag && Literals.isLanguageLiteral(lit)) { if (commonLanguageTag == null) { commonLanguageTag = lit.getLanguage().get(); } else if (!commonLanguageTag.equals(lit.getLanguage().orElse(null))) { commonLanguageTag = null; useLanguageTag = false; } } else { useLanguageTag = false; } concatBuilder.append(lit.getLabel()); } else { throw new ValueExprEvaluationException("unexpected argument type for CONCAT operator: " + arg); } } Literal result = null; if (useLanguageTag) { result = valueFactory.createLiteral(concatBuilder.toString(), commonLanguageTag); } else { result = valueFactory.createLiteral(concatBuilder.toString()); } return result; }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args); }
Concat implements Function { @Override public Literal evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length == 0) { throw new ValueExprEvaluationException("CONCAT requires at least 1 argument, got " + args.length); } StringBuilder concatBuilder = new StringBuilder(); String commonLanguageTag = null; boolean useLanguageTag = true; for (Value arg : args) { if (arg instanceof Literal) { Literal lit = (Literal) arg; if (!QueryEvaluationUtil.isStringLiteral(lit)) { throw new ValueExprEvaluationException("unexpected datatype for CONCAT operand: " + lit); } if (useLanguageTag && Literals.isLanguageLiteral(lit)) { if (commonLanguageTag == null) { commonLanguageTag = lit.getLanguage().get(); } else if (!commonLanguageTag.equals(lit.getLanguage().orElse(null))) { commonLanguageTag = null; useLanguageTag = false; } } else { useLanguageTag = false; } concatBuilder.append(lit.getLabel()); } else { throw new ValueExprEvaluationException("unexpected argument type for CONCAT operator: " + arg); } } Literal result = null; if (useLanguageTag) { result = valueFactory.createLiteral(concatBuilder.toString(), commonLanguageTag); } else { result = valueFactory.createLiteral(concatBuilder.toString()); } return result; }  @Override String getURI(); @Override Literal evaluate(ValueFactory valueFactory, Value... args);  }