⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classificationfilterruleimpl.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.entities.dynamictype.internal;

import java.util.Iterator;

import org.rapla.entities.EntityNotFoundException;
import org.rapla.entities.dynamictype.Attribute;
import org.rapla.entities.dynamictype.ClassificationFilterRule;
import org.rapla.entities.dynamictype.DynamicType;
import org.rapla.entities.storage.RefEntity;
import org.rapla.entities.storage.EntityReferencer;
import org.rapla.entities.storage.EntityResolver;
import org.rapla.entities.storage.internal.ReferenceHandler;

public final class ClassificationFilterRuleImpl
    implements
        ClassificationFilterRule
        ,EntityReferencer
        ,java.io.Serializable
{
    // Don't forget to increase the serialVersionUID when you change the fields
    private static final long serialVersionUID = 1;
    
    String[] operators;
    Object[] unresolvedRuleValues;
    boolean[] valueNeedsResolving;
    transient Object[] ruleValues;
    Object attributeId;
    ReferenceHandler referenceHandler = new ReferenceHandler();

    ClassificationFilterRuleImpl(DynamicType type,Attribute attribute, String[] operators,Object[] ruleValues) {
        referenceHandler.put("dynamictype",type);
        attributeId = ((RefEntity) attribute).getId();
        this.operators = operators;
        this.ruleValues = ruleValues;
        unresolvedRuleValues = new Object[ruleValues.length];
        valueNeedsResolving = new boolean[ruleValues.length];
        for (int i=0;i<ruleValues.length;i++) {
            if (ruleValues[i] instanceof RefEntity)
            {
                referenceHandler.put(String.valueOf(i),ruleValues[i]);
                //unresolvedRuleValues[i] = ((Entity)ruleValues[i]).getId();
                valueNeedsResolving[i] = true;
            }
            else
            {
                unresolvedRuleValues[i] = ruleValues[i];
                valueNeedsResolving[i] = false;
            }
        }
    }


    public void resolveEntities( EntityResolver resolver) throws EntityNotFoundException {
        referenceHandler.resolveEntities( resolver );
    }

    public boolean isRefering(RefEntity object) {
        return referenceHandler.isRefering(object);
    }

    public Iterator getReferences() {
        return referenceHandler.getReferences();
    }

    public boolean needsChange(Attribute typeAttribute) {
        Object[] ruleValues = getValues();
        for (int i=0;i<ruleValues.length;i++)
            if (typeAttribute.needsChange(ruleValues[i]))
                return true;
        return false;
    }

    public void commitChange(Attribute typeAttribute) {
        Object[] ruleValues = getValues();
        for (int i=0;i<ruleValues.length;i++) {
            Object oldValue = ruleValues[i];
            Object newValue = typeAttribute.convertValue(oldValue);
            ruleValues[i] = newValue;
        }
    }

    
    /** find the attribute of the given type that matches the id */
    private Attribute findAttribute(DynamicType type,Object id) {
        Attribute[] typeAttributes = type.getAttributes();
        for (int i=0; i<typeAttributes.length; i++) {
            if (((RefEntity)typeAttributes[i]).getId().equals(id)) {
                return typeAttributes[i];
            }
        }
        return null;
    }
    public Attribute getAttribute() {
        return findAttribute(getDynamicType(), attributeId);
    }
    
    public DynamicType getDynamicType() {
        return (DynamicType)referenceHandler.get("dynamictype");
    }

    public String[] getOperators() {
        return this.operators;
    }

    public Object[] getValues() {
        if (ruleValues == null)
            ruleValues = new Object[operators.length];
        for (int i=0;i<unresolvedRuleValues.length;i++) {
            if (valueNeedsResolving[i])
            {
                ruleValues[i] = referenceHandler.get(String.valueOf(i));
            }
            else
            {
                ruleValues[i] = unresolvedRuleValues[i];
            }
        }
        return ruleValues;
    }

    public Object clone() {
        return new ClassificationFilterRuleImpl(getDynamicType(),getAttribute(),getOperators(),getValues());
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -