text:
#pragma once

#include "ConcurrentJSLock.h"
#include "YarrPattern.h"

namespace WTF {
class BumpPointerAllocator;
}
using WTF::BumpPointerAllocator;

namespace JSC { namespace Yarr {

class ByteDisjunction;

struct ByteTerm {
    enum Type {
        TypeBodyAlternativeBegin,
        TypeBodyAlternativeDisjunction,
        TypeBodyAlternativeEnd,
        TypeAlternativeBegin,
        TypeAlternativeDisjunction,
        TypeAlternativeEnd,
        TypeSubpatternBegin,
        TypeSubpatternEnd,
        TypeAssertionBOL,
        TypeAssertionEOL,
        TypeAssertionWordBoundary,
        TypePatternCharacterOnce,
        TypePatternCharacterFixed,
        TypePatternCharacterGreedy,
        TypePatternCharacterNonGreedy,
        TypePatternCasedCharacterOnce,
        TypePatternCasedCharacterFixed,
        TypePatternCasedCharacterGreedy,
        TypePatternCasedCharacterNonGreedy,
        TypeCharacterClass,
        TypeBackReference,
        TypeParenthesesSubpattern,
        TypeParenthesesSubpatternOnceBegin,
        TypeParenthesesSubpatternOnceEnd,
        TypeParenthesesSubpatternTerminalBegin,
        TypeParenthesesSubpatternTerminalEnd,
        TypeParentheticalAssertionBegin,
        TypeParentheticalAssertionEnd,
        TypeCheckInput,
        TypeUncheckInput,
        TypeDotStarEnclosure,
    } type;
    union {
        struct {
            union {
                UChar32 patternCharacter;
                struct {
                    UChar32 lo;
                    UChar32 hi;
                } casedCharacter;
                CharacterClass* characterClass;
                unsigned subpatternId;
            };
            union {
                ByteDisjunction* parenthesesDisjunction;
                unsigned parenthesesWidth;
            };
            QuantifierType quantityType;
            unsigned quantityMinCount;
            unsigned quantityMaxCount;
        } atom;
        struct {
            int next;
            int end;
            bool onceThrough;
        } alternative;
        struct {
            bool m_bol : 1;
            bool m_eol : 1;
        } anchors;
        unsigned checkInputCount;
    };
    unsigned frameLocation;
    bool m_capture : 1;
    bool m_invert : 1;
    unsigned inputPosition;

    ByteTerm(UChar32 ch, unsigned inputPos, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
        : frameLocation(frameLocation)
        , m_capture(false)
        , m_invert(false)
    {
        atom.patternCharacter = ch;
        atom.quantityType = quantityType;
        atom.quantityMinCount = quantityCount.unsafeGet();
        atom.quantityMaxCount = quantityCount.unsafeGet();
        inputPosition = inputPos;

        switch (quantityType) {
        case QuantifierFixedCount:
            type = (quantityCount == 1) ? ByteTerm::TypePatternCharacterOnce : ByteTerm::TypePatternCharacterFixed;
            break;
        case QuantifierGreedy:
            type = ByteTerm::TypePatternCharacterGreedy;
            break;
        case QuantifierNonGreedy:
            type = ByteTerm::TypePatternCharacterNonGreedy;
            break;
        }
    }

    ByteTerm(UChar32 lo, UChar32 hi, unsigned inputPos, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
        : frameLocation(frameLocation)
        , m_capture(false)
        , m_invert(false)
    {
        switch (quantityType) {
        case QuantifierFixedCount:
            type = (quantityCount == 1) ? ByteTerm::TypePatternCasedCharacterOnce : ByteTerm::TypePatternCasedCharacterFixed;
            break;
        case QuantifierGreedy:
            type = ByteTerm::TypePatternCasedCharacterGreedy;
            break;
        case QuantifierNonGreedy:
            type = ByteTerm::TypePatternCasedCharacterNonGreedy;
            break;
        }

        atom.casedCharacter.lo = lo;
        atom.casedCharacter.hi = hi;
        atom.quantityType = quantityType;
        atom.quantityMinCount = quantityCount.unsafeGet();
        atom.quantityMaxCount = quantityCount.unsafeGet();
        inputPosition = inputPos;
    }

    ByteTerm(CharacterClass* characterClass, bool invert, unsigned inputPos)
        : type(ByteTerm::TypeCharacterClass)
        , m_capture(false)
        , m_invert(invert)
    {
        atom.characterClass = characterClass;
        atom.quantityType = QuantifierFixedCount;
        atom.quantityMinCount = 1;
        atom.quantityMaxCount = 1;
        inputPosition = inputPos;
    }

    ByteTerm(Type type, unsigned subpatternId, ByteDisjunction* parenthesesInfo, bool capture, unsigned inputPos)
        : type(type)
        , m_capture(capture)
        , m_invert(false)
    {
        atom.subpatternId = subpatternId;
        atom.parenthesesDisjunction = parenthesesInfo;
        atom.quantityType = QuantifierFixedCount;
        atom.quantityMinCount = 1;
        atom.quantityMaxCount = 1;
        inputPosition = inputPos;
    }

    ByteTerm(Type type, bool invert = false)
        : type(type)
        , m_capture(false)
        , m_invert(invert)
    {
        atom.quantityType = QuantifierFixedCount;
        atom.quantityMinCount = 1;
        atom.quantityMaxCount = 1;
    }

    ByteTerm(Type type, unsigned subpatternId, bool capture, bool invert, unsigned inputPos)
        : type(type)
        , m_capture(capture)
        , m_invert(invert)
    {
        atom.subpatternId = subpatternId;
        atom.quantityType = QuantifierFixedCount;
        atom.quantityMinCount = 1;
        atom.quantityMaxCount = 1;
        inputPosition = inputPos;
    }

    static ByteTerm BOL(unsigned inputPos)
    {
        ByteTerm term(TypeAssertionBOL);
        term.inputPosition = inputPos;
        return term;
    }

    static ByteTerm CheckInput(Checked<unsigned> count)
    {
        ByteTerm term(TypeCheckInput);
        term.checkInputCount = count.unsafeGet();
        return term;
    }

    static ByteTerm UncheckInput(Checked<unsigned> count)
    {
        ByteTerm term(TypeUncheckInput);
        term.checkInputCount = count.unsafeGet();
        return term;
    }

    static ByteTerm EOL(unsigned inputPos)
    {
        ByteTerm term(TypeAssertionEOL);
        term.inputPosition = inputPos;
        return term;
    }

    static ByteTerm WordBoundary(bool invert, unsigned inputPos)
    {
        ByteTerm term(TypeAssertionWordBoundary, invert);
        term.inputPosition = inputPos;
        return term;
    }

    static ByteTerm BackReference(unsigned subpatternId, unsigned inputPos)
    {
        return ByteTerm(TypeBackReference, subpatternId, false, false, inputPos);
    }

    static ByteTerm BodyAlternativeBegin(bool onceThrough)
    {
        ByteTerm term(TypeBodyAlternativeBegin);
        term.alternative.next = 0;
        term.alternative.end = 0;
        term.alternative.onceThrough = onceThrough;
        return term;
    }

    static ByteTerm BodyAlternativeDisjunction(bool onceThrough)
    {
        ByteTerm term(TypeBodyAlternativeDisjunction);
        term.alternative.next = 0;
        term.alternative.end = 0;
        term.alternative.onceThrough = onceThrough;
        return term;
    }

    static ByteTerm BodyAlternativeEnd()
    {
        ByteTerm term(TypeBodyAlternativeEnd);
        term.alternative.next = 0;
        term.alternative.end = 0;
        term.alternative.onceThrough = false;
        return term;
    }

    static ByteTerm AlternativeBegin()
    {
        ByteTerm term(TypeAlternativeBegin);
        term.alternative.next = 0;
        term.alternative.end = 0;
        term.alternative.onceThrough = false;
        return term;
    }

    static ByteTerm AlternativeDisjunction()
    {
        ByteTerm term(TypeAlternativeDisjunction);
        term.alternative.next = 0;
        term.alternative.end = 0;
        term.alternative.onceThrough = false;
        return term;
    }

    static ByteTerm AlternativeEnd()
    {
        ByteTerm term(TypeAlternativeEnd);
        term.alternative.next = 0;
        term.alternative.end = 0;
        term.alternative.onceThrough = false;
        return term;
    }

    static ByteTerm SubpatternBegin()
    {
        return ByteTerm(TypeSubpatternBegin);
    }

    static ByteTerm SubpatternEnd()
    {
        return ByteTerm(TypeSubpatternEnd);
    }

    static ByteTerm DotStarEnclosure(bool bolAnchor, bool eolAnchor)
    {
        ByteTerm term(TypeDotStarEnclosure);
        term.anchors.m_bol = bolAnchor;
        term.anchors.m_eol = eolAnchor;
        return term;
    }

    bool invert()
    {
        return m_invert;
    }

    bool capture()
    {
        return m_capture;
    }
};

class ByteDisjunction {
    WTF_MAKE_FAST_ALLOCATED;
public:
    ByteDisjunction(unsigned numSubpatterns, unsigned frameSize)
        : m_numSubpatterns(numSubpatterns)
        , m_frameSize(frameSize)
    {
    }

    size_t estimatedSizeInBytes() const { return terms.capacity() * sizeof(ByteTerm); }

    Vector<ByteTerm> terms;
    unsigned m_numSubpatterns;
    unsigned m_frameSize;
};

struct BytecodePattern {
    WTF_MAKE_FAST_ALLOCATED;
public:
    BytecodePattern(std::unique_ptr<ByteDisjunction> body, Vector<std::unique_ptr<ByteDisjunction>>& parenthesesInfoToAdopt, YarrPattern& pattern, BumpPointerAllocator* allocator, ConcurrentJSLock* lock)
        : m_body(WTFMove(body))
        , m_flags(pattern.m_flags)
        , m_allocator(allocator)
        , m_lock(lock)
    {
        m_body->terms.shrinkToFit();

        newlineCharacterClass = pattern.newlineCharacterClass();
        if (unicode() && ignoreCase())
            wordcharCharacterClass = pattern.wordUnicodeIgnoreCaseCharCharacterClass();
        else
            wordcharCharacterClass = pattern.wordcharCharacterClass();

        m_allParenthesesInfo.swap(parenthesesInfoToAdopt);
        m_allParenthesesInfo.shrinkToFit();

        m_userCharacterClasses.swap(pattern.m_userCharacterClasses);
        m_userCharacterClasses.shrinkToFit();
    }

    size_t estimatedSizeInBytes() const { return m_body->estimatedSizeInBytes(); }

    bool ignoreCase() const { return m_flags & FlagIgnoreCase; }
    bool multiline() const { return m_flags & FlagMultiline; }
    bool sticky() const { return m_flags & FlagSticky; }
    bool unicode() const { return m_flags & FlagUnicode; }

    std::unique_ptr<ByteDisjunction> m_body;
    RegExpFlags m_flags;
    // Each BytecodePattern is associated with a RegExp, each RegExp is associated
    // with a VM.  Cache a pointer to out VM's m_regExpAllocator.
    BumpPointerAllocator* m_allocator;
    ConcurrentJSLock* m_lock;

    CharacterClass* newlineCharacterClass;
    CharacterClass* wordcharCharacterClass;

private:
    Vector<std::unique_ptr<ByteDisjunction>> m_allParenthesesInfo;
    Vector<std::unique_ptr<CharacterClass>> m_userCharacterClasses;
};

JS_EXPORT_PRIVATE std::unique_ptr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*, ConcurrentJSLock* = nullptr);
JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const String& input, unsigned start, unsigned* output);
unsigned interpret(BytecodePattern*, const LChar* input, unsigned length, unsigned start, unsigned* output);
unsigned interpret(BytecodePattern*, const UChar* input, unsigned length, unsigned start, unsigned* output);

} } // namespace JSC::Yarr


text:
package bingo.odata.utils;

import java.sql.Time;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;

import bingo.lang.Dates;
import bingo.lang.codec.Base64;
import bingo.lang.exceptions.NotImplementedException;
import bingo.lang.value.DateTimeOffset;
import bingo.meta.edm.EdmSimpleType;
import bingo.odata.ODataErrors;
import bingo.odata.ODataException;

/**
 * Handle type operations.
 *
 * @author Thierry Boileau
 */
public class InternalTypeUtils {

	/** Formater for the EDM DateTime type. */
	public static final String[]	 dateTimeFormats	=
		new String[] { "yyyy-MM-dd'T'HH:mm:ssz", "yyyy-MM-dd'T'HH:mm:ss", "EEE, dd MMM yyyy HH:mm:ss zzz"	      };

	/** Formater for the EDM Decimal type. */
	public static final NumberFormat	decimalFormat	= DecimalFormat.getNumberInstance(Locale.US);

	/** Formater for the EDM Double type. */
	public static final NumberFormat	doubleFormat	= DecimalFormat.getNumberInstance(Locale.US);

	/** Formater for the EDM Single type. */
	public static final NumberFormat	singleFormat	= DecimalFormat.getNumberInstance(Locale.US);

	/** Formater for the EDM Time type. */
	public static final NumberFormat	timeFormat	  = DecimalFormat.getIntegerInstance(Locale.US);

	public static Date parseDateTime(String value){
		return Dates.parse(value, dateTimeFormats);
	}

	public static DateTimeOffset parseDateTimeOffset(String value){
		throw new NotImplementedException();
	}

	public static Time parseTime(String value){
		try {
	        return new Time(timeFormat.parse(value).longValue());
        } catch (ParseException e) {
        	throw new ODataException("cannot parse time value '{0}' : {1}",value,e.getMessage(),e);
        }
	}

	public static String formatDateTime(Date dt){
		return Dates.format(dt,dateTimeFormats[1]);
	}

	public static String formatDateTimeOffset(DateTimeOffset dt){
		throw ODataErrors.notImplemented();
	}

	public static String formatTime(Time t){
		throw ODataErrors.notImplemented();
	}

    /**
     * Converts the String representation of the target WCF type to its
     * corresponding value.
     *
     * @param value
     *            The value to convert.
     * @param adoNetType
     *            The target WCF type.
     * @return The converted value.
     */
    public static Object fromEdm(String value, String adoNetType) {
        if (value == null) {
            return null;
        }

        Object result = null;
        try {
            if (adoNetType.endsWith("Binary")) {
                result = Base64.decode(value);
            } else if (adoNetType.endsWith("Boolean")) {
                result = Boolean.valueOf(value);
            } else if (adoNetType.endsWith("DateTime")) {
                result = Dates.parse(value, dateTimeFormats);
            } else if (adoNetType.endsWith("DateTimeOffset")) {
                result = Dates.parse(value, dateTimeFormats);
            } else if (adoNetType.endsWith("Time")) {
                result = timeFormat.parseObject(value);
            } else if (adoNetType.endsWith("Decimal")) {
                result = decimalFormat.parseObject(value);
            } else if (adoNetType.endsWith("Single")) {
                result = singleFormat.parseObject(value);
            } else if (adoNetType.endsWith("Double")) {
                result = doubleFormat.parseObject(value);
            } else if (adoNetType.endsWith("Guid")) {
                result = value;
            } else if (adoNetType.endsWith("Int16")) {
                result = Short.valueOf(value);
            } else if (adoNetType.endsWith("Int32")) {
                result = Integer.valueOf(value);
            } else if (adoNetType.endsWith("Int64")) {
                result = Long.valueOf(value);
            } else if (adoNetType.endsWith("Byte")) {
                result = Byte.valueOf(value);
            } else if (adoNetType.endsWith("String")) {
                result = value;
            }
        } catch (Exception e) {
        	throw new ODataException("Cannot convert " + value + " from this EDM type " + adoNetType,e);
        }

        return result;
    }

    /**
     * Returns the literal form of the given value.
     *
     * @param value
     *            The value to convert.
     * @param adoNetType
     *            The type of the value.
     * @return The literal form of the given value.
     * @see <a
     *      href="http://www.odata.org/docs/%5BMC-APDSU%5D.htm#z61934eae311a4af4b8f882c112248651">Abstract
     *      Type System</a>
     */
    public static String getLiteralForm(String value, String adoNetType) {
        if (value == null) {
            return null;
        }

        String result = null;

        if (adoNetType.endsWith("Binary")) {
            result = "'" + value + "'";
        } else if (adoNetType.endsWith("DateTime")) {
            result = "datetime'" + value + "'";
        } else if (adoNetType.endsWith("DateTimeOffset")) {
            result = "datetimeoffset'" + value + "'";
        } else if (adoNetType.endsWith("Time")) {
            result = "time'" + value + "'";
        } else if (adoNetType.endsWith("Guid")) {
            result = "guid'" + value + "'";
        } else if (adoNetType.endsWith("String")) {
            result = "'" + value + "'";
        }

        return result;
    }

    public static String toEdmString(Object value, EdmSimpleType type) {
        String adoNetType = type.getName();

        if (value == null && adoNetType == null) {
            return null;
        }

        String result = null;
        if (adoNetType.endsWith("Binary")) {
            if ((byte[].class).isAssignableFrom(value.getClass())) {
                result = toEdmBinary((byte[]) value);
            }
        } else if (adoNetType.endsWith("Boolean")) {
            if ((Boolean.class).isAssignableFrom(value.getClass())) {
                result = toEdmBoolean((Boolean) value);
            }
        } else if (adoNetType.endsWith("DateTime")) {
            if ((Date.class).isAssignableFrom(value.getClass())) {
                result = toEdmDateTime((Date) value);
            }
        } else if (adoNetType.endsWith("DateTimeOffset")) {
            if ((Date.class).isAssignableFrom(value.getClass())) {
                result = toEdmDateTime((Date) value);
            }
        } else if (adoNetType.endsWith("Time")) {
            if ((Long.class).isAssignableFrom(value.getClass())) {
                result = toEdmTime((Long) value);
            }
        } else if (adoNetType.endsWith("Decimal")) {
            if ((Double.class).isAssignableFrom(value.getClass())) {
                result = toEdmDecimal((Double) value);
            }
        } else if (adoNetType.endsWith("Single")) {
            if ((Float.class).isAssignableFrom(value.getClass())) {
                result = toEdmSingle((Float) value);
            } else if ((Double.class).isAssignableFrom(value.getClass())) {
                result = toEdmSingle((Double) value);
            }
        } else if (adoNetType.endsWith("Double")) {
            if ((Double.class).isAssignableFrom(value.getClass())) {
                result = toEdmDouble((Double) value);
            }
        } else if (adoNetType.endsWith("Guid")) {
            result = value.toString();
        } else if (adoNetType.endsWith("Int16")) {
            if ((Short.class).isAssignableFrom(value.getClass())) {
                result = toEdmInt16((Short) value);
            }
        } else if (adoNetType.endsWith("Int32")) {
            if ((Integer.class).isAssignableFrom(value.getClass())) {
                result = toEdmInt32((Integer) value);
            }
        } else if (adoNetType.endsWith("Int64")) {
            if ((Long.class).isAssignableFrom(value.getClass())) {
                result = toEdmInt64((Long) value);
            }
        } else if (adoNetType.endsWith("Byte")) {
            if ((Byte.class).isAssignableFrom(value.getClass())) {
                result = toEdmByte((Byte) value);
            }
        } else if (adoNetType.endsWith("String")) {
            result = value.toString();
        }

        if (result == null) {
            result = value.toString();
        }

        return result;
    }

    public static String toEdmBinary(byte[] value) {
        return Base64.encode(value, false);
    }

    public static String toEdmBoolean(boolean value) {
        return Boolean.toString(value);
    }

    public static String toEdmByte(byte value) {
        return Byte.toString(value);
    }

    public static String toEdmDateTime(Date value) {
        return Dates.format(value, dateTimeFormats[0]);
    }

    /**
     * Convert the given value to the String representation of a EDM Decimal
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmDecimal(double value) {
        return decimalFormat.format(value);
    }

    /**
     * Convert the given value to the String representation of a EDM Double
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmDouble(double value) {
        return doubleFormat.format(value);
    }

    /**
     * Convert the given value to the String representation of a EDM Int16
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmInt16(short value) {
        return Short.toString(value);
    }

    /**
     * Convert the given value to the String representation of a EDM Int32
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmInt32(int value) {
        return Integer.toString(value);
    }

    /**
     * Convert the given value to the String representation of a EDM Int64
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmInt64(long value) {
        return Long.toString(value);
    }

    /**
     * Converts a value to the String representation of the target WCF type when
     * used a key in the URIs.
     *
     * @param value
     *            The value to convert.
     * @param type
     *            The target WCF type.
     * @return The converted value.
     */
    public static String toEdmKey(Object value, EdmSimpleType type) {
        String adoNetType = type.getName();
        if (value == null && adoNetType == null) {
            return null;
        }

        String result = null;
        if (adoNetType.endsWith("Binary")) {
            if ((byte[].class).isAssignableFrom(value.getClass())) {
                result = toEdmBinary((byte[]) value);
            }
        } else if (adoNetType.endsWith("Boolean")) {
            if ((Boolean.class).isAssignableFrom(value.getClass())) {
                result = toEdmBoolean((Boolean) value);
            }
        } else if (adoNetType.endsWith("DateTime")) {
            if ((Date.class).isAssignableFrom(value.getClass())) {
                result = toEdmDateTime((Date) value);
            }
        } else if (adoNetType.endsWith("DateTimeOffset")) {
            if ((Date.class).isAssignableFrom(value.getClass())) {
                result = toEdmDateTime((Date) value);
            }
        } else if (adoNetType.endsWith("Time")) {
            if ((Long.class).isAssignableFrom(value.getClass())) {
                result = toEdmTime((Long) value);
            }
        } else if (adoNetType.endsWith("Decimal")) {
            if ((Double.class).isAssignableFrom(value.getClass())) {
                result = toEdmDecimal((Double) value);
            }
        } else if (adoNetType.endsWith("Single")) {
            if ((Float.class).isAssignableFrom(value.getClass())) {
                result = toEdmSingle((Float) value);
            } else if ((Double.class).isAssignableFrom(value.getClass())) {
                result = toEdmSingle((Double) value);
            }
        } else if (adoNetType.endsWith("Double")) {
            if ((Double.class).isAssignableFrom(value.getClass())) {
                result = toEdmDouble((Double) value);
            }
        } else if (adoNetType.endsWith("Guid")) {
            result = value.toString();
        } else if (adoNetType.endsWith("Int16")) {
            if ((Short.class).isAssignableFrom(value.getClass())) {
                result = toEdmInt16((Short) value);
            }
        } else if (adoNetType.endsWith("Int32")) {
            if ((Integer.class).isAssignableFrom(value.getClass())) {
                result = toEdmInt32((Integer) value);
            }
        } else if (adoNetType.endsWith("Int64")) {
            if ((Long.class).isAssignableFrom(value.getClass())) {
                result = toEdmInt64((Long) value);
            }
        } else if (adoNetType.endsWith("Byte")) {
            if ((Byte.class).isAssignableFrom(value.getClass())) {
                result = toEdmByte((Byte) value);
            }
        } else if (adoNetType.endsWith("String")) {
            result = "'" + value.toString() + "'";
        }

        if (result == null) {
            result = value.toString();
        }

        return result;
    }

    /**
     * Convert the given value to the String representation of a EDM Single
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmSingle(double value) {
        return singleFormat.format(value);
    }

    /**
     * Convert the given value to the String representation of a EDM Single
     * value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmSingle(float value) {
        return singleFormat.format(value);
    }

    /**
     * Convert the given value to the String representation of a EDM Time value.
     *
     * @param value
     *            The value to convert.
     * @return The value converted as String object.
     */
    public static String toEdmTime(long value) {
        return timeFormat.format(value);
    }

    /**
     * Returns the corresponding Java class or scalar type.
     *
     * @param edmTypeName
     *            The type name.
     * @return The corresponding Java class or scalar type.
     */
    public static Class<?> toJavaClass(String edmTypeName) {
        Class<?> result = Object.class;
        if (edmTypeName.endsWith("Binary")) {
            result = byte[].class;
        } else if (edmTypeName.endsWith("Boolean")) {
            result = Boolean.class;
        } else if (edmTypeName.endsWith("DateTime")) {
            result = Date.class;
        } else if (edmTypeName.endsWith("DateTimeOffset")) {
            result = Date.class;
        } else if (edmTypeName.endsWith("Time")) {
            result = Long.class;
        } else if (edmTypeName.endsWith("Decimal")) {
            result = Double.class;
        } else if (edmTypeName.endsWith("Single")) {
            result = Double.class;
        } else if (edmTypeName.endsWith("Double")) {
            result = Double.class;
        } else if (edmTypeName.endsWith("Guid")) {
            result = String.class;
        } else if (edmTypeName.endsWith("Int16")) {
            result = Short.class;
        } else if (edmTypeName.endsWith("Int32")) {
            result = Integer.class;
        } else if (edmTypeName.endsWith("Int64")) {
            result = Long.class;
        } else if (edmTypeName.endsWith("Byte")) {
            result = Byte.class;
        } else if (edmTypeName.endsWith("String")) {
            result = String.class;
        }

        return result;
    }

    /**
     * Returns the name of the corresponding Java class or scalar type.
     *
     * @param edmTypeName
     *            The type name.
     * @return The name of the corresponding Java class or scalar type.
     */
    public static String toJavaTypeName(String edmTypeName) {
        String result = "Object";
        if (edmTypeName.endsWith("Binary")) {
            result = "byte[]";
        } else if (edmTypeName.endsWith("Boolean")) {
            result = "boolean";
        } else if (edmTypeName.endsWith("DateTime")) {
            result = "Date";
        } else if (edmTypeName.endsWith("DateTimeOffset")) {
            result = "Date";
        } else if (edmTypeName.endsWith("Time")) {
            result = "long";
        } else if (edmTypeName.endsWith("Decimal")) {
            result = "double";
        } else if (edmTypeName.endsWith("Single")) {
            result = "double";
        } else if (edmTypeName.endsWith("Double")) {
            result = "double";
        } else if (edmTypeName.endsWith("Guid")) {
            result = "String";
        } else if (edmTypeName.endsWith("Int16")) {
            result = "short";
        } else if (edmTypeName.endsWith("Int32")) {
            result = "int";
        } else if (edmTypeName.endsWith("Int64")) {
            result = "long";
        } else if (edmTypeName.endsWith("Byte")) {
            result = "byte";
        } else if (edmTypeName.endsWith("String")) {
            result = "String";
        }

        return result;
    }
}

redpajama_set_name: RedPajamaGithub


text: <forward mode="$type"/>


text:
package io.github.pturczyk.yaml.mojo;

import io.github.pturczyk.yaml.util.YamlFileUtils;
import io.github.pturczyk.yaml.validator.ValidationException;
import io.github.pturczyk.yaml.validator.YamlValidator;
import org.apache.maven.plugin.MojoFailureException;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.internal.util.collections.Sets;
import org.mockito.internal.util.reflection.Whitebox;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.IOException;
import java.io.InputStream;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;

/**
 * @author pturczyk@gmail.com
 */
@ExtendWith(MockitoExtension.class)
public class YamlValidationMojoTest {

    @Mock
    private YamlValidator validator;

    @Mock
    private YamlFileUtils fileUtils;

    @InjectMocks
    private YamlValidationMojo yamlValidationMojo;

    @Test
    void testExecutionShouldContinueOnFailure()  throws MojoFailureException, IOException, ValidationException {

        // given
        Set<String> yamlPaths = Sets.newSet("/path/file1.yml", "/path/file2.yml");
        given(fileUtils.getAbsoluteFilePaths(anySetOf(String.class))).willReturn(yamlPaths);

        InputStream mockedInputStream = mock(InputStream.class);
        given(fileUtils.openStream(anyString())).willReturn(mockedInputStream);

        ValidationException exception = new ValidationException("", null);
        doThrow(exception).when(validator).validate(any(InputStream.class), anyBoolean());

        // when
        yamlValidationMojo.execute();

        // then
        verify(validator, times(2)).validate(any(InputStream.class), anyBoolean());
    }

    @Test
    void testExecutionShouldStopOnFailure() throws IOException, ValidationException {

        // given
        Set<String> yamlPaths = Sets.newSet("/path/file1.yml", "/path/file2.yml");
        given(fileUtils.getAbsoluteFilePaths(anySetOf(String.class))).willReturn(yamlPaths);

        InputStream mockedInputStream = mock(InputStream.class);
        given(fileUtils.openStream(anyString())).willReturn(mockedInputStream);

        ValidationException exception = new ValidationException("", null);
        doThrow(exception).when(validator).validate(any(InputStream.class), anyBoolean());

        Whitebox.setInternalState(yamlValidationMojo, "failOnError", true);

        // when
        Throwable caught = catchThrowable(new ThrowingCallable() {
            @Override
            public void call() throws Throwable {
                yamlValidationMojo.execute();
            }
        });

        // then
        assertThat(caught).isInstanceOf(MojoFailureException.class).hasCauseInstanceOf(ValidationException.class);
        verify(validator).validate(any(InputStream.class), anyBoolean());
    }

}


text:
<!DOCTYPE html>

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  <link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
  <link href='https://fonts.googleapis.com/css?family=Titillium+Web' rel='stylesheet' type='text/css'>

  <link rel="apple-touch-icon" sizes="57x57" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="60x60" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="72x72" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="76x76" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="114x114" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="120x120" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="144x144" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="152x152" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-152x152.png">
  <link rel="apple-touch-icon" sizes="180x180" href="http://chrispilcher.us/capstone/favicon/apple-touch-icon-180x180.png">
  <link rel="icon" type="image/png" href="http://chrispilcher.us/capstone/favicon/favicon-32x32.png" sizes="32x32">
  <link rel="icon" type="image/png" href="http://chrispilcher.us/capstone/favicon/android-chrome-192x192.png" sizes="192x192">
  <link rel="icon" type="image/png" href="http://chrispilcher.us/capstone/favicon/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="http://chrispilcher.us/capstone/favicon/favicon-16x16.png" sizes="16x16">
  <link rel="manifest" href="http://chrispilcher.us/capstone/favicon/manifest.json">
  <link rel="mask-icon" href="http://chrispilcher.us/capstone/favicon/safari-pinned-tab.svg" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="msapplication-TileImage" content="http://chrispilcher.us/capstone/favicon/mstile-144x144.png">
  <meta name="theme-color" content="#ffffff">

  <title>Capstone 2016</title>

Capstone 2016 - Medical Express Software Suite Development Site

        Your source for totally real and definitely not fake medical information!

Close/Open Schedule

Module 1

Dec 10

Flo

No due dates

Module 2

Dec 17, Jan 7

Roger

Work due Jan 13

Module 3

Jan 14, Jan 21

Chris

Work due Jan 27

Module 4

Jan 28, Feb 4

Erica

Work due Feb 10

Module 5

Feb 11, Feb 18

Jose

Work due Feb 24

Module 6

Feb 25, Mar 3

Daquain/Adam

Work due Mar 9

            Meeting Minutes Week 5

            Team Lead: Chris Pilcher

              Everyone should be working on getting a Java development environment up and running on their own, personal computer.

              We need a "physician availability" table in the ERD.

              Use cases:

                  Every conceivable use case should be accounted for.

                  There should be one screen for each use case.

                  Example:

                    A staff member needs to look up a patient's phone number.

                  You can use wireframes to help with your use case diagrams.

            Meeting Minutes Week 4

            Team Lead: Chris Pilcher

            Reminder: Get in touch with Daquain and Flow

              Erica will update Project Plan. Chris will update the Dates.

              Chris will complete ERD by Wed. 1/20/16

              Chris will update Req. doc by Wed. 1/20/16

            Friday, 1/15/2016: Jose/Chris/Roger -- meetup for Context Diagram

            Context Diagrams Due Wed. 1/20/16

              Database Module: Chris

              Appointment Module: Erica

              Patient Module: Adam

              Reporting Module: Roger

              Medical Advice: Jose

            Slack Meeting on Sunday, 1/17/16 2pm

            Agenda for Module 2

Leader: Roger Marquez

            During the weeks of December 17th and January 7th, we will be establishing a more detailed project schedule. That means we need to figure out who will be working on what and at what time they will need to be finished. Using the rough outline that we put together last week, we should be able to assign a couple people to work on each upcoming portion of the project.

            We should also start work on building our patient database. Having it built and testable will mean we have more time to work on the meat and potatoes of our project: The application. Note, we don't have to finish the database early. It would just help to have it in the works earlier.

Project Name:

Medical Express 2018

Project Definition:

Application Language: Java, Go

Database Language: SQL

Implementation Software: MySQL, Apache2

Productivity & Development Software: Eclipse, MS Project, MS Word, MS Visio, MS PowerPoint, Google Hangouts, Slack, Nginx

Project Calendar:

December 10th: Agenda Decided

January 13th: Project Schedule

January 27th: Data-Flow Diagram, Entity Relational Diagram

February 10th: Database Prototype Implementation, Database Management module

Start testing database

February 5th: Final Exam

February 24th: Completed Database, Application Prototype

Start testing application

March 9th: Presentation

Project Purpose: Creating an application that collects and displays health information about individual patients, provides standard reporting and scheduling capabilities, and employs standard terminology. The software should include international classifications of medical standards such as ICD-10 coding and useful features for medical advice generation.

Project Goals and Objectives:

To have a functional database that can store the patient information in a way that can be presented in a user-friendly interface.

To have an application that can reliably analyze and manage the information in the database. It will be split into five modules:

Patient module: Direct interface to enter patient data

Appointment module: Direct interface to enter appointments, based on physician availability

Medical Advice module: Should analyze diagnosis and recommend medication/course of action

Reporting module: Read only interface to Medical Advice module

Database Management module: To manage patient database

Success Criteria:

The completion of both goals.

Navigation

            Learning Portal

            Blogs to follow


text:
(function() {

    angular
        .module('problem')
        .controller('ProblemsController', ProblemsController);

        ProblemsController.$inject = ['noteService', '$state'];

    /**
     * Main Controller for the Angular Material Starter App
     * @param $scope
     * @param $mdSidenav
     * @param avatarsService
     * @constructor
     */
    function ProblemsController(noteService, $state) {
        var psc = this;

        psc.problemsId = $state.params.id;

        psc.problems = [];
        psc.note_tepmlate = {
            type: {
                id: 2,
                name: 'problem'
            },
            parent_id: psc.problemsId
        };
        /*pc.selected = null;
        pc.selectUser = selectUser;
        pc.toggleList = toggleUsersList;
        pc.makeContact = makeContact;*/

        // Load all types

        noteService
            .loadAllNotesForParrent(psc.problemsId)
            .then(function(problems) {
                psc.problems = [].concat(problems.data);
            });
    }

})();


text:
Copyright (c) 2015 Altoidnerd
http://altoidnerd.com

![plot.png](https://raw.githubusercontent.com/Altoidnerd/bitcoin-price/master/plot.png "plot-example.py in action - matplotlib required")
http://altoidnerd.com/2015/09/11/bitcoin-data-manipulaton-and-plotting-in-python/

## Create a quick plot of bitcoin's price history:

    from price_dump import *
    import matplotlib.pyplot as plt

    data = get_first_N(147) #Currently there are about 148 pages available.
    price = prices(data)
    bins = range(0, len(price))

    plt.plot(bins, price[::-1])
    plt.show()

![log-plot.png](http://i.imgur.com/EsOkkkt.png "Actually this image is a log plot, but it's only a slight modification - see log-plot-expample.py")

... actually this image is a log plot, but it's only a slight modification - see log-plot-expample.py.

## Clone the repo, and run the tests.

    git clone https://github.com/altoidnerd/bitcoin-price.git
    cd bitcoin-price
    python3 ./tests/test.py

Hopefully you will see something like this

    t_index2k:  311
    t_index1k:  44
    timestamp test 1:  PASS
    timestamp test 2:  PASS
    timestamp test 3:  PASS
    prices test 1:  PASS
    prices test 2:  PASS
    parse test 1:  PASS

Please help out by improving and writing more tests.

## Learn by doing ...

Get bitcoin price data from the coinbase API and parse it into an easily manipulated form.

    >>> from fast_dump_v22 import *
    >>> get_page(1)

Will return all the data on page 1 of coinbase's bitcoin price API (this is the latest data).

You can almost always turn on optional debug statements

    >>> get_first_N(3, show=True)
    ... fetching first 3

You can get all the price data that coinbase has

    >>> get_all(show=True)
    ... getting page 1
    ... getting page 2
    ... getting page 3
    ... getting page 4
    ... getting page 5
    ... getting page 6
    ... getting page 7
    ... getting page 8
    ... getting page 9
    ... etc ...

All the 'get_*' functions return a price_data string, which is interlaced timespams and prices littered with newlines and commas.  You can print them to see what is going on more clearly:

    >>> print(get_page(1))
    2015-09-11T06:44:04-05:00,241.14
    2015-09-11T06:34:04-05:00,240.8
    2015-09-11T06:24:04-05:00,240.75
    2015-09-11T06:14:05-05:00,240.68
    2015-09-11T06:04:04-05:00,240.83
    2015-09-11T05:54:05-05:00,240.92
    2015-09-11T05:44:04-05:00,240.64
    2015-09-11T04:34:04-05:00,241.27
    2015-09-11T04:24:04-05:00,240.73
    ...

Turn on the optional show switch for printing large vectors

    >>> prices(get_page(11), show=True)
    ... returning 11000 prices in specified range ...
    ['239.9',
    '239.9',
    '239.4',
    '239.77',
    '239.33',
    '239.99',
    '239.81',
    '240.28',
    '240.4',
You can use prices(data)[k] and timestamps()[j] to return the kth price in data, or the jth timestamp in data.

    >>> data = get_page(1)
    >>> prices(data)[4]
    '241.2'
    >>> prices(data, index=4)
    '241.2'

are two equivalent ways of returning only the 4th price in the requested range (in this case, page 1).  This also works for timestamps.

    >>> timestamps(get_page(1)+get_page(2))[1166] == timestamps(get_first_N(2), index=1166)
    True

This shows the expressiveness of this module. In general:

    >>> prices(get_page(2)) == parse(get_page(2))[0]
    True

prices() and timestamps() are just functions that return a parsed() object having a specific index, or indices.

    >>> parse(get_page(1)+get_page(2)+get_page(3))[0] == prices(get_first_N(3))
    True
    >>> parse(get_page(2)+get_page(3))[0] == prices(get_range(2,3))
    True

The parse() function is there to manually control the outputs instead of just getting prices, or timestamps

    >>> x = parse(get_page(1))
    >>> x[0][0]
    '241.2'
    >>> x[0][1]
    '241.14'
    >>> x[1][1]
    '2015-09-11T04:34:04-07:00'

As you can see, parse(price_data)[0][k] returns the kth price in the list.  Indices [1][k] return the kth timestamp.

The parse() function takes care of some weird edge cases:

    >>> get_first_N(3) == get_page(1)+get_page(2)+get_page(3)
    False
    >>> parse(get_first_N(3)) == parse(get_page(1)+get_page(2)+get_page(3))
    True
    >>> x = get_page(1)
    >>> y = get_range(2,7)
    >>> prices(get_first_N(7)) == prices(x+y)
    True

In general,

    OPERATOR( get_page(1) + get_page(2) + ... + get_page(k) ) == OPERATOR(get_first_N(k))

where operator is parsed(), prices(), or timestamps().  We also know

prices() can obviously display and return ranges of values.  When returning large vectors, you can verify their length by setting show=True.  The "show" parameter is optional for all get\_\* functions and provides some information about the operation being performed.

    >>> print( prices(get_first_N(11), show=True) )
    ... returning 11000 prices in specified range...

since each page is a thousand pairs of values (timestamp, price).

    >>> len(prices(get_page(2))
    1000
    >>> prices(get_page(2))  # returns a long list
    ['230.11',
     '229.64',
     '230.04',
     '229.71',
     '229.69',
     '229.74',
     '229.92',
     '229.43',
     '229.43',
     '229.41',
    ...

* fast_dump_v1* are older versions that are somewhat different.  They are designed to store the fetched data in the .data directory.  This in v2*, this was abandoned in favor of stdout redirection.

// 2015 altodinerd.com