Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * This program is free software; you can redistribute it and/or modify it under the
   * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
   * Foundation.
   *
   * You should have received a copy of the GNU Lesser General Public License along with this
   * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
   * or from the Free Software Foundation, Inc.,
   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * This program 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.
  *
  * Copyright (c) 2006 - 2009 Pentaho Corporation..  All rights reserved.
  */
 package org.pentaho.pms.schema.concept;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import  org.pentaho.di.core.changed.ChangedFlag;

Deprecated:
as of metadata 3.0. Please use org.pentaho.metadata.model.concept.Concept
 
 public class Concept extends ChangedFlag implements ConceptInterfaceCloneable
 {
     private String name;
 
     private ConceptInterface parentInterface;
 
     public Concept()
     {
     }
 
     public Concept(String name)
     {
         this();
         this. = name;
     }
 
     public Concept(String nameConceptInterface parentInterface)
     {
         this(name);
         this. = parentInterface;
     }
 
     public boolean equals(Object obj) {
       if (!(obj instanceof Concept)) {
         return false;
       }
       if (this == obj) {
         return true;
       }
       Concept rhs = (Conceptobj;
       return new EqualsBuilder().append(rhs.name).append(rhs.childPropertyInterfaces)
           .append(rhs.parentInterface).append(rhs.inheritedInterface)
           .append(rhs.securityParentInterface).isEquals();
     }
 
     public int hashCode() {
       return new HashCodeBuilder(131,  173 ).append().append().append()
     }
 
 //    public String toString() {
 //        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).
 //          append(type).
 //          append(width).
 //          toString();
 //    }
 
     public Object clone()
     {
         try
         {
             Concept concept = new Concept();
             concept.setName();
             concept.setParentInterface();
             concept.setInheritedInterface();
            if (!=nullconcept.setSecurityParentInterface((ConceptInterface.clone()); // deep copy of the security information
            String[] ids = getChildPropertyIDs();
            for (int i=0;i<ids.length;i++)
            {
                ConceptPropertyInterface property = getChildProperty(ids[i]);
                if (property!=null)
                {
                    concept.addProperty((ConceptPropertyInterface) ((ConceptPropertyBaseproperty).clone());
                }
            }
            concept.setChanged(hasChanged());
            return concept;
        }
        catch(CloneNotSupportedException e)
        {
            return null;
        }
    }
//    public String toString()
//    {
//        StringBuffer string = new StringBuffer();
//
//        // Print the properties...
//        String[] propertyIDs = getPropertyIDs();
//        for (int i = 0; i < propertyIDs.length; i++)
//        {
//            String id = propertyIDs[i];
//            String value = getProperty(id).toString();
//            if (i>0) string.append(", "); //$NON-NLS-1$
//            string.append(value);
//        }
//
//        return string.toString();
//    }
    public String toString() {
      return new ToStringBuilder(this.).append(this.)
  }

    

Returns:
the name
    public String getName()
    {
        return ;
    }

    

Parameters:
name the name to set
    public void setName(String name)
    {
        this. = name;
    }
    {
        return ;
    }
    {
        if (==nullreturn null;
        return .getPropertyInterfaces();
    }
    {
        if (==nullreturn null;
        return .getPropertyInterfaces();
    }
    {
        if (==nullreturn null;
    }

    

Returns:
a read-only list of properties: please modify using the child properties
    {
        // Properties inherited from the "logical relationship": BusinessColumn inherits from Physical Column, B.Table from Ph.Table
        //
        if (!=null)
        {
            all.putAll(.getPropertyInterfaces());
        }
        // Properties inherited from the pre-defined concepts like "Base", "ID", "Name", "Description", etc.
        //
        if (!=null)
        {
            all.putAll(.getPropertyInterfaces());
        }
        // The security settings from the security parent: Business table inherits from Business model, business column from business table
        //
        if (!=null// Only take over the security information, nothing else
        {
            String id = ..getId();
            ConceptPropertySecurity parentSecurityProperty = (ConceptPropertySecurity.getPropertyInterfaces().get(id);
            if (parentSecurityProperty!=null)
            {
               all.put(idparentSecurityProperty);
            }
        }
        // The child properties overwrite everything else.
        //
        all.putAll();
        return all;
    }
    public void setParentInterface(ConceptInterface parentInterface)
    {
        if ( (this.==null && parentInterface!=null) ||
             (this.!=null && parentInterface==null) ||
             (this.!=null && parentInterface!=null && !this..equals(parentInterface))
            )
        {
            setChanged(true);
        }
        this. = parentInterface;
    }
    {
        return ;
    }
    public void addProperty(ConceptPropertyInterface property)
    {
        .put(property.getId(), property);
        setChanged(true);
    }
    {
        return ;
    }
    public void setInheritedInterface(ConceptInterface inheritedInterface)
    {
        this. = inheritedInterface;
    }
    {
        return (ConceptPropertyInterfacegetPropertyInterfaces().get(id);
    }
    {
    }
    {
        if (==nullreturn null;
    }
    {
        if (==nullreturn null;
    }
    {
        if (==nullreturn null;
    }
    public void clearChanged()
    {
        setChanged(false);
    }
    public String[] getChildPropertyIDs()
    {
    }
    public String[] getPropertyIDs()
    {
    }
    private static final String[] getSortedPropertyIDs(Map<String,?> map)
    {
        Set<StringkeySet = map.keySet();
        List<Stringlist = new ArrayList<String>(keySet);
        Comparator<Stringcomparator = new Comparator<String>()
        {
            public int compare(String o1String o2)
            {
                String one = (Stringo1;
                String two = (Stringo2;
                int oneOrder = DefaultPropertyID.findDefaultPropertyOrder(one);
                int twoOrder = DefaultPropertyID.findDefaultPropertyOrder(two);
                if (oneOrder!=twoOrderreturn oneOrder-twoOrder;
                // Non-default properties: order by ID
                return one.compareTo(two);
            }
        };
        Collections.sort(listcomparator);
        return (String[])list.toArray(new String[list.size()]);
    }

    

Returns:
the depth from the root concept

Depth 1: child
Depth 2: child --> parent
Depth 3: child --> parent --> parent
etc.
    public int getDepth()
    {
        int depth = 0;
        ConceptInterface follow = this;
        while (follow!=null)
        {
            follow = follow.getParentInterface();
            depth++;
        }
        return depth;
    }

    

Returns:
the path from root --> .. --> gp --> parent --> concept
    public String[] getPath()
    {
        int depth = getDepth();
        String[] retval = new String[depth];
        int d=0;
        ConceptInterface follow = this;
        while (follow!=null)
        {
            retval[depth-d-1] = follow.getName();
            follow = follow.getParentInterface();
            d++;
        }
        return retval;
    }

    

Parameters:
path the path to match with
Returns:
true if the path matches the specified path from root --> .. --> gp --> parent --> concept
    public boolean matches(String[] path)
    {
        if (path.length==0) return false;
        int depth=0;
        ConceptInterface follow = this;
        while (follow!=null && depth<path.length)
        {
            if (!follow.getName().equals(path[path.length-depth-1])) return false;
            follow = follow.getParentInterface();
            depth++;
        }
        if (depth!=path.lengthreturn false;
        return true;
    }


    
Find a localized property (type ConceptPropertyType.PROPERTY_TYPE_LOC_STRING)

Parameters:
propertyName the name
locale the locale to search for
Returns:
the localized value (string) or null if nothing could be found
    public String getLocalizedProperty(String propertyNameString locale)
    {
        ConceptPropertyInterface property = getProperty(propertyName);
        if (property!=null && property.getType().equals(.))
        {
            LocalizedStringSettings locString = (LocalizedStringSettingsproperty.getValue();
            return locString.getString(locale);
        }
        return null;
    }

    
Add a localized string property (type ConceptPropertyType.PROPERTY_TYPE_LOC_STRING) to this concept

Parameters:
propertyName the name
locale the locale
value the value to store
    public void addLocalizedProperty(String propertyNameString localeString value)
    {
        // Get the property
        //
        ConceptPropertyInterface property = getChildProperty(propertyName);
        LocalizedStringSettings locStringSettings;
        // Found anything?
        if (property==null || (property!=null && !property.getType().equals(.)) || property.getValue()==null)
        {
            locStringSettings = new LocalizedStringSettings();
            // If there is no (or an empty) property or it somehow got the wrong type in there, we create a new one on that for that name...
            //
            property = new ConceptPropertyLocalizedString(propertyNamelocStringSettings);
            addProperty(property);
        }
        else
        {
            locStringSettings = (LocalizedStringSettingsproperty.getValue();
        }
        // Now, that we have the localized String settings property, add the localized value to it..
        locStringSettings.setLocaleString(localevalue);
    }

    

Returns:
The locale used in the properties of type Localized String
    public String[] getUsedLocale()
    {
        Map<String,Stringlocales = new Hashtable<String,String>();
        String[] propertyNames = getChildPropertyIDs();
        for (int i = 0; i < propertyNames.lengthi++)
        {
            ConceptPropertyInterface property = getProperty(propertyNames[i]);
            if (property.getType().equals(.))
            {
                // Yep, this is localized.
                LocalizedStringSettings locString = (LocalizedStringSettingsproperty.getValue();
                String[] locs = locString.getLocales();
                for (int j=0;j<locs.length;j++) locales.put(locs[j], ""); //$NON-NLS-1$
            }
        }
        Set<StringkeySet = locales.keySet();
        return (String[])keySet.toArray(new String[keySet.size()]);
    }

    
Get an array of the localized concept properties (ONLY type Localized String!!)

Parameters:
locale the locale to look for
Returns:
an array of the localized concept properties
    {
        List<ConceptPropertyInterfacepropertiesList = new ArrayList<ConceptPropertyInterface>();
        String[] propertyNames = getChildPropertyIDs();
        for (int i = 0; i < propertyNames.lengthi++)
        {
            ConceptPropertyInterface property = getProperty(propertyNames[i]);
            if (property.getType().equals(.))
            {
                // Yep, this is localized.
                LocalizedStringSettings locString = (LocalizedStringSettingsproperty.getValue();
                if (locString.getString(locale)!=null)
                {
                    // We have a property for this locale
                    // add it to the list or properties
                    propertiesList.add(property);
                }
            }
        }
        return (ConceptPropertyInterface[])propertiesList.toArray(new ConceptPropertyInterface[propertiesList.size()]);
    }

    
Special utility method: save a special localized property indicating the name

Parameters:
locale the locale the name is in
name the name of the object that contains this concept
    public void setName(String localeString name)
    {
        addLocalizedProperty(..getId(), localename);
    }

    
special utility method: get the value of a special localized property indicating the name

Parameters:
locale the locale the name is in
Returns:
the localized name or null if nothing was found in the specified locale
    public String getName(String locale)
    {
        if (property!=null && property.getType().equals(.))
        {
            LocalizedStringSettings locString = (LocalizedStringSettings)property.getValue();
            if (locString!=null)
            {
                return locString.getString(locale);
            }
        }
        return null;
    }

    
Special utility: save a special localized property indicating the description

Parameters:
locale the locale the description is in
name the description of the object that contains this concept
    public void setDescription(String localeString description)
    {
        addLocalizedProperty(..getId(), localedescription);
    }

    
special utility method: get the value of a special localized property indicating the description

Parameters:
locale the locale the description is in
Returns:
the localized description or null if nothing was found in the specified locale
    public String getDescription(String locale)
    {
        if (property!=null && property.getType().equals(.))
        {
            LocalizedStringSettings locString = (LocalizedStringSettings)property.getValue();
            if (locString!=null)
            {
                return locString.getString(locale);
            }
        }
        return null;
    }

    
Clears the properties of this concept, not the parents or anything like that.
    public void clearChildProperties()
    {
        setChanged(true);
    }

    
Remove a property from the children.

Parameters:
property The property to remove
    public void removeChildProperty(ConceptPropertyInterface property)
    {
        .remove(property.getId());
        setChanged(true);
    }
    public boolean hasInheritedConcept()
    {
        return !=null;
    }
    public boolean hasParentConcept()
    {
        return !=null;
    }
    public boolean hasSecurityParentConcept()
    {
        return !=null;
    }

    

Returns:
the securityParentInterface
    {
        return ;
    }

    

Parameters:
securityParentInterface the securityParentInterface to set
    public void setSecurityParentInterface(ConceptInterface securityParentInterface)
    {
        this. = securityParentInterface;
    }

    
Go up to the parent, the grandparent, etc, until you find a parent concept.

Returns:
the first parent concept by going up until the root
    {
        ConceptInterface concept = this;
        ConceptInterface parent = ;
        int levels = 0; // just to make sure we're not going in an endless loop somewhere.
        while (concept!=null && parent==null && concept.getInheritedInterface()!=null && levels<20)
        {
            concept = concept.getInheritedInterface();
            parent = concept.getParentInterface();
            levels++;
        }
        return parent;
    }
New to GrepCode? Check out our FAQ X