All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dmfs.android.xmlmagic.builder.EqualsObjectBuilder Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
/*
 * Copyright (C) 2015 Marten Gajda 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.dmfs.android.xmlmagic.builder;

import org.dmfs.xmlobjects.ElementDescriptor;
import org.dmfs.xmlobjects.builder.AbstractObjectBuilder;
import org.dmfs.xmlobjects.pull.ParserContext;
import org.dmfs.xmlobjects.pull.XmlObjectPullParserException;


/**
 * A Builder that returns true if all child elements of the built element are equal (as of the {@link Object#equals(Object)} method.
 * 

* Example: * *

 * {@code
 * 
 *     
 *     
 * 
 * }
 * 
* * The result value of the equals element above will be true if and only if the column name of the provided cursor contains the string * "abc". *

* {@link org.dmfs.android.xmlmagic.Model#EQUALS} uses this builder. * * @author Marten Gajda */ public class EqualsObjectBuilder extends AbstractObjectBuilder { @Override public Boolean get(ElementDescriptor descriptor, Boolean recycle, ParserContext context) throws XmlObjectPullParserException { // the default result is true return true; } @Override public Boolean update(ElementDescriptor descriptor, Boolean object, ElementDescriptor childDescriptor, V child, ParserContext context) throws XmlObjectPullParserException { if (!object) { // Condition is false already, at least one element didn't equal the others return object; } Object state = context.getState(); if (state == null) { context.setState(child); return object; } else { boolean result = state.equals(child); context.setState(child); return result; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy