<commit_before>/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01742
 *
 *  Web Site: http://www.concord.org
 *  Email: <EMAIL>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * END LICENSE */

/*
 * Created on Jul 28, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.concord.framework.otrunk;

import java.util.Vector;





/**
 * This class can be used to create more complex OTObjects.
 * The OTObject interface can be used for simple interfaces
 * that adhere to the current conventions of the OTrunk.
 * If there is an interface that doesn't follow these conventions
 * you can extend this class and make an OTResourceSchema 
 * interface to store the state.  The OTrunk will create a 
 * proxy class that implements this OTResourceSchema.  
 * 
 * TODO provide some pointers to examples.
 * 
 * @author scott
 *
 */
public class DefaultOTObject 
	implements OTObject, OTChangeNotifying
{
	private OTResourceSchema resources;
	
	private Vector changeListeners = new Vector();
    private OTChangeEvent changeEvent = new OTChangeEvent(this);
	
	public DefaultOTObject(OTResourceSchema resources)
	{
		this.resources = resources;		
	}
	
	//public DefaultOTObject(Vector userList) {
	//	this.userList = userList;
	//}
			
	public OTID getGlobalId()
	{
		return resources.getGlobalId();
	}
	
	public String getName()
	{
		return resources.getName();
	}
	
	public void setName(String name)
	{
		resources.setName(name);
	}

    /**
     * This method can be used by an object to get the object service
     * associated with this object.  This service can be used for creating
     * new objects, and getting objects from ids.
     * @return
     */
    protected OTObjectService getOTObjectService()
    {
        return resources.getOTObjectService();
    }
    
	public void init()
	{
	}
	
	public OTObject getReferencedObject(String id)
	{
        OTObjectService objService = resources.getOTObjectService();
	    OTID linkId = objService.getOTID(id);
	    if(linkId == null) {
	        return null;
	    }
	    return getReferencedObject(linkId);
	}
	
	public OTID getReferencedId(String id)
	{
        OTObjectService objService = resources.getOTObjectService();
        return objService.getOTID(id);
	}
	
	public OTObject getReferencedObject(OTID id)
	{
    	try {
            OTObjectService objService = resources.getOTObjectService();
    		return objService.getOTObject(id);
    	} catch (Exception e) {
    		e.printStackTrace();
    		return null;
    	}
	}	
	
	public boolean equals(Object other)
	{
		if(!(other instanceof OTObject)){
			return false;
		}
		
		if(this == other) {
			return true;
		}
		
		if(((OTObject)other).getGlobalId().equals(getGlobalId())) {
			System.err.println("compared two ot objects with the same ID but different instances");
			return true;
		}
		return false;
	}
	
	/* (non-Javadoc)
     * @see org.concord.framework.otrunk.OTChangeNotifying#addOTChangeListener(org.concord.framework.otrunk.OTChangeListener)
     */
    public void addOTChangeListener(OTChangeListener listener)
    {
        // TODO Auto-generated method stub
        if(changeListeners.contains(listener)) return;
        
        changeListeners.add(listener);
    }
    
    /* (non-Javadoc)<commit_msg>Implemented hashCode method for default object<commit_after>/*
 *  Copyright (C) 2004  The Concord Consortium, Inc.,
 *  10 Concord Crossing, Concord, MA 01742
 *
 *  Web Site: http://www.concord.org
 *  Email: <EMAIL>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * END LICENSE */

/*
 * Created on Jul 28, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.concord.framework.otrunk;

import java.util.Vector;

/**
 * This class can be used to create more complex OTObjects.
 * The OTObject interface can be used for simple interfaces
 * that adhere to the current conventions of the OTrunk.
 * If there is an interface that doesn't follow these conventions
 * you can extend this class and make an OTResourceSchema 
 * interface to store the state.  The OTrunk will create a 
 * proxy class that implements this OTResourceSchema.  
 * 
 * TODO provide some pointers to examples.
 * 
 * @author scott
 *
 */
public class DefaultOTObject 
	implements OTObject, OTChangeNotifying
{
	private OTResourceSchema resources;
	
	private Vector changeListeners = new Vector();
    private OTChangeEvent changeEvent = new OTChangeEvent(this);
	
	public DefaultOTObject(OTResourceSchema resources)
	{
		this.resources = resources;		
	}
	
	//public DefaultOTObject(Vector userList) {
	//	this.userList = userList;
	//}
			
	public OTID getGlobalId()
	{
		return resources.getGlobalId();
	}
	
	public String getName()
	{
		return resources.getName();
	}
	
	public void setName(String name)
	{
		resources.setName(name);
	}

    /**
     * This method can be used by an object to get the object service
     * associated with this object.  This service can be used for creating
     * new objects, and getting objects from ids.
     * @return
     */
    protected OTObjectService getOTObjectService()
    {
        return resources.getOTObjectService();
    }
    
	public void init()
	{
	}
	
	public OTObject getReferencedObject(String id)
	{
        OTObjectService objService = resources.getOTObjectService();
	    OTID linkId = objService.getOTID(id);
	    if(linkId == null) {
	        return null;
	    }
	    return getReferencedObject(linkId);
	}
	
	public OTID getReferencedId(String id)
	{
        OTObjectService objService = resources.getOTObjectService();
        return objService.getOTID(id);
	}
	
	public OTObject getReferencedObject(OTID id)
	{
    	try {
            OTObjectService objService = resources.getOTObjectService();
    		return objService.getOTObject(id);
    	} catch (Exception e) {
    		e.printStackTrace();
    		return null;
    	}
	}	

    public int hashCode()
    {
        String str = getClass().getName() + "@" +  getGlobalId();
        return str.hashCode();
    }
    
	public boolean equals(Object other)
	{
		if(!(other instanceof OTObject)){
			return false;
		}
		
		if(this == other) {
			return true;
		}
		
		if(((OTObject)other).getGlobalId().equals(getGlobalId())) {
			System.err.println("compared two ot objects with the same ID but different instances");
			return true;
		}
		return false;
	}
	
	/* (non-Javadoc)
     * @see org.concord.framework.otrunk.OTChangeNotifying#addOTChangeListener(org.concord.framework.otrunk.OTChangeListener)
     */
    public void addOTChangeListener(OTChangeListener listener)
    {
        // TODO Auto-generated method stub
        if(changeListeners.contains(listener)) return;
        
        changeListeners.add(listener);
    }
    
    /* (non-Javadoc)
{'fraction_non_alphanumeric': 0.08331332533013205, 'fraction_numerical': 0.007923169267707083, 'mean_word_length': 3.1365441906653424, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1366801', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2350, 'n_words': 823}