Java Code Examples for org.openrdf.query.BindingSet#size()

The following examples show how to use org.openrdf.query.BindingSet#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebTestUtils.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * Copied from org.openrdf.query.QueryResultUtil
 */
private static boolean bindingSetsMatch(final BindingSet bs1, final BindingSet bs2) {

	if (bs1.size() != bs2.size()) {
		return false;
	}

	for (Binding binding1 : bs1) {
		Value value1 = binding1.getValue();
		Value value2 = bs2.getValue(binding1.getName());

		if ((value1 instanceof BNode) && (value2 instanceof BNode)) {
			// BNode mappedBNode = bNodeMapping.get(value1);
			//
			// if (mappedBNode != null) {
			// // bNode 'value1' was already mapped to some other bNode
			// if (!value2.equals(mappedBNode)) {
			// // 'value1' and 'value2' do not match
			// return false;
			// }
			// } else {
			// // 'value1' was not yet mapped, we need to check if 'value2'
			// // is a
			// // possible mapping candidate
			// if (bNodeMapping.containsValue(value2)) {
			// // 'value2' is already mapped to some other value.
			// return false;
			// }
			// }

			return value1.equals(value2);
		} else {
			// values are not (both) bNodes
			if ((value1 instanceof Literal) && (value2 instanceof Literal)) {
				// do literal value-based comparison for supported datatypes
				Literal leftLit = (Literal) value1;
				Literal rightLit = (Literal) value2;

				URI dt1 = leftLit.getDatatype();
				URI dt2 = rightLit.getDatatype();

				if ((dt1 != null) && (dt2 != null) && dt1.equals(dt2) && XMLDatatypeUtil.isValidValue(leftLit.getLabel(), dt1)
						&& XMLDatatypeUtil.isValidValue(rightLit.getLabel(), dt2)) {
					Integer compareResult = null;
					if (dt1.equals(XMLSchema.DOUBLE)) {
						compareResult = Double.compare(leftLit.doubleValue(), rightLit.doubleValue());
					} else if (dt1.equals(XMLSchema.FLOAT)) {
						compareResult = Float.compare(leftLit.floatValue(), rightLit.floatValue());
					} else if (dt1.equals(XMLSchema.DECIMAL)) {
						compareResult = leftLit.decimalValue().compareTo(rightLit.decimalValue());
					} else if (XMLDatatypeUtil.isIntegerDatatype(dt1)) {
						compareResult = leftLit.integerValue().compareTo(rightLit.integerValue());
					} else if (dt1.equals(XMLSchema.BOOLEAN)) {
						Boolean leftBool = Boolean.valueOf(leftLit.booleanValue());
						Boolean rightBool = Boolean.valueOf(rightLit.booleanValue());
						compareResult = leftBool.compareTo(rightBool);
					} else if (XMLDatatypeUtil.isCalendarDatatype(dt1)) {
						XMLGregorianCalendar left = leftLit.calendarValue();
						XMLGregorianCalendar right = rightLit.calendarValue();

						compareResult = left.compare(right);
					}

					if (compareResult != null) {
						if (compareResult.intValue() != 0) {
							return false;
						}
					} else if (!value1.equals(value2)) {
						return false;
					}
				} else if (!value1.equals(value2)) {
					return false;
				}
			} else if (!value1.equals(value2)) {
				return false;
			}
		}
	}

	return true;
}
 
Example 2
Source File: ASTEvalHelper.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Convert a Sesame {@link BindingSet} into a bigdata {@link IBindingSet}.
 * 
 * @param src
 *            The {@link BindingSet} (optional).
 * 
 * @return The {@link IBindingSet}. When the source is null or empty, an
 *         empty {@link ListBindingSet} is returned.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static IBindingSet[] toBindingSet(final BindingSet src) {
    
    if (src == null || src.size() == 0) {
        
        return new IBindingSet[] { new ListBindingSet() };

    }

    final ListBindingSet bindingSet = new ListBindingSet();

    final Iterator<Binding> itr = src.iterator();

    while (itr.hasNext()) {

        final Binding binding = itr.next();

        final IVariable<IV> var = com.bigdata.bop.Var.var(binding.getName());
        
        final IV iv = ((BigdataValue) binding.getValue()).getIV();
        
        final IConstant<IV> val = new Constant<IV>(iv);
        
        bindingSet.set(var, val);
        
    }
    
    return new IBindingSet[]{ bindingSet };

}