Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
     Copyright (c) 2012 zuendorf 
     
     Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
     and associated documentation files (the "Software"), to deal in the Software without restriction, 
     including without limitation the rights to use, copy, modify, merge, publish, distribute, 
     sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
     furnished to do so, subject to the following conditions: 
     
    The above copyright notice and this permission notice shall be included in all copies or 
    substantial portions of the Software. 
    
    The Software shall be used for Good, not Evil. 
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
    BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
    DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
  */
    
 package org.sdmlib.models.pattern;
 
 
 
 
 public class LinkConstraint extends PatternLink implements PropertyChangeInterface
 {
    //==========================================================================
    
    @Override
    public boolean findNextMatch()
    {
       if (..equals(getModifier()))
       {
          if ( ! this.getPattern().getHasMatch())
          {
             return false;
          }
          
          if (this.getHasMatch())
          {
             this.setHasMatch(false);
             return false;
          }
          else
          {
             Object srcObj = this.getSrc().getCurrentMatch();
             SendableEntityCreator creatorClass = this.getPattern().getJsonIdMap().getCreatorClass(srcObj);
             creatorClass.setValue(srcObjthis.getTgtRoleName(), this.getTgt().getCurrentMatch(), "");
             this.setHasMatch(true);
             
             if (getTopPattern().getDebugMode() >= .)
             {
                getTopPattern().addLogMsg(this.getSrc().getPatternObjectName()
                   + ".set" + StrUtil.upFirstChar(getTgtRoleName()) + "(" + this.getTgt().getPatternObjectName() + ")");
             }
 
             return true;
          }
       }
       else if (..equals(getModifier()))
       {
          if ( ! this.getPattern().getHasMatch())
          {
             return false;
          }
          
          if (this.getHasMatch())
          {
             this.setHasMatch(false);
             return false;
          }
          else
          {
             Object srcObj = this.getSrc().getCurrentMatch();
             SendableEntityCreator creatorClass = this.getPattern().getJsonIdMap().getCreatorClass(srcObj);
             Object value = creatorClass.getValue(srcObjthis.getTgtRoleName());
             if (value == null)
             {
             	// do nothing
             }
             else if (value instanceof Collection)
             {
                if (getTopPattern().getDebugMode() >= .)
                {
                   getTopPattern().addLogMsg(this.getSrc().getPatternObjectName()
                      + ".removeFrom" + StrUtil.upFirstChar(getTgtRoleName()) + "(" + this.getTgt().getPatternObjectName() + ")");
                }
                
             	creatorClass.setValue(srcObjthis.getTgtRoleName()  + .this.getTgt().getCurrentMatch(), "");
             }
             else
            {
               if (getTopPattern().getDebugMode() >= .)
               {
                  getTopPattern().addLogMsg(this.getSrc().getPatternObjectName()
                     + ".set" + StrUtil.upFirstChar(getTgtRoleName()) + "(null); // remove" + this.getTgt().dumpHostGraphObject(this.getTgt().getCurrentMatch()));
               }
               
            	creatorClass.setValue(srcObjthis.getTgtRoleName(), null"");
            }
            this.setHasMatch(true);
            return true;
         }
      }
      	
      
      // real search
      if (this.getHostGraphSrcObject() == null)
      {
         // search forward
         this.setHostGraphSrcObject(this.getSrc().getCurrentMatch());
         
         if (getHostGraphSrcObject() != null)
         {
            SendableEntityCreator creatorClass = this.getPattern().getJsonIdMap().getCreatorClass(getHostGraphSrcObject());
            Object value = creatorClass.getValue(getHostGraphSrcObject(), getTgtRoleName());
            Object hostGraphTgtObject = this.getTgt().getCurrentMatch();
            
            if (hostGraphTgtObject != null && 
                  (hostGraphTgtObject == value || (value instanceof Collection && ((Collection<?>) value).contains(hostGraphTgtObject))))
            {
               if (getTopPattern().getDebugMode() >= .)
               {
                  String msg = "// cnet link from x to y exists";
                  msg = msg.replaceFirst("y"getTopPattern().getJsonIdMap().getId(value) + " " + value.toString());
                  msg = msg.replaceFirst("x"getTopPattern().getJsonIdMap().getId(getHostGraphSrcObject()) + " " + getHostGraphSrcObject().toString());
                  msg = msg.replaceFirst("cnet"getTgtRoleName());
                  getTopPattern().addLogMsg(msg);
               }
               return true;
            }
            else
            {
               if (getTopPattern().getDebugMode() >= .)
               {
                  String msg = "// cnet link from x to ? does not exists, backtrack";
                  if (value != null)
                  {
                     msg = msg.replaceFirst("\\?"getTopPattern().getJsonIdMap().getId(value) + " " + value.toString());
                  }
                  msg = msg.replaceFirst("x"getTopPattern().getJsonIdMap().getId(getHostGraphSrcObject()) + " " + getHostGraphSrcObject().toString());
                  msg = msg.replaceFirst("cnet"getTgtRoleName());
                  getTopPattern().addLogMsg(msg);
               }
               
               this.setHostGraphSrcObject(null);
               
               return false;
            }
         }
         else 
         {
            return false;
         }
      }
      else
      {
         this.setHostGraphSrcObject(null);
      
         return false;
      }
   }
   
   public void resetSearch()
   {
      this.setHasMatch(false);
      super.resetSearch();
   }
   //==========================================================================
   
   public void removeYou()
   {
      super.removeYou();
      setPattern(null);
      setTgt(null);
      setSrc(null);
      getPropertyChangeSupport().firePropertyChange("REMOVE_YOU"thisnull);
   }
   public String toString()
   {
      StringBuilder s = new StringBuilder();
      
      s.append(" ").append(this.getTgtRoleName());
      s.append(" ").append(this.getModifier());
      s.append(" ").append(this.getPatternObjectName());
      return s.substring(1);
   }
   
   //==========================================================================
   
   public static final String PROPERTY_TGTROLENAME = "tgtRoleName";
   
   private String tgtRoleName;
   public String getTgtRoleName()
   {
      return this.;
   }
   
   public void setTgtRoleName(String value)
   {
      if ( ! StrUtil.stringEquals(this.value))
      {
         String oldValue = this.;
         this. = value;
      }
   }
   
   public PatternLink withTgtRoleName(String value)
   {
      setTgtRoleName(value);
      return this;
   } 
   
   //==========================================================================
   
   public static final String PROPERTY_HOSTGRAPHSRCOBJECT = "hostGraphSrcObject";
   
   private Object hostGraphSrcObject;
   {
      return this.;
   }
   
   public void setHostGraphSrcObject(Object value)
   {
      if (this. != value)
      {
         Object oldValue = this.;
         this. = value;
      }
   }
   
   {
      setHostGraphSrcObject(value);
      return this;
   } 
New to GrepCode? Check out our FAQ X