/**
 * JLibs: Common Utilities for Java
 * Copyright (C) 2009  Santhosh Kumar T <santhosh.tekuri@gmail.com>
 *
 * 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.
 */

package jlibs.nblr.matchers;

import jlibs.core.util.Range;

import java.util.Collections;
import java.util.List;

/**
 * @author Santhosh Kumar T
 */
public final class Not extends Matcher{
    public final Matcher delegate;

    public Not(Matcher delegate){
        this.delegate = delegate;
    }

    @Override
    public boolean hasCustomJavaCode(){
        return super.hasCustomJavaCode() || delegate.hasCustomJavaCode();
    }

    @Override
    protected String __javaCode(String variable){
        if(delegate instanceof Any){
            Any any = (Any)delegate;

            if(any.chars==null)
                return variable+"==-1";

            StringBuilder buff = new StringBuilder();
            for(int ch: any.chars){
                if(buff.length()>0)
                    buff.append(" && ");
                buff.append(variable).append("!=").append(toJava(ch));
            }
            return buff.toString();
        }else
            return "!("+delegate._javaCode(variable)+")";
    }

    public static int minValue = Character.MIN_VALUE;
    @Override
    public List<Range> ranges(){
        return Range.minus(Collections.singletonList(new Range(minValue, Character.MAX_VALUE)), delegate.ranges());
    }

    @Override
    public String toString(){
        String msg = delegate._toString();
        msg = msg.substring(1, msg.length()-1);
        return "[^"+msg+"]";
    }
}

@@ -1830,21 +1830,26 @@
 ter.MAX_
-VALUE
+CODE_POINT
 )), dele

should use MAX_CODEPOINT