directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1683298 [2/2] - in /directory/studio/trunk/plugins/openldap.config.editor/src: main/java/org/apache/directory/studio/openldap/config/editor/dialogs/ main/java/org/apache/directory/studio/openldap/config/editor/pages/ main/java/org/apache/d...
Date Wed, 03 Jun 2015 11:42:41 GMT
Modified: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/TuningPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/TuningPage.java?rev=1683298&r1=1683297&r2=1683298&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/TuningPage.java
(original)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/pages/TuningPage.java
Wed Jun  3 11:42:41 2015
@@ -715,7 +715,7 @@ public class TuningPage extends OpenLDAP
 
             if ( dialog.open() == OverlayDialog.OK )
             {
-                String newTimeLimitStr = dialog.getNewTimeLimit();
+                String newTimeLimitStr = dialog.getNewLimit();
                 
                 if ( newTimeLimitStr != null )
                 {
@@ -737,7 +737,7 @@ public class TuningPage extends OpenLDAP
 
             if ( dialog.open() == OverlayDialog.OK )
             {
-                String newSizeLimitStr = dialog.getNewSizeLimit();
+                String newSizeLimitStr = dialog.getNewLimit();
                 
                 if ( newSizeLimitStr != null )
                 {

Added: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/AbstractLimitWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/AbstractLimitWrapper.java?rev=1683298&view=auto
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/AbstractLimitWrapper.java
(added)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/AbstractLimitWrapper.java
Wed Jun  3 11:42:41 2015
@@ -0,0 +1,299 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.studio.openldap.config.editor.wrappers;
+
+/**
+ * A shared class with the TimeLimitWrapper and SizeLimitWrapper
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractLimitWrapper
+{
+    /** The global limit */
+    protected Integer globalLimit;
+
+    /** The soft limit */
+    protected Integer softLimit;
+    
+    /** The hard limit */
+    protected Integer hardLimit;
+    
+    // Define some of the used constants
+    public static final Integer HARD_SOFT = Integer.valueOf( -3 );
+    public static final Integer UNLIMITED = Integer.valueOf( -1 );
+
+    public static final String HARD_STR = "hard";
+    public static final String NONE_STR = "none";
+    public static final String SOFT_STR = "soft";
+    public static final String UNLIMITED_STR = "unlimited";
+
+
+    /**
+     * Create a LimitWrapper instance
+     */
+    public AbstractLimitWrapper()
+    {
+    }
+    
+
+    /**
+     * Create a SizeLimitWrapper instance
+     * 
+     * @param globalLimit The global limit
+     * @param hardLimit The hard limit
+     * @param softLimit The soft limit
+     */
+    public AbstractLimitWrapper( Integer globalLimit, Integer hardLimit, Integer softLimit
)
+    {
+        this.globalLimit = globalLimit; 
+        this.hardLimit = hardLimit;
+        this.softLimit = softLimit;
+    }
+
+    
+    /**
+     * Clear the TimeLimitWrapper (reset all the values to null)
+     */
+    public void clear()
+    {
+        globalLimit = null;
+        softLimit = null;
+        hardLimit = null;
+    }
+    
+    
+    /**
+     * Get an integer out of a String. Return null if we don't find any.
+     */
+    protected static String getInteger( String str, int pos )
+    {
+        for ( int i = pos; i < str.length(); i++ )
+        {
+            char c = str.charAt( i );
+            
+            if ( ( c < '0') && ( c > '9' ) )
+            {
+                if ( i == pos )
+                {
+                    return null;
+                }
+                else
+                {
+                    return str.substring( pos, i );
+                }
+            }
+        }
+        
+        return str.substring( pos );
+    }
+    
+    
+    /**
+     * @return the globalLimit
+     */
+    public Integer getGlobalLimit()
+    {
+        return globalLimit;
+    }
+
+
+    /**
+     * @param globalLimit the globalLimit to set
+     */
+    public void setGlobalLimit( Integer globalLimit )
+    {
+        this.globalLimit = globalLimit;
+    }
+
+
+    /**
+     * @return the softLimit
+     */
+    public Integer getSoftLimit()
+    {
+        return softLimit;
+    }
+
+
+    /**
+     * @param softLimit the softLimit to set
+     */
+    public void setSoftLimit( Integer softLimit )
+    {
+        this.softLimit = softLimit;
+    }
+
+
+    /**
+     * @return the hardLimit
+     */
+    public Integer getHardLimit()
+    {
+        return hardLimit;
+    }
+
+
+    /**
+     * @param hardLimit the hardLimit to set
+     */
+    public void setHardLimit( Integer hardLimit )
+    {
+        this.hardLimit = hardLimit;
+    }
+    
+    
+    /**
+     * @return The Limit's type
+     */
+    protected abstract String getType();
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        String limitType = getType();
+        
+        if ( globalLimit != null )
+        {
+            // The globalLimit overrides the soft and hard limit
+            sb.append( limitType ).append( "=" );
+            
+            if ( globalLimit.equals( UNLIMITED ) )
+            {
+                sb.append( UNLIMITED_STR );
+            }
+            else if ( globalLimit.intValue() >= 0 )
+            {
+                sb.append( globalLimit );
+            }
+        }
+        else
+        {
+            if ( hardLimit != null )
+            {
+                // First check the hard limit, has it can be set to be equal to soft limit
+                if ( softLimit != null )
+                {
+                    if ( hardLimit.equals( softLimit ) )
+                    {
+                        // If hard and soft are set and equals, we use the global limit instead
+                        sb.append( limitType ).append( "=" );
+                        
+                        if ( hardLimit.equals( UNLIMITED ) )
+                        {
+                            sb.append( UNLIMITED_STR );
+                        }
+                        else if ( hardLimit.intValue() >= 0 )
+                        {
+                            sb.append( hardLimit );
+                        }
+                    }
+                    else
+                    {
+                        // We have both values, the aren't equal. 
+                        if ( hardLimit.equals( UNLIMITED ) )
+                        {
+                            sb.append( limitType ).append( ".hard=unlimited " );
+                            sb.append( limitType ).append( ".soft=" );
+                            sb.append( softLimit );
+                        }
+                        else if ( hardLimit.intValue() == 0 )
+                        {
+                            // Special cases : hard = soft
+                            sb.append( limitType ).append( "=" ).append( softLimit );
+                        }
+                        else if ( hardLimit.intValue() < softLimit.intValue() )
+                        {
+                            // when the hard limit is lower than the soft limit : use the
hard limit
+                            sb.append( limitType ).append( "=" ).append( hardLimit );
+                        }
+                        else 
+                        {
+                            // Special case : softLimit is -1
+                            if ( softLimit.equals( UNLIMITED ) )
+                            {
+                                // We use the hard limit
+                                sb.append( limitType ).append( "=" ).append( hardLimit );
+                            }
+                            else
+                            {
+                                sb.append( limitType ).append( ".hard=" );
+                                
+                                if ( hardLimit.equals( UNLIMITED ) )
+                                {
+                                    sb.append( UNLIMITED_STR );
+                                }
+                                else if ( hardLimit.intValue() > 0 )
+                                {
+                                    sb.append( hardLimit );
+                                }
+        
+                                sb.append( ' ' ).append( limitType ).append( ".soft=" );
+                                
+                                if ( softLimit.equals( UNLIMITED ) )
+                                {
+                                    sb.append( UNLIMITED_STR );
+                                }
+                                else if ( softLimit.intValue() >= 0 )
+                                {
+                                    sb.append( softLimit );
+                                }
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    // Only an hard limit
+                    sb.append( limitType ).append( ".hard=" );
+                    
+                    if ( hardLimit.equals( UNLIMITED ) )
+                    {
+                        sb.append( UNLIMITED_STR );
+                    }
+                    else if ( hardLimit.intValue() >= 0 )
+                    {
+                        sb.append( hardLimit );
+                    }
+                }
+            }
+            else if ( softLimit != null )
+            {
+                // Only a soft limit
+                sb.append( limitType ).append( ".soft=" );
+                
+                if ( softLimit.equals( UNLIMITED ) )
+                {
+                    sb.append( UNLIMITED_STR );
+                }
+                else if ( softLimit.intValue() >= 0 )
+                {
+                    sb.append( softLimit );
+                }
+            }
+        }
+        
+        return sb.toString();
+    }
+}

Modified: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SizeLimitWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SizeLimitWrapper.java?rev=1683298&r1=1683297&r2=1683298&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SizeLimitWrapper.java
(original)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/SizeLimitWrapper.java
Wed Jun  3 11:42:41 2015
@@ -44,17 +44,8 @@ import org.apache.directory.api.util.Str
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class SizeLimitWrapper
+public class SizeLimitWrapper extends AbstractLimitWrapper
 {
-    /** The global limit */
-    private Integer globalLimit;
-
-    /** The soft limit */
-    private Integer softLimit;
-    
-    /** The hard limit */
-    private Integer hardLimit;
-    
     /** The unchecked limit */
     private Integer uncheckedLimit;
     
@@ -68,19 +59,12 @@ public class SizeLimitWrapper
     private boolean noEstimate;
     
     //Define some of the used constants
-    public static final Integer HARD_SOFT = Integer.valueOf( -3 );
     public static final Integer PR_DISABLED = Integer.valueOf( -2 );
     public static final Integer PR_HARD = Integer.valueOf( 0 );
     public static final Integer UC_DISABLED = Integer.valueOf( 0 );
-    public static final Integer UNLIMITED = Integer.valueOf( -1 );
     
     public static final String DISABLED_STR = "disabled";
-    public static final String HARD_STR = "hard";
-    public static final String NONE_STR = "none";
-    public static final String SOFT_STR = "soft";
     public static final String UNCHECKED_STR = "unchecked";
-    public static final String UNLIMITED_STR = "unlimited";
-
 
 
     /**
@@ -88,6 +72,7 @@ public class SizeLimitWrapper
      */
     private SizeLimitWrapper()
     {
+        super();
     }
     
     
@@ -104,9 +89,7 @@ public class SizeLimitWrapper
     public SizeLimitWrapper( Integer globalLimit, Integer hardLimit, Integer softLimit, Integer
uncheckedLimit, 
         Integer prLimit, Integer prTotalLimit, boolean noEstimate )
     {
-        this.globalLimit = globalLimit;
-        this.hardLimit = hardLimit;
-        this.softLimit = softLimit;
+        super( globalLimit, hardLimit, softLimit );
         this.uncheckedLimit = uncheckedLimit;
         this.prLimit = prLimit;
         this.prTotalLimit = prTotalLimit;
@@ -225,9 +208,7 @@ public class SizeLimitWrapper
      */
     public void clear()
     {
-        globalLimit = null;
-        softLimit = null;
-        hardLimit = null;
+        super.clear();
         uncheckedLimit = null;
         prLimit = null;
         prTotalLimit = null;
@@ -554,32 +535,6 @@ public class SizeLimitWrapper
     
     
     /**
-     * Get an integer out of a String. Return null if we don't find any.
-     */
-    private static String getInteger( String str, int pos )
-    {
-        for ( int i = pos; i < str.length(); i++ )
-        {
-            char c = str.charAt( i );
-            
-            if ( ( c < '0') && ( c > '9' ) )
-            {
-                if ( i == pos )
-                {
-                    return null;
-                }
-                else
-                {
-                    return str.substring( pos, i );
-                }
-            }
-        }
-        
-        return str.substring( pos );
-    }
-    
-    
-    /**
      * Tells if the SizeLimit element is valid or not
      * @param sizeLimitStr the sizeLimit String to check
      * @return true if the values are correct, false otherwise
@@ -613,60 +568,6 @@ public class SizeLimitWrapper
 
         return true;
     }
-    
-    
-    /**
-     * @return the globalLimit
-     */
-    public Integer getGlobalLimit()
-    {
-        return globalLimit;
-    }
-
-
-    /**
-     * @param globalLimit the globalLimit to set
-     */
-    public void setGlobalLimit( Integer globalLimit )
-    {
-        this.globalLimit = globalLimit;
-    }
-
-
-    /**
-     * @return the softLimit
-     */
-    public Integer getSoftLimit()
-    {
-        return softLimit;
-    }
-
-
-    /**
-     * @param softLimit the softLimit to set
-     */
-    public void setSoftLimit( Integer softLimit )
-    {
-        this.softLimit = softLimit;
-    }
-
-
-    /**
-     * @return the hardLimit
-     */
-    public Integer getHardLimit()
-    {
-        return hardLimit;
-    }
-
-
-    /**
-     * @param hardLimit the hardLimit to set
-     */
-    public void setHardLimit( Integer hardLimit )
-    {
-        this.hardLimit = hardLimit;
-    }
 
 
     /**
@@ -738,7 +639,15 @@ public class SizeLimitWrapper
     {
         this.noEstimate = noEstimate;
     }
-
+    
+    
+    /**
+     * @return The Limit's type
+     */
+    protected String getType()
+    {
+        return "size";
+    }
 
 
     /**
@@ -748,135 +657,17 @@ public class SizeLimitWrapper
     {
         StringBuilder sb = new StringBuilder();
         
-        // Deal with global/hard/soft limits first
-        if ( globalLimit != null )
-        {
-            // The globalLimit overrides the soft and hard limit
-            sb.append( "size=" );
-            
-            if ( globalLimit.equals( UNLIMITED ) )
-            {
-                sb.append( UNLIMITED_STR );
-            }
-            else if ( globalLimit.intValue() >= 0 )
-            {
-                sb.append( globalLimit );
-            }
-        }
-        else
-        {
-            if ( hardLimit != null )
-            {
-                // First check the hard limit, has it can be set to be equal to soft limit
-                if ( softLimit != null )
-                {
-                    if ( hardLimit.equals( softLimit ) )
-                    {
-                        // If hard and soft are set and equals, we use the global limit instead
-                        sb.append( "size=" );
-                        
-                        if ( hardLimit.equals( UNLIMITED ) )
-                        {
-                            sb.append( UNLIMITED_STR );
-                        }
-                        else if ( hardLimit.intValue() >= 0 )
-                        {
-                            sb.append( hardLimit );
-                        }
-                    }
-                    else
-                    {
-                        // We have both values, the aren't equal. 
-                        if ( hardLimit.equals( UNLIMITED ) )
-                        {
-                            sb.append( "size.hard=unlimited size.soft=" );
-                            sb.append( softLimit );
-                        }
-                        else if ( hardLimit.intValue() == 0 )
-                        {
-                            // Special cases : hard = soft
-                            sb.append( "size=" ).append( softLimit );
-                        }
-                        else if ( hardLimit.intValue() < softLimit.intValue() )
-                        {
-                            // when the hard limit is lower than the soft limit : use the
hard limit
-                            sb.append( "size=" ).append( hardLimit );
-                        }
-                        else 
-                        {
-                            // Special case : softLimit is -1
-                            if ( softLimit.equals( UNLIMITED ) )
-                            {
-                                // We use the hard limit
-                                sb.append( "size=" ).append( hardLimit );
-                            }
-                            else
-                            {
-                                sb.append( "size.hard=" );
-                                
-                                if ( hardLimit.equals( UNLIMITED ) )
-                                {
-                                    sb.append( UNLIMITED_STR );
-                                }
-                                else if ( hardLimit.intValue() > 0 )
-                                {
-                                    sb.append( hardLimit );
-                                }
-        
-                                sb.append( " size.soft=" );
-                                
-                                if ( softLimit.equals( UNLIMITED ) )
-                                {
-                                    sb.append( UNLIMITED_STR );
-                                }
-                                else if ( softLimit.intValue() >= 0 )
-                                {
-                                    sb.append( softLimit );
-                                }
-                            }
-                        }
-                    }
-                }
-                else
-                {
-                    // Only an hard limit
-                    sb.append( "size.hard=" );
-                    
-                    if ( hardLimit.equals( UNLIMITED ) )
-                    {
-                        sb.append( UNLIMITED_STR );
-                    }
-                    else if ( hardLimit.intValue() >= 0 )
-                    {
-                        sb.append( hardLimit );
-                    }
-                }
-            }
-            else if ( softLimit != null )
-            {
-                // Only a soft limit
-                sb.append( "size.soft=" );
-                
-                if ( softLimit.equals( UNLIMITED ) )
-                {
-                    sb.append( UNLIMITED_STR );
-                }
-                else if ( softLimit.intValue() >= 0 )
-                {
-                    sb.append( softLimit );
-                }
-            }
-        }
+        sb.append( super.toString() );
 
-        // Eventually add a space at the end if we have had some size limit
-        if ( sb.length() > 0 )
-        {
-            sb.append( ' ' );
-        }
-        
         // process the unchecked limit
         if ( uncheckedLimit != null )
         {
+            // Eventually add a space at the end if we have had some size limit
+            if ( sb.length() > 0 )
+            {
+                sb.append( ' ' );
+            }
+            
             sb.append( "size.unchecked=" );
             
             if ( uncheckedLimit.equals( UNLIMITED ) )
@@ -896,12 +687,13 @@ public class SizeLimitWrapper
         // Process the pr limit
         if ( prLimit != null )
         {
-            // Add a space if we have had some unchecked limit
-            if ( uncheckedLimit != null )
+            // Eventually add a space at the end if we have had some size limit
+            if ( sb.length() > 0 )
             {
                 sb.append( ' ' );
             }
             
+            
             sb.append( "size.pr=" );
             
             if ( prLimit.equals( UNLIMITED ) )
@@ -917,12 +709,12 @@ public class SizeLimitWrapper
         // Process the prTotal limit
         if ( prTotalLimit != null )
         {
-            // Add a space if we have had some unchecked limit or some pr limit
-            if ( ( uncheckedLimit != null ) || ( prLimit != null ) )
+            // Eventually add a space at the end if we have had some size limit
+            if ( sb.length() > 0 )
             {
                 sb.append( ' ' );
             }
-
+            
             sb.append( "size.prtotal=" );
             
             if ( prTotalLimit.equals( UNLIMITED ) )
@@ -933,22 +725,25 @@ public class SizeLimitWrapper
             {
                 sb.append( HARD_STR );
             }
+            else if ( prTotalLimit.intValue() == PR_DISABLED )
+            {
+                sb.append( DISABLED_STR );
+            }
             else
             {
                 sb.append( prTotalLimit );
             }
-            
         }
         
         // Last, not least, the noEstimate flag
         if ( noEstimate )
         {
-            // Add a space if we have had some unchecked, pr or prTotal limit
-            if ( ( uncheckedLimit != null ) || ( prLimit != null ) || ( prTotalLimit != null
) )
+            // Eventually add a space at the end if we have had some size limit
+            if ( sb.length() > 0 )
             {
                 sb.append( ' ' );
             }
-
+            
             sb.append( "size.pr=noEstimate" );
         }
         

Modified: directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/TimeLimitWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/TimeLimitWrapper.java?rev=1683298&r1=1683297&r2=1683298&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/TimeLimitWrapper.java
(original)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/editor/wrappers/TimeLimitWrapper.java
Wed Jun  3 11:42:41 2015
@@ -40,26 +40,14 @@ import org.apache.directory.api.util.Str
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class TimeLimitWrapper
+public class TimeLimitWrapper extends AbstractLimitWrapper
 {
-    /** The global limit */
-    private Integer globalLimit;
-
-    /** The soft limit */
-    private Integer softLimit;
-    
-    /** The hard limit */
-    private Integer hardLimit;
-    
-    //Define some of the used constants
-    public static final Integer UNLIMITED = Integer.valueOf( -1 );
-    public static final Integer HARD_SOFT = Integer.valueOf( -3 );
-    
     /**
      * Create a TimeLimitWrapper instance
      */
     private TimeLimitWrapper()
     {
+        super();
     }
     
     
@@ -72,9 +60,7 @@ public class TimeLimitWrapper
      */
     public TimeLimitWrapper( Integer globalLimit, Integer hardLimit, Integer softLimit )
     {
-        this.globalLimit = globalLimit;
-        this.hardLimit = hardLimit;
-        this.softLimit = softLimit;
+        super( globalLimit, hardLimit, softLimit );
     }
     
     
@@ -163,17 +149,6 @@ public class TimeLimitWrapper
     
     
     /**
-     * Clear the TimeLimitWrapper (reset all the values to null)
-     */
-    public void clear()
-    {
-        globalLimit = null;
-        softLimit = null;
-        hardLimit = null;
-    }
-    
-    
-    /**
      * Parse a single limit :
      * <pre>
      * timeLimit ::= 'time' ( '.hard=' hardLimit | '.soft=' limit | '=' limit )
@@ -198,12 +173,12 @@ public class TimeLimitWrapper
                 // Global : get the limit
                 pos++;
                 
-                if ( limitStr.startsWith( "unlimited", pos ) )
+                if ( limitStr.startsWith( UNLIMITED_STR, pos ) )
                 {
                     pos += 9;
                     tlw.globalLimit = UNLIMITED;
                 }
-                else if ( limitStr.startsWith( "none", pos ) )
+                else if ( limitStr.startsWith( NONE_STR, pos ) )
                 {
                     pos += 4;
                     tlw.globalLimit = UNLIMITED;
@@ -238,19 +213,19 @@ public class TimeLimitWrapper
                 // Hard limit : get the hard limit
                 pos += 6;
                 
-                if ( limitStr.startsWith( "unlimited", pos ) )
+                if ( limitStr.startsWith( UNLIMITED_STR, pos ) )
                 {
                     pos += 9;
                     
                     tlw.hardLimit = UNLIMITED;
                 }
-                else if ( limitStr.startsWith( "none", pos ) )
+                else if ( limitStr.startsWith( NONE_STR, pos ) )
                 {
                     pos += 4;
                     
                     tlw.hardLimit = UNLIMITED;
                 }
-                else if ( limitStr.startsWith( "soft", pos ) )
+                else if ( limitStr.startsWith( SOFT_STR, pos ) )
                 {
                     pos += 4;
                     tlw.globalLimit = HARD_SOFT;
@@ -280,13 +255,13 @@ public class TimeLimitWrapper
                 // Soft limit : get the limit
                 pos += 6;
 
-                if ( limitStr.startsWith( "unlimited", pos ) )
+                if ( limitStr.startsWith( UNLIMITED_STR, pos ) )
                 {
                     pos += 9;
                     
                     tlw.softLimit = UNLIMITED;
                 }
-                else if ( limitStr.startsWith( "none", pos ) )
+                else if ( limitStr.startsWith( NONE_STR, pos ) )
                 {
                     pos += 4;
                     
@@ -334,32 +309,6 @@ public class TimeLimitWrapper
     
     
     /**
-     * Get an integer out of a String. Return null if we don't find any.
-     */
-    private static String getInteger( String str, int pos )
-    {
-        for ( int i = pos; i < str.length(); i++ )
-        {
-            char c = str.charAt( i );
-            
-            if ( ( c < '0') && ( c > '9' ) )
-            {
-                if ( i == pos )
-                {
-                    return null;
-                }
-                else
-                {
-                    return str.substring( pos, i );
-                }
-            }
-        }
-        
-        return str.substring( pos );
-    }
-    
-    
-    /**
      * Tells if the TimeLimit element is valid or not
      * @param timeLimitStr the timeLimit String to check
      * @return true if the values are correct, false otherwise
@@ -396,185 +345,10 @@ public class TimeLimitWrapper
     
     
     /**
-     * @return the globalLimit
-     */
-    public Integer getGlobalLimit()
-    {
-        return globalLimit;
-    }
-
-
-    /**
-     * @param globalLimit the globalLimit to set
-     */
-    public void setGlobalLimit( Integer globalLimit )
-    {
-        this.globalLimit = globalLimit;
-    }
-
-
-    /**
-     * @return the softLimit
-     */
-    public Integer getSoftLimit()
-    {
-        return softLimit;
-    }
-
-
-    /**
-     * @param softLimit the softLimit to set
-     */
-    public void setSoftLimit( Integer softLimit )
-    {
-        this.softLimit = softLimit;
-    }
-
-
-    /**
-     * @return the hardLimit
-     */
-    public Integer getHardLimit()
-    {
-        return hardLimit;
-    }
-
-
-    /**
-     * @param hardLimit the hardLimit to set
-     */
-    public void setHardLimit( Integer hardLimit )
-    {
-        this.hardLimit = hardLimit;
-    }
-
-
-    /**
-     * @see Object#toString()
+     * @return The Limit's type
      */
-    public String toString()
+    protected String getType()
     {
-        StringBuilder sb = new StringBuilder();
-        
-        if ( globalLimit != null )
-        {
-            // The globalLimit overrides the soft and hard limit
-            sb.append( "time=" );
-            
-            if ( globalLimit.equals( UNLIMITED ) )
-            {
-                sb.append( "unlimited" );
-            }
-            else if ( globalLimit.intValue() >= 0 )
-            {
-                sb.append( globalLimit );
-            }
-        }
-        else
-        {
-            if ( hardLimit != null )
-            {
-                // First check the hard limit, has it can be set to be equal to soft limit
-                if ( softLimit != null )
-                {
-                    if ( hardLimit.equals( softLimit ) )
-                    {
-                        // If hard and soft are set and equals, we use the global limit instead
-                        sb.append( "time=" );
-                        
-                        if ( hardLimit.equals( UNLIMITED ) )
-                        {
-                            sb.append( "unlimited" );
-                        }
-                        else if ( hardLimit.intValue() >= 0 )
-                        {
-                            sb.append( hardLimit );
-                        }
-                    }
-                    else
-                    {
-                        // We have both values, the aren't equal. 
-                        if ( hardLimit.equals( UNLIMITED ) )
-                        {
-                            sb.append( "time.hard=unlimited time.soft=" );
-                            sb.append( softLimit );
-                        }
-                        else if ( hardLimit.intValue() == 0 )
-                        {
-                            // Special cases : hard = soft
-                            sb.append( "time=" ).append( softLimit );
-                        }
-                        else if ( hardLimit.intValue() < softLimit.intValue() )
-                        {
-                            // when the hard limit is lower than the soft limit : use the
hard limit
-                            sb.append( "time=" ).append( hardLimit );
-                        }
-                        else 
-                        {
-                            // Special case : softLimit is -1
-                            if ( softLimit.equals( UNLIMITED ) )
-                            {
-                                // We use the hard limit
-                                sb.append( "time=" ).append( hardLimit );
-                            }
-                            else
-                            {
-                                sb.append( "time.hard=" );
-                                
-                                if ( hardLimit.equals( UNLIMITED ) )
-                                {
-                                    sb.append( "unlimited" );
-                                }
-                                else if ( hardLimit.intValue() > 0 )
-                                {
-                                    sb.append( hardLimit );
-                                }
-        
-                                sb.append( " time.soft=" );
-                                
-                                if ( softLimit.equals( UNLIMITED ) )
-                                {
-                                    sb.append( "unlimited" );
-                                }
-                                else if ( softLimit.intValue() >= 0 )
-                                {
-                                    sb.append( softLimit );
-                                }
-                            }
-                        }
-                    }
-                }
-                else
-                {
-                    // Only an hard limit
-                    sb.append( "time.hard=" );
-                    
-                    if ( hardLimit.equals( UNLIMITED ) )
-                    {
-                        sb.append( "unlimited" );
-                    }
-                    else if ( hardLimit.intValue() >= 0 )
-                    {
-                        sb.append( hardLimit );
-                    }
-                }
-            }
-            else if ( softLimit != null )
-            {
-                // Only a soft limit
-                sb.append( "time.soft=" );
-                
-                if ( softLimit.equals( UNLIMITED ) )
-                {
-                    sb.append( "unlimited" );
-                }
-                else if ( softLimit.intValue() >= 0 )
-                {
-                    sb.append( softLimit );
-                }
-            }
-        }
-        
-        return sb.toString();
+        return "time";
     }
 }

Modified: directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SizeLimitWrapperTest.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SizeLimitWrapperTest.java?rev=1683298&r1=1683297&r2=1683298&view=diff
==============================================================================
--- directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SizeLimitWrapperTest.java
(original)
+++ directory/studio/trunk/plugins/openldap.config.editor/src/test/java/org/apache/directory/studio/openldap/config/wrappers/SizeLimitWrapperTest.java
Wed Jun  3 11:42:41 2015
@@ -21,6 +21,7 @@ package org.apache.directory.studio.open
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 import org.apache.directory.studio.openldap.config.editor.wrappers.SizeLimitWrapper;
 import org.junit.Test;
@@ -119,7 +120,7 @@ public class SizeLimitWrapperTest
     
     
     @Test
-    public void testCreateTimeLimit()
+    public void testCreateSizeLimit()
     {
         SizeLimitWrapper slw = new SizeLimitWrapper( null );
         assertEquals( null, slw.getGlobalLimit() );
@@ -206,5 +207,15 @@ public class SizeLimitWrapperTest
         assertEquals( 100, slw.getGlobalLimit().intValue() );
         assertEquals( null, slw.getSoftLimit() );
         assertEquals( null, slw.getHardLimit() );
+        assertFalse( slw.isNoEstimate() );
+
+        slw = new SizeLimitWrapper( "size.hard=100 size.soft=50 size.unchecked=20 size.pr=10
size.prtotal=20 size.pr=noEstimate" );
+        assertEquals( null, slw.getGlobalLimit() );
+        assertEquals( 50, slw.getSoftLimit().intValue() );
+        assertEquals( 100, slw.getHardLimit().intValue() );
+        assertEquals( 20, slw.getUncheckedLimit().intValue() );
+        assertEquals( 10, slw.getPrLimit().intValue() );
+        assertEquals( 20, slw.getPrTotalLimit().intValue() );
+        assertTrue( slw.isNoEstimate() );
     }
 }



Mime
View raw message