text:
package owl.sod.hlds;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

public class SemanticDescription {
    public List<AtomicConcept> atomicConcepts;
    public List<GreaterThanRole> greaterThanRoles;
    public List<LessThanRole> lessThanRoles;
    public List<UniversalRole> universalRoles;

    public SemanticDescription() {
        this.atomicConcepts = new ArrayList();
        this.greaterThanRoles = new ArrayList();
        this.lessThanRoles = new ArrayList();
        this.universalRoles = new ArrayList();
    }

    public List<AtomicConcept> getConcepts() {
        List<AtomicConcept> subClass = new ArrayList();
        for (int i = 0; i < this.atomicConcepts.size(); i++) {
            if (!((AtomicConcept) this.atomicConcepts.get(i)).denied) {
                subClass.add((AtomicConcept) this.atomicConcepts.get(i));
            }
        }
        return subClass;
    }

    public List<AtomicConcept> getComplements() {
        List<AtomicConcept> complements = new ArrayList();
        for (int i = 0; i < this.atomicConcepts.size(); i++) {
            if (((AtomicConcept) this.atomicConcepts.get(i)).denied) {
                complements.add((AtomicConcept) this.atomicConcepts.get(i));
            }
        }
        return complements;
    }

    public void addConcept(AtomicConcept atomicConcept) {
        this.atomicConcepts.add(atomicConcept);
    }

    public void addConcepts(List<AtomicConcept> v) {
        for (int i = 0; i < v.size(); i++) {
            if (!this.atomicConcepts.contains(v.get(i)))
                this.atomicConcepts.add((AtomicConcept) v.get(i));
        }
    }

    public void addGreaterThanRole(GreaterThanRole greaterThanRole) {
        this.greaterThanRoles.add(greaterThanRole);
    }

    public void addLessThanRole(LessThanRole lessThanRole) {
        this.lessThanRoles.add(lessThanRole);
    }

    public void addUniversalRole(UniversalRole universalRole) {
        this.universalRoles.add(universalRole);
    }

    public void addAllFromSD(SemanticDescription sourceSD) {
        this.atomicConcepts.addAll(sourceSD.atomicConcepts);
        this.greaterThanRoles.addAll(sourceSD.greaterThanRoles);
        this.lessThanRoles.addAll(sourceSD.lessThanRoles);
        this.universalRoles.addAll(sourceSD.universalRoles);
    }

    public void removeUniversalRole(UniversalRole universalRole) {
        this.universalRoles.remove(universalRole);
    }

    public void removeConcept(AtomicConcept atomicConcept) {
        this.atomicConcepts.remove(atomicConcept);
    }

    public void removegreaterThanRoles(GreaterThanRole greaterThanRole) {
        this.greaterThanRoles.remove(greaterThanRole);
    }

    public void removelessThanRoles(LessThanRole lessThanRole) {
        this.lessThanRoles.remove(lessThanRole);
    }

    public String toString() {
        String outputString = "(";

        if ((this.atomicConcepts != null) || (this.greaterThanRoles != null) || (this.lessThanRoles != null) || (this.universalRoles != null)) {

            if (this.atomicConcepts != null) {
                for (AtomicConcept atomicConcept : this.atomicConcepts) {
                    if (atomicConcept.denied) {
                        outputString = outputString + "!";
                    }
                    outputString = outputString + atomicConcept.name;
                    outputString = outputString + ",";
                }
            }
            if (this.greaterThanRoles != null) {
                for (GreaterThanRole greaterThanRole : this.greaterThanRoles) {
                    outputString = outputString + greaterThanRole.name + ">=" + greaterThanRole.cardinality + ",";
                }
            }
            if (this.lessThanRoles != null) {
                for (LessThanRole lessThanRole : this.lessThanRoles) {
                    outputString = outputString + lessThanRole.name + "<=" + lessThanRole.cardinality + ",";
                }
            }
            if (this.universalRoles != null) {
                for (UniversalRole ur : this.universalRoles) {
                    outputString = outputString + ur.toString();
                }
            }
        }
        if (outputString.length() > 1) {
            outputString = outputString.substring(0, outputString.length() - 1);
        }

        outputString = outputString + ")";
        return outputString;
    }

    public boolean isSubsumed(SemanticDescription subsumer) {
        if (this.atomicConcepts != null) {
            for (AtomicConcept atomicConcept : this.atomicConcepts) {
                if (atomicConcept.name.equals("Nothing")) {
                    return true;
                }
            }
        }

        if ((subsumer.atomicConcepts != null) && (this.atomicConcepts != null)) {
            for (AtomicConcept subsumerConc : subsumer.atomicConcepts) {
                boolean result = false;
                for (AtomicConcept thisConc : this.atomicConcepts) {
                    if (((thisConc.name.equals(subsumerConc.name)) || (subsumerConc.name.contains("Thing"))) && (thisConc.denied == subsumerConc.denied)) {
                        result = true;
                    }
                }
                if (!result) {
                    return false;
                }
            }
        }

        if ((subsumer.greaterThanRoles != null) && (this.greaterThanRoles != null)) {
            for (GreaterThanRole subsumerGTR : subsumer.greaterThanRoles) {
                boolean result = false;
                for (GreaterThanRole thisGTR : this.greaterThanRoles) {
                    if ((thisGTR.name.equals(subsumerGTR.name)) && (thisGTR.cardinality >= subsumerGTR.cardinality)) {
                        result = true;
                    }
                }
                if (!result) {
                    return false;
                }
            }
        }

        if ((subsumer.lessThanRoles != null) && (this.lessThanRoles != null)) {
            for (LessThanRole subsumerLTR : subsumer.lessThanRoles) {
                boolean result = false;
                for (LessThanRole thisLTR : this.lessThanRoles) {
                    if ((thisLTR.name.equals(subsumerLTR.name)) && (thisLTR.cardinality <= subsumerLTR.cardinality)) {
                        result = true;
                    }
                }
                if (!result) {
                    return false;
                }
            }
        }

        if ((subsumer.universalRoles != null) && (this.universalRoles != null)) {
            for (UniversalRole subsumerUV : subsumer.universalRoles) {
                boolean result = false;
                for (UniversalRole thisUV : this.universalRoles) {
                    if (subsumerUV.name.equals(thisUV.name)) {
                        result = thisUV.filler.isSubsumed(subsumerUV.filler);
                    }
                }
                if (!result) {
                    return false;
                }
            }
        }

        return true;
    }

    public boolean checkCompatibility(SemanticDescription demandSD) {
        if ((demandSD.atomicConcepts != null) && (this.atomicConcepts != null)) {
            for (AtomicConcept demandConc : demandSD.atomicConcepts) {
                boolean result = conceptSearch(this.atomicConcepts, demandConc);
                if (result) {
                    return false;
                }
            }
        }
        if ((demandSD.greaterThanRoles != null) && (this.lessThanRoles != null)) {
            for (GreaterThanRole demandGT : demandSD.greaterThanRoles) {
                boolean result = numberRoleSearchGT(this.lessThanRoles, demandGT);
                if (result) {
                    return false;
                }
            }
        }
        if ((demandSD.lessThanRoles != null) && (this.greaterThanRoles != null)) {
            for (LessThanRole demandLT : demandSD.lessThanRoles) {
                boolean result = numberRoleSearchLT(this.greaterThanRoles, demandLT);
                if (result) {
                    return false;
                }
            }
        }

        if ((demandSD.universalRoles != null) && (this.universalRoles != null)) {
//            Iterator localIterator2;
//            for (??? =demandSD.universalRoles.iterator(); ???.hasNext();
//            localIterator2.hasNext())
//            {
//                UniversalRole sdUniversalRole = (UniversalRole) ???.next();
//                localIterator2 = this.universalRoles.iterator();
//                continue;
//                UniversalRole thisUniversalRole = (UniversalRole) localIterator2.next();
//                if ((sdUniversalRole.name.equals(thisUniversalRole.name)) && ((hasRelation(this.greaterThanRoles, sdUniversalRole.name)) || (hasRelation(demandSD.greaterThanRoles, sdUniversalRole.name))) &&
//                        (!thisUniversalRole.filler.checkCompatibility(sdUniversalRole.filler))) {
//                    return false;
//                }
//            }
        }

        return true;
    }

    public Abduction abduce(SemanticDescription demandSD) {
        SemanticDescription H = new SemanticDescription();
        double penalty = 0.0D;
        int index = -1;

        if (demandSD.atomicConcepts != null) {
            if (this.atomicConcepts != null) {
                for (AtomicConcept demandConcept : demandSD.atomicConcepts) {
                    if (!this.atomicConcepts.contains(demandConcept)) {
                        H.addConcept(demandConcept);
                        penalty += 1.0D;
                    }
                }
            } else {
                H.atomicConcepts = demandSD.atomicConcepts;
                penalty += demandSD.atomicConcepts.size();
            }
        }

        if (demandSD.greaterThanRoles != null) {
            if (this.greaterThanRoles != null) {
                for (GreaterThanRole demandGTRole : demandSD.greaterThanRoles) {
                    index = this.greaterThanRoles.indexOf(demandGTRole);
                    if (index >= 0) {
                        GreaterThanRole great = (GreaterThanRole) this.greaterThanRoles.get(index);
                        if (great.cardinality < demandGTRole.cardinality) {
                            H.addGreaterThanRole(demandGTRole);

                            penalty = penalty + (demandGTRole.cardinality - great.cardinality) / demandGTRole.cardinality;
                        }
                    } else {
                        H.addGreaterThanRole(demandGTRole);
                        penalty += 1.0D;
                    }
                }
            } else {
                H.greaterThanRoles = demandSD.greaterThanRoles;
                penalty += demandSD.greaterThanRoles.size();
            }
        }

        if (demandSD.lessThanRoles != null) {
            if (this.lessThanRoles != null) {
                for (LessThanRole demandLTRole : demandSD.lessThanRoles) {
                    index = this.lessThanRoles.indexOf(demandLTRole);
                    if (index >= 0) {
                        LessThanRole less = (LessThanRole) this.lessThanRoles.get(index);
                        if (less.cardinality > demandLTRole.cardinality) {
                            H.addLessThanRole(demandLTRole);

                            penalty = penalty + (less.cardinality - demandLTRole.cardinality) / less.cardinality;
                        }
                    } else {
                        H.addLessThanRole(demandLTRole);
                        penalty += 1.0D;
                    }
                }
            } else {
                H.lessThanRoles = demandSD.lessThanRoles;
                penalty += demandSD.lessThanRoles.size();
            }
        }

        if (demandSD.universalRoles != null) {
            if (this.universalRoles != null) {
                for (UniversalRole demandURole : demandSD.universalRoles) {
                    index = this.universalRoles.indexOf(demandURole);
                    if (index >= 0) {
                        UniversalRole thisUniversalRole = (UniversalRole) this.universalRoles.get(index);
                        Abduction uRoleAbductionResult = thisUniversalRole.filler.abduce(demandURole.filler);
                        if ((!uRoleAbductionResult.H.atomicConcepts.isEmpty()) || (!uRoleAbductionResult.H.greaterThanRoles.isEmpty()) || (!uRoleAbductionResult.H.lessThanRoles.isEmpty()) || (!uRoleAbductionResult.H.universalRoles.isEmpty())) {
                            H.addUniversalRole(new UniversalRole(demandURole.name, uRoleAbductionResult.H));
                            penalty += uRoleAbductionResult.penalty;
                        }
                    } else {
                        H.addUniversalRole(new UniversalRole(demandURole.name, demandURole.filler));
                        penalty += new SemanticDescription().abduce(demandURole.filler).penalty;
                    }
                }
            } else {
                H.universalRoles = demandSD.universalRoles;
                for (UniversalRole demandURole : demandSD.universalRoles) {
                    penalty += new SemanticDescription().abduce(demandURole.filler).penalty;
                }
            }
        }

        return new Abduction(H, penalty);
    }

    public Contraction contract(SemanticDescription demandSD) {
        SemanticDescription G = new SemanticDescription();
        SemanticDescription K = new SemanticDescription();
        double penalty = 0.0D;

        K.addAllFromSD(demandSD);
        Iterator localIterator1;
        Iterator localIterator2;
        if ((demandSD.atomicConcepts != null) &&
                (this.atomicConcepts != null)) {
            for (localIterator1 = demandSD.atomicConcepts.iterator(); localIterator1.hasNext();
                 localIterator2.hasNext()) {
                AtomicConcept demandConcept = (AtomicConcept) localIterator1.next();
                localIterator2 = this.atomicConcepts.iterator();
                continue;
//                AtomicConcept thisConcept = (AtomicConcept) localIterator2.next();
//                if ((thisConcept.name.equals(demandConcept.name)) && (thisConcept.denied != demandConcept.denied)) {
//                    G.addConcept(demandConcept);
//                    K.removeConcept(demandConcept);
//                    penalty += 1.0D;
//                }
            }
        }

        if ((demandSD.greaterThanRoles != null) &&
                (this.lessThanRoles != null)) {
            for (localIterator1 = demandSD.greaterThanRoles.iterator(); localIterator1.hasNext();
                 localIterator2.hasNext()) {
                GreaterThanRole demandGTRole = (GreaterThanRole) localIterator1.next();
                localIterator2 = this.lessThanRoles.iterator();
                continue;
//                LessThanRole thisLTRole = (LessThanRole) localIterator2.next();
//                if ((thisLTRole.name.equals(demandGTRole.name)) && (thisLTRole.cardinality < demandGTRole.cardinality)) {
//                    G.addGreaterThanRole(demandGTRole);
//                    K.removegreaterThanRoles(demandGTRole);
//                    K.addGreaterThanRole(new GreaterThanRole(thisLTRole.name, thisLTRole.cardinality));
//
//                    penalty = penalty + (demandGTRole.cardinality - thisLTRole.cardinality) / demandGTRole.cardinality;
//                }
            }
        }

        if ((demandSD.lessThanRoles != null) &&
                (this.greaterThanRoles != null)) {
            for (localIterator1 = demandSD.lessThanRoles.iterator(); localIterator1.hasNext();
                 localIterator2.hasNext()) {
                LessThanRole demandLTRole = (LessThanRole) localIterator1.next();
                localIterator2 = this.greaterThanRoles.iterator();
                continue;
//                GreaterThanRole thisGTRole = (GreaterThanRole) localIterator2.next();
//                if ((thisGTRole.name.equals(demandLTRole.name)) && (thisGTRole.cardinality > demandLTRole.cardinality)) {
//                    G.addLessThanRole(demandLTRole);
//                    K.removelessThanRoles(demandLTRole);
//                    K.addLessThanRole(new LessThanRole(thisGTRole.name, thisGTRole.cardinality));
//
//                    penalty = penalty + (thisGTRole.cardinality - demandLTRole.cardinality) / thisGTRole.cardinality;
//                }
            }
        }

        if ((demandSD.universalRoles != null) &&
                (this.universalRoles != null)) {
            for (localIterator1 = demandSD.universalRoles.iterator(); localIterator1.hasNext();
                 localIterator2.hasNext()) {
                UniversalRole demandURole = (UniversalRole) localIterator1.next();
                localIterator2 = this.universalRoles.iterator();
                continue;
//                UniversalRole thisUniversalRole = (UniversalRole) localIterator2.next();
//                if (demandURole.name.equals(thisUniversalRole.name)) {
//                    if ((demandSD.greaterThanRoles != null) && (hasRelation(demandSD.greaterThanRoles, demandURole.name))) {
//                        Contraction uRoleContractionResult = thisUniversalRole.filler.contract(demandURole.filler);
//                        if ((!uRoleContractionResult.G.atomicConcepts.isEmpty()) || (!uRoleContractionResult.G.greaterThanRoles.isEmpty()) || (!uRoleContractionResult.G.lessThanRoles.isEmpty()) || (!uRoleContractionResult.G.universalRoles.isEmpty())) {
//                            G.addUniversalRole(new UniversalRole(demandURole.name, uRoleContractionResult.G));
//                            K.removeUniversalRole(demandURole);
//                            K.addUniversalRole(new UniversalRole(demandURole.name, uRoleContractionResult.K));
//                            penalty += uRoleContractionResult.penalty;
//                        }
//                    } else if ((demandSD.lessThanRoles != null) && (this.greaterThanRoles != null)) {
//                        GreaterThanRole gtr = extractFromlistGTR(this.greaterThanRoles, thisUniversalRole.name);
//                        LessThanRole ltr = extractFromlistLTR(demandSD.lessThanRoles, thisUniversalRole.name);
//                        if (gtr.cardinality < ltr.cardinality) {
//                            Contraction uRoleContractionResult = thisUniversalRole.filler.contract(demandURole.filler);
//                            if ((!uRoleContractionResult.G.atomicConcepts.isEmpty()) || (!uRoleContractionResult.G.greaterThanRoles.isEmpty()) || (!uRoleContractionResult.G.lessThanRoles.isEmpty()) || (!uRoleContractionResult.G.universalRoles.isEmpty())) {
//                                G.addUniversalRole(new UniversalRole(demandURole.name, uRoleContractionResult.G));
//                                K.removeUniversalRole(demandURole);
//                                K.addUniversalRole(new UniversalRole(demandURole.name, uRoleContractionResult.K));
//                                penalty += uRoleContractionResult.penalty;
//                            }
//                        }
//                    }
//                }
            }
        }

        return new Contraction(G, K, penalty);
    }

    public boolean isACover(SemanticDescription demandSD) {
        if ((demandSD.atomicConcepts != null) &&
                (this.atomicConcepts != null)) {
            for (int i = 0; i < demandSD.atomicConcepts.size(); i++) {
                AtomicConcept demandConcept = (AtomicConcept) demandSD.atomicConcepts.get(i);
                if (this.atomicConcepts.contains(demandConcept)) {
                    return true;
                }
            }
        }

        if ((demandSD.greaterThanRoles != null) &&
                (this.greaterThanRoles != null)) {
            for (int i = 0; i < demandSD.greaterThanRoles.size(); i++) {
                GreaterThanRole demandGTRole = (GreaterThanRole) demandSD.greaterThanRoles.get(i);
                if (this.greaterThanRoles.contains(demandGTRole)) {
                    return true;
                }
            }
        }

        LessThanRole demandLTRole;
        if ((demandSD.lessThanRoles != null) &&
                (this.lessThanRoles != null)) {
            for (int i = 0; i < demandSD.lessThanRoles.size(); i++) {
                demandLTRole = (LessThanRole) demandSD.lessThanRoles.get(i);
                if (this.lessThanRoles.contains(demandLTRole)) {
                    return true;
                }
            }
        }

        if ((demandSD.universalRoles != null) &&
                (this.universalRoles != null)) {
            for (UniversalRole demandURole : demandSD.universalRoles) {
                if (this.universalRoles.contains(demandURole)) {
                    for (UniversalRole thisUniversalRole : this.universalRoles) {
                        if ((demandURole.name.equals(thisUniversalRole.name)) &&
                                (thisUniversalRole.filler.isACover(demandURole.filler))) {
                            return true;
                        }
                    }
                }
            }
        }

        return false;
    }

    public Composition greedyCCoP(Vector<Item> resources) {
        Vector<Item> Rc = new Vector();
        Item demand = new Item("");
        demand.description = this;
        Item Du = new Item("");
        Du.copy(demand);
        Item Hmin = new Item("");
        Hmin.copy(demand);
        int hmin = (int) Math.round(new SemanticDescription().abduce(demand.description).penalty);
        Item Smax;
        do {
            Smax = new Item("");
            Item supply = new Item("");
            for (int j = 0; j < resources.size(); j++) {
                supply = (Item) resources.elementAt(j);
                boolean compatible = true;
                if (!Rc.isEmpty()) {
                    for (int i = 0; i < Rc.size(); i++) {
                        Item resource = (Item) Rc.elementAt(i);
                        compatible = (compatible) && (resource.description.checkCompatibility(supply.description));
                    }
                }
                if ((compatible) &&
                        (supply.description.isACover(Du.description))) {
                    Item H = new Item("");
                    H.description = supply.description.abduce(Du.description).H;
                    int h = (int) Math.round(new SemanticDescription().abduce(H.description).penalty);
                    if (h < hmin) {
                        Smax.copy(supply);
                        Hmin.copy(H);
                        hmin = h;
                    }
                }
            }

            if ((!Smax.description.atomicConcepts.isEmpty()) || (!Smax.description.greaterThanRoles.isEmpty()) || (!Smax.description.lessThanRoles.isEmpty()) || (!Smax.description.universalRoles.isEmpty())) {
                for (int i = 0; i < resources.size(); i++) {
                    Item servizio = (Item) resources.elementAt(i);
                    if (servizio.name.equals(Smax.name)) {
                        resources.remove(servizio);
                    }
                }
                Rc.add(Smax);
                Du.copy(Hmin);
            }
        }
        while ((!Smax.description.atomicConcepts.isEmpty()) || (!Smax.description.greaterThanRoles.isEmpty()) || (!Smax.description.lessThanRoles.isEmpty()) || (!Smax.description.universalRoles.isEmpty()));

        return new Composition(Rc, Du);
    }

    protected boolean hasRelation(List<GreaterThanRole> greaterThanRoles, String name) {
        if (greaterThanRoles != null) {
            for (GreaterThanRole gret : greaterThanRoles) {
                if ((gret.name.equals(name)) && (gret.cardinality >= 1)) {
                    return true;
                }
            }
            return false;
        }
        return false;
    }

    protected boolean checkUniversal(SemanticDescription demandSD) {
        if ((demandSD.atomicConcepts != null) && (this.atomicConcepts != null)) {
            for (AtomicConcept demandConc : demandSD.atomicConcepts) {
                boolean result = conceptSearch(this.atomicConcepts, demandConc);
                if (result) {
                    return false;
                }
            }
        }
        if ((demandSD.greaterThanRoles != null) && (this.lessThanRoles != null)) {
            for (GreaterThanRole demandGT : demandSD.greaterThanRoles) {
                boolean result = numberRoleSearchGT(this.lessThanRoles, demandGT);
                if (result) {
                    return false;
                }
            }
        }
        if ((demandSD.lessThanRoles != null) && (this.greaterThanRoles != null)) {
            for (LessThanRole demandLT : demandSD.lessThanRoles) {
                boolean result = numberRoleSearchLT(this.greaterThanRoles, demandLT);
                if (result) {
                    return false;
                }
            }
        }

        if ((demandSD.universalRoles != null) && (this.universalRoles != null)) {
//            Iterator localIterator2;
//            for (??? =demandSD.universalRoles.iterator(); ???.hasNext();
//            localIterator2.hasNext())
//            {
//                UniversalRole sdUniversalRole = (UniversalRole) ???.next();
//                localIterator2 = this.universalRoles.iterator();
//                continue;
//                UniversalRole thisUniversalRole = (UniversalRole) localIterator2.next();
//                if (sdUniversalRole.name.equals(thisUniversalRole.name)) {
//                    boolean res = thisUniversalRole.filler.checkUniversal(sdUniversalRole.filler);
//                    if (!res) {
//                        LessThanRole ltrole = new LessThanRole();
//                        ltrole.name = thisUniversalRole.name;
//                        ltrole.cardinality = 0;
//                        addLessThanRole(ltrole);
//                    }
//                }
//            }
        }

        return true;
    }

    protected boolean conceptSearch(List<AtomicConcept> atomicConcepts, AtomicConcept atomicConcept) {
        for (AtomicConcept concetto : atomicConcepts) {
            if ((concetto.name.equals(atomicConcept.name)) && (concetto.denied != atomicConcept.denied)) {
                return true;
            }
        }
        return false;
    }

    protected boolean numberRoleSearchGT(List<LessThanRole> numberRoles, GreaterThanRole role) {
        for (LessThanRole less : numberRoles) {
            if ((less.name.equals(role.name)) && (role.cardinality > less.cardinality)) {
                return true;
            }
        }
        return false;
    }

    protected boolean numberRoleSearchLT(List<GreaterThanRole> numberRoles, LessThanRole role) {
        for (GreaterThanRole great : numberRoles) {
            if ((great.name.equals(role.name)) && (role.cardinality < great.cardinality)) {
                return true;
            }
        }
        return false;
    }

    protected GreaterThanRole extractFromlistGTR(List<GreaterThanRole> ls, String name) {
        GreaterThanRole gtr = new GreaterThanRole();

        for (int i = 0; i < ls.size(); i++) {
            gtr = (GreaterThanRole) ls.get(i);
            if (gtr.name.equals(name)) {
                return gtr;
            }
        }

        return gtr;
    }

    protected LessThanRole extractFromlistLTR(List<LessThanRole> ls, String name) {
        LessThanRole ltr = new LessThanRole();

        for (int i = 0; i < ls.size(); i++) {
            ltr = (LessThanRole) ls.get(i);
            if (ltr.name.equals(name)) {
                return ltr;
            }
        }

        return ltr;
    }

    protected void delete(SemanticDescription demandSD) {
        if ((demandSD.atomicConcepts != null) && (this.atomicConcepts != null)) {
            for (int i = 0; i < demandSD.atomicConcepts.size(); i++) {
                removeConcept((AtomicConcept) demandSD.atomicConcepts.get(i));
            }
        }
        if ((demandSD.greaterThanRoles != null) && (this.greaterThanRoles != null)) {
            for (int i = 0; i < demandSD.greaterThanRoles.size(); i++) {
                removegreaterThanRoles((GreaterThanRole) demandSD.greaterThanRoles.get(i));
            }
        }
        if ((demandSD.lessThanRoles != null) && (this.lessThanRoles != null)) {
            for (int i = 0; i < demandSD.lessThanRoles.size(); i++) {
                removelessThanRoles((LessThanRole) demandSD.lessThanRoles.get(i));
            }
        }
        if ((demandSD.universalRoles != null) && (this.universalRoles != null)) {
            for (int i = 0; i < demandSD.universalRoles.size(); i++) {
                UniversalRole demandUR = (UniversalRole) demandSD.universalRoles.get(i);
                for (int j = 0; j < this.universalRoles.size(); j++) {
                    UniversalRole itemUR = (UniversalRole) this.universalRoles.get(j);
                    if (itemUR.name.equals(demandUR.name)) {
                        itemUR.filler.delete(demandUR.filler);
                    }
                }
            }
        }
    }

    protected String toXML(String name) {
        return "<D name=\"" + name + "\">\n" + XMLBody() + "</D>\n";
    }

    protected String XMLBody() {
        String outputString = "";

        if ((this.atomicConcepts != null) || (this.greaterThanRoles != null) || (this.lessThanRoles != null) || (this.universalRoles != null)) {
            if ((this.atomicConcepts != null) &&
                    (this.atomicConcepts.size() > 0)) {
                AtomicConcept atomicConcept = (AtomicConcept) this.atomicConcepts.get(0);
                outputString = outputString + "<Cs>\n<C id=\"" + atomicConcept.name + "\"/>\n</Cs>\n";
            }

            if ((this.greaterThanRoles != null) &&
                    (this.greaterThanRoles.size() > 0)) {
                outputString = outputString + "<GTRs>\n";
                for (int i = 0; i < this.greaterThanRoles.size(); i++) {
                    GreaterThanRole gtr = (GreaterThanRole) this.greaterThanRoles.get(i);
                    outputString = outputString + "<GTR id=\"" + gtr.name + "\" n=\"" + gtr.cardinality + "\"/>\n";
                }
                outputString = outputString + "</GTRs>\n";
            }

            if ((this.lessThanRoles != null) &&
                    (this.lessThanRoles.size() > 0)) {
                outputString = outputString + "<LTRs>\n";
                for (int i = 0; i < this.lessThanRoles.size(); i++) {
                    LessThanRole ltr = (LessThanRole) this.lessThanRoles.get(i);
                    outputString = outputString + "<LTR id=\"" + ltr.name + "\" n=\"" + ltr.cardinality + "\"/>\n";
                }
                outputString = outputString + "</LTRs>\n";
            }

            if ((this.universalRoles != null) &&
                    (this.universalRoles.size() > 0)) {
                outputString = outputString + "<URs>\n";
                for (int i = 0; i < this.universalRoles.size(); i++) {
                    UniversalRole ur = (UniversalRole) this.universalRoles.get(i);
                    String xmlBody = ur.filler.XMLBody();
                    if (!xmlBody.equals(""))
                        outputString = outputString + "<UR id=\"" + ur.name + "\">\n" + xmlBody + "</UR>\n";
                }
                outputString = outputString + "</URs>\n";
            }
        }

        return outputString;
    }

    public SemanticDescription subtract(SemanticDescription d) {
        SemanticDescription r = new SemanticDescription();

        if (this.atomicConcepts != null) {
            for (int i = 0; i < this.atomicConcepts.size(); i++) {
                AtomicConcept c = (AtomicConcept) this.atomicConcepts.get(i);
                if ((d.atomicConcepts == null) || (!d.atomicConcepts.contains(c))) {
                    r.addConcept(c);
                }
            }
        }
        if (this.greaterThanRoles != null) {
            for (int i = 0; i < this.greaterThanRoles.size(); i++) {
                GreaterThanRole g1 = (GreaterThanRole) this.greaterThanRoles.get(i);
                if (d.greaterThanRoles == null) {
                    r.addGreaterThanRole(g1);
                } else {
                    for (int j = 0; j < d.greaterThanRoles.size(); j++) {
                        GreaterThanRole g2 = (GreaterThanRole) d.greaterThanRoles.get(j);
                        if ((g1.name.equals(g2.name)) &&
                                (g1.cardinality < g2.cardinality)) {
                            int min = g1.cardinality;
                            int max = g2.cardinality - 1;
                            GreaterThanRole g = new GreaterThanRole();
                            g.name = g1.name;
                            g.cardinality = min;
                            r.addGreaterThanRole(g);
                            LessThanRole l = new LessThanRole();
                            l.name = g1.name;
                            l.cardinality = max;
                            r.addLessThanRole(l);
                        }
                    }
                }
            }
        }

        if (this.lessThanRoles != null) {
            for (int i = 0; i < this.lessThanRoles.size(); i++) {
                LessThanRole l1 = (LessThanRole) this.lessThanRoles.get(i);
                if (d.lessThanRoles == null) {
                    r.addLessThanRole(l1);
                } else {
                    for (int j = 0; j < d.lessThanRoles.size(); j++) {
                        LessThanRole l2 = (LessThanRole) d.lessThanRoles.get(j);
                        if ((l1.name.equals(l2.name)) &&
                                (l1.cardinality > l2.cardinality)) {
                            int min = l2.cardinality + 1;
                            int max = l1.cardinality;
                            GreaterThanRole g = new GreaterThanRole();
                            g.name = l1.name;
                            g.cardinality = min;
                            r.addGreaterThanRole(g);
                            LessThanRole l = new LessThanRole();
                            l.name = l1.name;
                            l.cardinality = max;
                            r.addLessThanRole(l);
                        }
                    }
                }
            }
        }

        if (this.universalRoles != null) {
            for (int i = 0; i < this.universalRoles.size(); i++) {
                UniversalRole u = (UniversalRole) this.universalRoles.get(i);
                if ((d.universalRoles == null) || (!d.universalRoles.contains(u))) {
                    r.addUniversalRole(u);
                } else {
                    SemanticDescription f1 = u.filler;
                    SemanticDescription f2 = ((UniversalRole) d.universalRoles.get(d.universalRoles.indexOf(u))).filler;
                    SemanticDescription df = f1.subtract(f2);
                    if ((!df.atomicConcepts.isEmpty()) || (!df.lessThanRoles.isEmpty()) || (!df.greaterThanRoles.isEmpty()) || (!df.universalRoles.isEmpty())) {
                        UniversalRole ur = new UniversalRole(u.name, df);
                        r.addUniversalRole(ur);
                    }
                }
            }
        }

        return r;
    }
}


text:
package com.digits.sdk.android;

import android.os.Build;

import com.twitter.sdk.android.core.AuthenticatedClient;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Session;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterCore;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;

import javax.net.ssl.SSLSocketFactory;

import retrofit.RestAdapter;
import retrofit.android.MainThreadExecutor;
import retrofit.http.Field;
import retrofit.http.FormUrlEncoded;
import retrofit.http.GET;
import retrofit.http.POST;
import retrofit.http.Query;

class DigitsApiClient {
    private final ConcurrentHashMap<Class, Object> services;
    private final RestAdapter restAdapter;
    private final Session session;

    DigitsApiClient(Session session) {
        this(session, TwitterCore.getInstance().getAuthConfig(),
                TwitterCore.getInstance().getSSLSocketFactory(), Digits.getInstance()
                        .getExecutorService(),
                new DigitsUserAgent(Digits.getInstance().getVersion(), Build.VERSION.RELEASE));
    }

    DigitsApiClient(Session session, TwitterAuthConfig authConfig,
            SSLSocketFactory sslFactory, ExecutorService executorService,
            DigitsUserAgent userAgent) {
        this.session = session;
        this.services = new ConcurrentHashMap<>();
        this.restAdapter = new RestAdapter.Builder()
                .setEndpoint(new DigitsApi().getBaseHostUrl())
                .setRequestInterceptor(new DigitsRequestInterceptor(userAgent))
                .setExecutors(executorService, new MainThreadExecutor())
                .setClient(new AuthenticatedClient(authConfig, session, sslFactory))
                .build();
    }

    public Session getSession() {
        return session;
    }

    public SdkService getSdkService() {
        return getService(SdkService.class);
    }

    public DeviceService getDeviceService() {
        return getService(DeviceService.class);
    }

    public AccountService getAccountService() {
        return getService(AccountService.class);
    }

    @SuppressWarnings("unchecked")
    private <T> T getService(Class<T> cls) {
        if (!services.containsKey(cls)) {
            services.put(cls, restAdapter.create(cls));
        }
        return (T) services.<T>get(cls);
    }

    protected interface DeviceService {
        @FormUrlEncoded
        @POST("/1.1/device/register.json")
        void register(@Field("raw_phone_number") String rawPhoneNumber,
                @Field("text_key") String textKey,
                @Field("send_numeric_pin") Boolean sendNumericPin,
                @Field("lang") String lang,
                @Field("client_identifier_string") String id,
                @Field("verification_type") String verificationType,
                Callback<DeviceRegistrationResponse> cb);
    }

    protected interface SdkService {
        @FormUrlEncoded
        @POST("/1.1/sdk/account.json")
        void account(@Field("phone_number") String phoneNumber,
                            @Field("numeric_pin") String numericPin,
                            Callback<DigitsUser> cb);

        @FormUrlEncoded
        @POST("/1/sdk/login")
        void auth(@Field("x_auth_phone_number") String phoneNumber, @Field("verification_type")
        String verificationType, Callback<AuthResponse> cb);

        @FormUrlEncoded
        @POST("/auth/1/xauth_challenge.json")
        void login(@Field("login_verification_request_id") String requestId,
                          @Field("login_verification_user_id") long userId,
                          @Field("login_verification_challenge_response") String code,
                          Callback<DigitsSessionResponse> cb);

        @FormUrlEncoded
        @POST("/auth/1/xauth_pin.json")
        void verifyPin(@Field("login_verification_request_id") String requestId,
                       @Field("login_verification_user_id") long userId,
                       @Field("pin") String pin,
                       Callback<DigitsSessionResponse> cb);

        @POST("/1.1/sdk/account/email")
        void email(@Query("email_address") String email, Callback<DigitsSessionResponse> cb);
    }

    public interface AccountService {
        @GET("/1.1/sdk/account.json")
        void verifyAccount(Callback<VerifyAccountResponse> cb);
    }
}

redpajama_set_name: RedPajamaGithub


text:
package org.apache.olingo.server.core.deserializer.batch;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

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

import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
import org.junit.Test;

public class BatchRequestParserTest {

  private static final String SERVICE_ROOT = "http://localhost/odata";
  private static final String CRLF = "\r\n";
  private static final String BOUNDARY = "batch_8194-cf13-1f56";
  private static final String MIME_HEADERS = "Content-Type: application/http" + CRLF
      + "Content-Transfer-Encoding: binary" + CRLF;
  private static final String GET_REQUEST = ""
      + MIME_HEADERS
      + CRLF
      + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
      + CRLF
      + CRLF;

  @Test
  public void test() throws Exception {
    final InputStream in = readFile("/batchWithPost.batch");
    final List<BatchRequestPart> batchRequestParts = parse(in);

    assertNotNull(batchRequestParts);
    assertFalse(batchRequestParts.isEmpty());

    for (BatchRequestPart object : batchRequestParts) {
      if (!object.isChangeSet()) {
        assertEquals(1, object.getRequests().size());
        ODataRequest retrieveRequest = object.getRequests().get(0);
        assertEquals(HttpMethod.GET, retrieveRequest.getMethod());

        if (retrieveRequest.getHeaders(HttpHeader.ACCEPT_LANGUAGE) != null) {
          assertEquals(3, retrieveRequest.getHeaders(HttpHeader.ACCEPT_LANGUAGE).size());
        }

        assertEquals(SERVICE_ROOT, retrieveRequest.getRawBaseUri());
        assertEquals("/Employees('2')/EmployeeName", retrieveRequest.getRawODataPath());
        assertEquals("http://localhost/odata/Employees('2')/EmployeeName?$format=json", retrieveRequest
            .getRawRequestUri());
        assertEquals("$format=json", retrieveRequest.getRawQueryPath());
      } else {
        List<ODataRequest> requests = object.getRequests();
        for (ODataRequest request : requests) {

          assertEquals(HttpMethod.PUT, request.getMethod());
          assertEquals("100000", request.getHeader(HttpHeader.CONTENT_LENGTH));
          assertEquals("application/json;odata=verbose", request.getHeader(HttpHeader.CONTENT_TYPE));

          List<String> acceptHeader = request.getHeaders(HttpHeader.ACCEPT);
          assertEquals(3, request.getHeaders(HttpHeader.ACCEPT).size());
          assertEquals("application/atomsvc+xml;q=0.8", acceptHeader.get(0));
          assertEquals("*/*;q=0.1", acceptHeader.get(2));

          assertEquals("http://localhost/odata/Employees('2')/EmployeeName", request.getRawRequestUri());
          assertEquals("http://localhost/odata", request.getRawBaseUri());
          assertEquals("/Employees('2')/EmployeeName", request.getRawODataPath());
          assertEquals("", request.getRawQueryPath()); // No query parameter
        }
      }
    }
  }

  @Test
  public void testImageInContent() throws Exception {
    final InputStream contentInputStream = readFile("/batchWithContent.batch");
    final String content = IOUtils.toString(contentInputStream);
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees?$filter=Age%20gt%2040 HTTP/1.1" + CRLF
        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + "content-type:     Application/http" + CRLF
        + "content-transfer-encoding: Binary" + CRLF
        + "Content-ID: 1" + CRLF
        + CRLF
        + "POST Employees HTTP/1.1" + CRLF
        + "Content-length: 100000" + CRLF
        + "Content-type: application/octet-stream" + CRLF
        + CRLF
        + content
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + "--batch_8194-cf13-1f56--";
    final List<BatchRequestPart> BatchRequestParts = parse(batch);

    for (BatchRequestPart part : BatchRequestParts) {
      if (!part.isChangeSet()) {
        assertEquals(1, part.getRequests().size());
        final ODataRequest retrieveRequest = part.getRequests().get(0);

        assertEquals(HttpMethod.GET, retrieveRequest.getMethod());
        assertEquals("http://localhost/odata/Employees?$filter=Age%20gt%2040", retrieveRequest.getRawRequestUri());
        assertEquals("http://localhost/odata", retrieveRequest.getRawBaseUri());
        assertEquals("/Employees", retrieveRequest.getRawODataPath());
        assertEquals("$filter=Age%20gt%2040", retrieveRequest.getRawQueryPath());
      } else {
        final List<ODataRequest> requests = part.getRequests();
        for (ODataRequest request : requests) {
          assertEquals(HttpMethod.POST, request.getMethod());
          assertEquals("100000", request.getHeader(HttpHeader.CONTENT_LENGTH));
          assertEquals("1", request.getHeader(HttpHeader.CONTENT_ID));
          assertEquals("application/octet-stream", request.getHeader(HttpHeader.CONTENT_TYPE));

          final InputStream body = request.getBody();
          assertEquals(content, IOUtils.toString(body));
        }
      }
    }
  }

  @Test
  public void testPostWithoutBody() throws Exception {
    final String batch = CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: changeRequest1" + CRLF
        + CRLF
        + "POST Employees('2') HTTP/1.1" + CRLF
        + "Content-Length: 100" + CRLF
        + "Content-Type: application/octet-stream" + CRLF
        + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";
    final List<BatchRequestPart> batchRequestParts = parse(batch);

    for (BatchRequestPart object : batchRequestParts) {
      if (object.isChangeSet()) {
        final List<ODataRequest> requests = object.getRequests();

        for (ODataRequest request : requests) {
          assertEquals(HttpMethod.POST, request.getMethod());
          assertEquals("100", request.getHeader(HttpHeader.CONTENT_LENGTH));
          assertEquals("application/octet-stream", request.getHeader(HttpHeader.CONTENT_TYPE));
          assertNotNull(request.getBody());
        }
      }
    }
  }

  @Test
  public void testAbsoluteUri() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET http://localhost/odata/Employees('1')/EmployeeName?$top=1 HTTP/1.1" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    final List<BatchRequestPart> batchRequestParts = parse(batch);

    assertEquals(1, batchRequestParts.size());
    final BatchRequestPart part = batchRequestParts.get(0);

    assertEquals(1, part.getRequests().size());
    final ODataRequest request = part.getRequests().get(0);

    assertEquals("/Employees('1')/EmployeeName", request.getRawODataPath());
    assertEquals("$top=1", request.getRawQueryPath());
    assertEquals("http://localhost/odata/Employees('1')/EmployeeName?$top=1", request.getRawRequestUri());
    assertEquals("http://localhost/odata", request.getRawBaseUri());
  }

  @Test
  public void boundaryParameterWithQuotes() throws Exception {
    final String contentType = "multipart/mixed; boundary=\"batch_1.2+34:2j)0?\"";
    final String boundary = BatchParserCommon.getBoundary(contentType, 0);
    final String batch = ""
        + "--batch_1.2+34:2j)0?" + CRLF
        + GET_REQUEST
        + "--batch_1.2+34:2j)0?--";
    final BatchParser parser = new BatchParser();
    final BatchOptions batchOptions = BatchOptions.with().isStrict(true).rawBaseUri(SERVICE_ROOT).build();
    final List<BatchRequestPart> batchRequestParts =
        parser.parseBatchRequest(IOUtils.toInputStream(batch), boundary, batchOptions);

    assertNotNull(batchRequestParts);
    assertFalse(batchRequestParts.isEmpty());
  }

  @Test
  public void testBatchWithInvalidContentType() throws Exception {
    final String invalidContentType = "multipart;boundary=batch_1740-bb84-2f7f";

    try {
      BatchParserCommon.getBoundary(invalidContentType, 0);
      fail();
    } catch (BatchDeserializerException e) {
      assertMessageKey(e, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
    }
  }

  @Test
  public void testContentTypeCharset() throws Exception {
    final String contentType = "multipart/mixed; charset=UTF-8;boundary=batch_14d1-b293-b99a";
    final String boundary = BatchParserCommon.getBoundary(contentType, 0);

    assertEquals("batch_14d1-b293-b99a", boundary);
  }

  @Test
  public void batchWithoutBoundaryParameter() throws Exception {
    final String invalidContentType = "multipart/mixed";

    try {
      BatchParserCommon.getBoundary(invalidContentType, 0);
      fail();
    } catch (BatchDeserializerException e) {
      assertMessageKey(e, BatchDeserializerException.MessageKeys.MISSING_BOUNDARY_DELIMITER);
    }
  }

  @Test
  public void boundaryParameterWithoutQuote() throws Exception {
    final String invalidContentType = "multipart/mixed;boundary=batch_1740-bb:84-2f7f";

    try {
      BatchParserCommon.getBoundary(invalidContentType, 0);
      fail();
    } catch (BatchDeserializerException e) {
      assertMessageKey(e, BatchDeserializerException.MessageKeys.INVALID_BOUNDARY);
    }
  }

  @Test
  public void testWrongBoundaryString() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f5" + CRLF
        + GET_REQUEST
        + "--batch_8194-cf13-1f56--";

    final List<BatchRequestPart> parts = parse(batch);
    assertEquals(0, parts.size());
  }

  @Test
  public void testMissingHttpVersion() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: application/http" + CRLF
        + "Content-Transfer-Encoding:binary" + CRLF
        + CRLF
        + "GET Employees?$format=json" + CRLF
        + "Host: localhost:8080" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE);
  }

  @Test
  public void testMissingHttpVersion2() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: application/http" + CRLF
        + "Content-Transfer-Encoding:binary" + CRLF
        + CRLF
        + "GET Employees?$format=json " + CRLF
        + "Host: localhost:8080" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HTTP_VERSION);
  }

  @Test
  public void testMissingHttpVersion3() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: application/http" + CRLF
        + "Content-Transfer-Encoding:binary" + CRLF
        + CRLF
        + "GET Employees?$format=json SMTP:3.1" + CRLF
        + "Host: localhost:8080" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HTTP_VERSION);
  }

  @Test
  public void testBoundaryWithoutHyphen() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + GET_REQUEST
        + "batch_8194-cf13-1f56" + CRLF
        + GET_REQUEST
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT);
  }

  @Test
  public void testNoBoundaryString() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + GET_REQUEST
        // + no boundary string
        + GET_REQUEST
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT);
  }

  @Test
  public void testBatchBoundaryEqualsChangeSetBoundary() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=batch_8194-cf13-1f56" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "PUT Employees('2')/EmployeeName HTTP/1.1" + CRLF
        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--"
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE);
  }

  @Test
  public void testNoContentType() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Transfer-Encoding: binary" + CRLF
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE);
  }

  @Test
  public void testMimeHeaderContentType() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: text/plain" + CRLF
        + "Content-Transfer-Encoding: binary" + CRLF
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
  }

  @Test
  public void testMimeHeaderEncoding() throws Exception {
    String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: application/http" + CRLF
        + "Content-Transfer-Encoding: 8bit" + CRLF
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING);
  }

  @Test
  public void testGetRequestMissingCRLF() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        // + CRLF // Belongs to the GET request
        + CRLF // Belongs to the
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE);
  }

  @Test
  public void testInvalidMethodForBatch() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "POST Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_QUERY_OPERATION_METHOD);
  }

  @Test
  public void testNoBoundaryFound() throws Exception {
    final String batch = "batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "POST Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF;

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
  }

  @Test
  public void testEmptyRequest() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56--";

    final List<BatchRequestPart> parts = parse(batch);
    assertEquals(0, parts.size());
  }

  @Test
  public void testBadRequest() throws Exception {
    final String batch = "This is a bad request. There is no syntax and also no semantic";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
  }

  @Test
  public void testNoMethod() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + /* GET */"Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE);
  }

  @Test
  public void testInvalidMethodForChangeset() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "GET Employees('2')/EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd--"
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CHANGESET_METHOD);
  }

  @Test
  public void testInvalidChangeSetBoundary() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94d"/* +"d" */+ CRLF
        + MIME_HEADERS
        + CRLF
        + "POST Employees('2') HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    final List<BatchRequestPart> parts = parse(batch);
    assertEquals(1, parts.size());

    final BatchRequestPart part = parts.get(0);
    assertTrue(part.isChangeSet());
    assertEquals(0, part.getRequests().size());
  }

  @Test
  public void testNestedChangeset() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + "Content-Transfer-Encoding: binary" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd2" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd2" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "POST Employees('2') HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF + "MaxDataServiceVersion: 2.0" + CRLF
        + "Content-Id: 2"
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
  }

  @Test
  public void testMissingContentTransferEncoding() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + "Content-Id: 1" + CRLF
        + "Content-Type: application/http" + CRLF
        // + "Content-Transfer-Encoding: binary" + CRLF
        + CRLF
        + "POST Employees('2') HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING);
  }

  @Test
  public void testMissingContentType() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + "Content-Id: 1"
        // + "Content-Type: application/http" + CRLF
        + "Content-Transfer-Encoding: binary" + CRLF
        + CRLF
        + "POST Employees('2') HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE);
  }

  @Test
  public void testNoCloseDelimiter() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + GET_REQUEST;

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
  }

  @Test
  public void testNoCloseDelimiter2() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF;

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
  }

  @Test
  public void testUriWithAbsolutePath() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Host: http://localhost" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_URI);
  }

  @Test
  public void testUriWithAbsolutePathMissingHostHeader() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.INVALID_URI);
  }

  @Test
  public void testUriWithAbsolutePathOtherHost() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Host: http://localhost2" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.INVALID_URI);
  }

  @Test
  public void testUriWithAbsolutePathWrongPath() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET /myservice/Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Host: http://localhost" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.INVALID_URI);
  }

  @Test
  public void testNoCloseDelimiter3() throws Exception {
    final String batch = "--batch_8194-cf13-1f56" + CRLF + GET_REQUEST + "--batch_8194-cf13-1f56-"/* no hyphen */;

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
  }

  @Test
  public void testNegativeContentLengthChangeSet() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + "Content-Length: -2" + CRLF
        + CRLF
        + "PUT EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "Content-Id: 1" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parse(batch);
  }

  @Test
  public void testNegativeContentLengthRequest() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + CRLF
        + "PUT EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "Content-Id: 1" + CRLF
        + "Content-Length: 2" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parse(batch);
  }

  @Test
  public void testContentLengthGreatherThanBodyLength() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + CRLF
        + "PUT Employee/Name HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "Content-Length: 100000" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";
    final List<BatchRequestPart> batchRequestParts = parse(batch);

    assertNotNull(batchRequestParts);

    for (BatchRequestPart multipart : batchRequestParts) {
      if (multipart.isChangeSet()) {
        assertEquals(1, multipart.getRequests().size());

        final ODataRequest request = multipart.getRequests().get(0);
        assertEquals("{\"EmployeeName\":\"Peter Fall\"}", IOUtils.toString(request.getBody()));
      }
    }
  }

  @Test
  public void testContentLengthSmallerThanBodyLength() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + CRLF
        + "PUT EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "Content-Length: 10" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";
    final List<BatchRequestPart> batchRequestParts = parse(batch);

    assertNotNull(batchRequestParts);

    for (BatchRequestPart multipart : batchRequestParts) {
      if (multipart.isChangeSet()) {
        assertEquals(1, multipart.getRequests().size());

        final ODataRequest request = multipart.getRequests().get(0);
        assertEquals("{\"Employee", IOUtils.toString(request.getBody()));
      }
    }
  }

  @Test
  public void testNonNumericContentLength() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + CRLF
        + "PUT EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "Content-Length: 10abc" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HEADER);
  }

  @Test
  public void testNonStrictParser() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_8194-cf13-1f56" + CRLF
        + "--changeset_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + "Content-ID: myRequest" + CRLF
        + "PUT Employees('2')/EmployeeName HTTP/1.1" + CRLF
        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
        + "--changeset_8194-cf13-1f56--" + CRLF
        + "--batch_8194-cf13-1f56--";

    final List<BatchRequestPart> requests = parse(batch, false);

    assertNotNull(requests);
    assertEquals(1, requests.size());

    final BatchRequestPart part = requests.get(0);
    assertTrue(part.isChangeSet());
    assertNotNull(part.getRequests());
    assertEquals(1, part.getRequests().size());

    final ODataRequest changeRequest = part.getRequests().get(0);
    assertEquals("{\"EmployeeName\":\"Frederic Fall MODIFIED\"}",
        IOUtils.toString(changeRequest.getBody()));
    assertEquals("application/json;odata=verbose", changeRequest.getHeader(HttpHeader.CONTENT_TYPE));
    assertEquals(HttpMethod.PUT, changeRequest.getMethod());
  }

  @Test
  public void testNonStrictParserMoreCRLF() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed;boundary=changeset_8194-cf13-1f56" + CRLF
        + "--changeset_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + CRLF // Only one CRLF allowed
        + "PUT Employees('2')/EmployeeName HTTP/1.1" + CRLF
        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "MaxDataServiceVersion: 2.0" + CRLF
        + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
        + "--changeset_8194-cf13-1f56--" + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, false);
  }

  @Test
  public void testContentId() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees HTTP/1.1" + CRLF
        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
        + "Content-Id: BBB" + CRLF
        + CRLF + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "POST Employees HTTP/1.1" + CRLF
        + "Content-type: application/octet-stream" + CRLF
        + CRLF
        + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + CRLF
        + "PUT $1/EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + "Content-Id: 2" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    final List<BatchRequestPart> batchRequestParts = parse(batch);
    assertNotNull(batchRequestParts);

    for (BatchRequestPart multipart : batchRequestParts) {
      if (!multipart.isChangeSet()) {
        assertEquals(1, multipart.getRequests().size());
        final ODataRequest retrieveRequest = multipart.getRequests().get(0);

        assertEquals("BBB", retrieveRequest.getHeader(HttpHeader.CONTENT_ID));
      } else {
        for (ODataRequest request : multipart.getRequests()) {
          if (HttpMethod.POST.equals(request.getMethod())) {
            assertEquals("1", request.getHeader(HttpHeader.CONTENT_ID));
          } else if (HttpMethod.PUT.equals(request.getMethod())) {
            assertEquals("2", request.getHeader(HttpHeader.CONTENT_ID));
            assertEquals("/$1/EmployeeName", request.getRawODataPath());
            assertEquals("http://localhost/odata/$1/EmployeeName", request.getRawRequestUri());
          }
        }
      }
    }
  }

  @Test
  public void testNoContentId() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees HTTP/1.1" + CRLF
        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
        + CRLF + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "POST Employees HTTP/1.1" + CRLF
        + "Content-type: application/octet-stream" + CRLF
        + CRLF
        + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "PUT $1/EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parse(batch);
  }

  @Test
  public void testPreamble() throws Exception {
    final String batch = ""
        + "This is a preamble and must be ignored" + CRLF
        + CRLF
        + CRLF
        + "----1242" + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees HTTP/1.1" + CRLF
        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
        + "Content-Id: BBB" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "This is a preamble and must be ignored" + CRLF
        + CRLF
        + CRLF
        + "----1242" + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "POST Employees HTTP/1.1" + CRLF
        + "Content-type: application/octet-stream" + CRLF
        + CRLF
        + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 2" + CRLF
        + CRLF
        + "PUT $1/EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";
    final List<BatchRequestPart> batchRequestParts = parse(batch);

    assertNotNull(batchRequestParts);
    assertEquals(2, batchRequestParts.size());

    final BatchRequestPart getRequestPart = batchRequestParts.get(0);
    assertEquals(1, getRequestPart.getRequests().size());

    final ODataRequest getRequest = getRequestPart.getRequests().get(0);
    assertEquals(HttpMethod.GET, getRequest.getMethod());

    final BatchRequestPart changeSetPart = batchRequestParts.get(1);
    assertEquals(2, changeSetPart.getRequests().size());
    assertEquals("/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA"
        + CRLF,
        IOUtils.toString(changeSetPart.getRequests().get(0).getBody()));
    assertEquals("{\"EmployeeName\":\"Peter Fall\"}",
        IOUtils.toString(changeSetPart.getRequests().get(1).getBody()));
  }

  @Test
  public void testContentTypeCaseInsensitive() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: muLTiParT/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + "Content-Length: 200" + CRLF
        + CRLF
        + "PUT EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parse(batch);
  }

  @Test
  public void testContentTypeBoundaryCaseInsensitive() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; bOunDaRy=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 1" + CRLF
        + CRLF
        + "PUT EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";
    final List<BatchRequestPart> batchRequestParts = parse(batch);

    assertNotNull(batchRequestParts);
    assertEquals(1, batchRequestParts.size());
    assertTrue(batchRequestParts.get(0).isChangeSet());
    assertEquals(1, batchRequestParts.get(0).getRequests().size());
  }

  @Test
  public void testEpilog() throws Exception {
    String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees HTTP/1.1" + CRLF
        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
        + "Content-Id: BBB" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56" + CRLF
        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-Id: 1" + CRLF
        + CRLF
        + "POST Employees HTTP/1.1" + CRLF
        + "Content-type: application/octet-stream" + CRLF
        + CRLF
        + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + CRLF
        + CRLF
        + "--changeset_f980-1cb6-94dd" + CRLF
        + MIME_HEADERS
        + "Content-ID: 2" + CRLF
        + CRLF
        + "PUT $1/EmployeeName HTTP/1.1" + CRLF
        + "Content-Type: application/json;odata=verbose" + CRLF
        + CRLF
        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
        + "--changeset_f980-1cb6-94dd--" + CRLF
        + CRLF
        + "This is an epilog and must be ignored" + CRLF
        + CRLF
        + CRLF
        + "----1242"
        + CRLF
        + "--batch_8194-cf13-1f56--"
        + CRLF
        + "This is an epilog and must be ignored" + CRLF
        + CRLF
        + CRLF
        + "----1242";
    final List<BatchRequestPart> batchRequestParts = parse(batch);

    assertNotNull(batchRequestParts);
    assertEquals(2, batchRequestParts.size());

    BatchRequestPart getRequestPart = batchRequestParts.get(0);
    assertEquals(1, getRequestPart.getRequests().size());
    ODataRequest getRequest = getRequestPart.getRequests().get(0);
    assertEquals(HttpMethod.GET, getRequest.getMethod());

    BatchRequestPart changeSetPart = batchRequestParts.get(1);
    assertEquals(2, changeSetPart.getRequests().size());
    assertEquals("/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA"
        + CRLF,
        IOUtils.toString(changeSetPart.getRequests().get(0).getBody()));
    assertEquals("{\"EmployeeName\":\"Peter Fall\"}",
        IOUtils.toString(changeSetPart.getRequests().get(1).getBody()));
  }

  @Test
  public void testLargeBatch() throws Exception {
    final InputStream in = readFile("/batchLarge.batch");
    parse(in);
  }

  @Test
  public void forbiddenHeaderAuthorization() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Authorization: Basic QWxhZdsdsddsduIHNlc2FtZQ==" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
  }

  @Test
  public void forbiddenHeaderExpect() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Expect: 100-continue" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
  }

  @Test
  public void forbiddenHeaderFrom() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "From: test@test.com" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
  }

  @Test
  public void forbiddenHeaderRange() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Range: 200-256" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
  }

  @Test
  public void forbiddenHeaderMaxForwards() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "Max-Forwards: 3" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
  }

  @Test
  public void forbiddenHeaderTE() throws Exception {
    final String batch = ""
        + "--batch_8194-cf13-1f56" + CRLF
        + MIME_HEADERS
        + CRLF
        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
        + "TE: deflate" + CRLF
        + CRLF
        + CRLF
        + "--batch_8194-cf13-1f56--";

    parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
  }

  private List<BatchRequestPart> parse(final InputStream in, final boolean isStrict) throws Exception {
    final BatchParser parser = new BatchParser();
    final BatchOptions options = BatchOptions.with().isStrict(isStrict).rawBaseUri(SERVICE_ROOT).build();
    final List<BatchRequestPart> batchRequestParts =
        parser.parseBatchRequest(in, BOUNDARY, options);

    assertNotNull(batchRequestParts);

    return batchRequestParts;
  }

  private List<BatchRequestPart> parse(final InputStream in) throws Exception {
    return parse(in, true);
  }

  private List<BatchRequestPart> parse(final String batch) throws Exception {
    return parse(batch, true);
  }

  private List<BatchRequestPart> parse(final String batch, final boolean isStrict) throws Exception {
    return parse(IOUtils.toInputStream(batch), isStrict);
  }

  private void parseInvalidBatchBody(final String batch, final MessageKeys key, final boolean isStrict)
      throws Exception {
    final BatchParser parser = new BatchParser();
    final BatchOptions options = BatchOptions.with().isStrict(isStrict).rawBaseUri(SERVICE_ROOT).build();
    try {
      parser.parseBatchRequest(IOUtils.toInputStream(batch), BOUNDARY, options);
      fail("No exception thrown. Expect: " + key.toString());
    } catch (BatchDeserializerException e) {
      assertMessageKey(e, key);
    }
  }

  private void parseInvalidBatchBody(final String batch, final MessageKeys key) throws Exception {
    parseInvalidBatchBody(batch, key, true);
  }

  private void assertMessageKey(final BatchDeserializerException e, final MessageKeys key) {
    assertEquals(key, e.getMessageKey());
  }

  private InputStream readFile(final String fileName) throws Exception {
    final InputStream in = ClassLoader.class.getResourceAsStream(fileName);
    if (in == null) {
      throw new IOException("Requested file '" + fileName + "' was not found.");
    }
    return in;
  }
}


text:
import Validator from '../Validator';
import { isNumeric, isString, isArray } from '../internal/utils';

Validator.registerRule('max', (value: any, { max }: { max: number }) => {
  if (isNumeric(value)) {
    return parseFloat(<any>value) <= max;
  } else if (isString(value) || isArray(value)) {
    return value.length <= max;
  } else {
    return false;
  }
}, {
  mapArgsToParams: (max: number) => ({ max }),
});


text:
-- ===============================================
-- Author:		Stephen Quin
-- Create date: 05/10/2012
-- Description:	Adds a new telesales campaign type
-- ===============================================
CREATE PROCEDURE [dbo].[h3giAddTelesalesCampaignType]
	@campaignType VARCHAR(10)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    IF NOT EXISTS (SELECT * FROM h3giTelesalesCampaignType WHERE campaignType = @campaignType)
    BEGIN
		INSERT INTO h3giTelesalesCampaignType
		VALUES (@campaignType)
    END

END

GRANT EXECUTE ON h3giAddTelesalesCampaignType TO b4nuser
GO


text:
package io.crossbar.autobahn.wamp.messages;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.crossbar.autobahn.wamp.exceptions.ProtocolError;
import io.crossbar.autobahn.wamp.interfaces.IMessage;
import io.crossbar.autobahn.wamp.utils.MessageUtil;

import static io.crossbar.autobahn.wamp.utils.Shortcuts.getOrDefault;

public class Event implements IMessage {

    public static final int MESSAGE_TYPE = 36;

    public final long subscription;
    public final long publication;
    public final String topic;
    public final boolean retained;
    public final List<Object> args;
    public final Map<String, Object> kwargs;

    public Event(long subscription, long publication, String topic, boolean retained, List<Object> args, Map<String, Object> kwargs) {
        this.subscription = subscription;
        this.publication = publication;
        this.topic = topic;
        this.retained = retained;
        this.args = args;
        this.kwargs = kwargs;
    }

    public static Event parse(List<Object> wmsg) {
        MessageUtil.validateMessage(wmsg, MESSAGE_TYPE, "EVENT", 3, 6);
        long subscription = MessageUtil.parseLong(wmsg.get(1));
        long publication = MessageUtil.parseLong(wmsg.get(2));

        Map<String, Object> details = (Map<String, Object>) wmsg.get(3);
        String topic = (String)details.get("topic");
        boolean retained = getOrDefault(details, "retained", false);

        List<Object> args = null;
        if (wmsg.size() > 4) {
            if (wmsg.get(4) instanceof byte[]) {
                throw new ProtocolError("Binary payload not supported");
            }
            args = (List<Object>) wmsg.get(4);
        }
        Map<String, Object> kwargs = null;
        if (wmsg.size() > 5) {
            kwargs = (Map<String, Object>) wmsg.get(5);
        }

        return new Event(subscription, publication, topic, retained, args, kwargs);
    }

    @Override
    public List<Object> marshal() {
        List<Object> marshaled = new ArrayList<>();
        marshaled.add(MESSAGE_TYPE);
        marshaled.add(subscription);
        marshaled.add(publication);
        Map<String, Object> details = new HashMap<>();
        if (topic != null) {
            details.put("topic", topic);
        }
        if (retained) {
            details.put("retained", retained);
        }
        marshaled.add(details);
        if (kwargs != null) {
            if (args == null) {
                // Empty args.
                marshaled.add(Collections.emptyList());
            } else {
                marshaled.add(args);
            }
            marshaled.add(kwargs);
        } else if (args != null) {
            marshaled.add(args);
        }
        return marshaled;
    }
}


text:
package com.wrq.rearranger.settings;

import com.wrq.rearranger.RearrangerActionHandler;
import com.wrq.rearranger.settings.attributeGroups.RegexUtil;
import com.wrq.rearranger.configuration.IntTextField;
import com.wrq.rearranger.util.CommentUtil;
import com.wrq.rearranger.util.Constraints;
import org.jdom.Attribute;
import org.jdom.Element;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Implements routines for handling comment fill string expansion.
 */
public class CommentFillString
{
    private String fillString;                                // replicate in place of %FS%
    private boolean useProjectWidthForFill;
    private int fillWidth;

    public CommentFillString()
    {
        fillString = "";
        useProjectWidthForFill = true;
        fillWidth = 0;
    }

    public final String getExpandedCommentText(String commentText)
    {
        int width = useProjectWidthForFill ? RearrangerActionHandler.getRightMargin() : fillWidth;
        int tabSize = RearrangerActionHandler.getTabSize();
        return CommentUtil.expandFill(commentText, width, tabSize, fillString);
    }

    public String getFillString()
    {
        return fillString;
    }

    public void setFillString(String fillString)
    {
        this.fillString = fillString;
    }

    public boolean isUseProjectWidthForFill()
    {
        return useProjectWidthForFill;
    }

    public void setUseProjectWidthForFill(boolean useProjectWidthForFill)
    {
        this.useProjectWidthForFill = useProjectWidthForFill;
    }

    public int getFillWidth()
    {
        return fillWidth;
    }

    public void setFillWidth(int fillWidth)
    {
        this.fillWidth = fillWidth;
    }

    public final boolean equals(final Object object)
    {
        if (!(object instanceof CommentFillString)) return false;
        final CommentFillString c = (CommentFillString) object;
        return fillString.equals(c.fillString)                      &&
               useProjectWidthForFill  == c.useProjectWidthForFill  &&
               fillWidth               == c.fillWidth                 ;
    }

    public final CommentFillString deepCopy()
    {
        final CommentFillString comment = new CommentFillString();
        comment.fillString              = fillString;
        comment.useProjectWidthForFill  = useProjectWidthForFill;
        comment.fillWidth               = fillWidth;
        return comment;
    }

    public static CommentFillString readExternal(final Element item)
    {
        final CommentFillString   result = new CommentFillString();
            Attribute fillAttr = RearrangerSettings.getAttribute(item, "fillString");
            if (fillAttr == null) result.fillString = "";
            else {
                String fill = fillAttr.getValue();
                result.fillString = CommentRule.unescape(fill);
            }
        result.useProjectWidthForFill = RearrangerSettings.getBooleanAttribute(item, "useProjectWidthForFill", true);
        result.fillWidth              = RearrangerSettings.getIntAttribute(item, "fillWidth", 0);
        return result;
    }

    public final void writeExternal(final Element me)
    {
        me.setAttribute("fillString"             , CommentRule.escape(fillString)          );
        me.setAttribute("useProjectWidthForFill" , "" + useProjectWidthForFill );
        me.setAttribute("fillWidth"              , "" + fillWidth              );
    }

    public final JPanel getCommentFillStringPanel()
    {
        final JPanel cfsPanel = new JPanel(new GridBagLayout());
        final Constraints constraints = new Constraints(GridBagConstraints.NORTHWEST);
        constraints.fill       = GridBagConstraints.BOTH;
        constraints.insets     = new Insets(4, 4, 4, 0);
        constraints.newRow();
        final JLabel fillStringLabel = new JLabel("Fill string:");
        fillStringLabel.setToolTipText("Occurrences of %FS% in the comment separator text will be replaced with equal \n" +
                                       "amounts of the fill string, replicated to make the comment end at the specified column");
        cfsPanel.add(fillStringLabel, constraints.firstCol());
        final JTextField fillString = new JTextField(this.fillString);
        cfsPanel.add(fillString, constraints.weightedLastCol());
        constraints.newRow();
        final JCheckBox useProjectWidthBox = new JCheckBox("Use project right margin as fill width");
        useProjectWidthBox.setSelected(useProjectWidthForFill);
        cfsPanel.add(useProjectWidthBox, constraints.weightedLastCol());
        constraints.lastRow();
        constraints.insets = new Insets(4, 15, 4, 4);
        final JLabel fillWidthLabel = new JLabel("Fill width:");
        cfsPanel.add(fillWidthLabel, constraints.firstCol());
        final IntTextField fillWidthField = new IntTextField(
                new IntTextField.IGetSet()
                {
                    public int get() { return fillWidth; }
                    public void set(int value) { fillWidth = value; }
                },
                0,
                999
        );
        cfsPanel.add(fillWidthField, constraints.nextCol());
        cfsPanel.add(new JLabel(), constraints.weightedLastCol());
        fillWidthLabel.setEnabled(!useProjectWidthForFill);
        fillWidthField.setEnabled(!useProjectWidthForFill);
        fillString.getDocument().addDocumentListener(new DocumentListener()
        {
            public void insertUpdate(DocumentEvent e)
            {
                setFillString(fillString.getText());
            }

            public void removeUpdate(DocumentEvent e)
            {
                setFillString(fillString.getText());
            }

            public void changedUpdate(DocumentEvent e)
            {
                setFillString(fillString.getText());
            }
        });
        useProjectWidthBox.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                useProjectWidthForFill = useProjectWidthBox.isSelected();
                fillWidthLabel.setEnabled(!useProjectWidthForFill);
                fillWidthField.setEnabled(!useProjectWidthForFill);
            }
        });
        return cfsPanel;
    }

    /**
      * Returns a regular expression that will match the fill string.
      */
     public String getFillStringPattern()
     {
         String fs = fillString;
         if (fs.length() == 0) fs = " ";
         final int length = fs.length();
         StringBuffer sb = new StringBuffer(length * (length + 1) / 2 + length * 3);
         sb.append('(');
         sb.append(RegexUtil.escape(fs));
         sb.append(")*");
         if (length > 1) {
             sb.append('(');
             for (int i = length - 1; i > 0; i--)
             {
                 sb.append(RegexUtil.escape(fs.substring(0, i)));
                 sb.append(i <= 1 ? ")?" : "|");
             }
         }
         return sb.toString();
     }

}


text:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>dust2</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="dust.html" title="dust" />
    <link rel="next" href="else.html" title="else" />

          dust2

          Prev
          Orchestra Opcodes and Operators
           Next

          dust2

dust2 —
      Random impulses.

Description

      Generates random impulses from -1 to 1.

Syntax

ares dust2 kamp, kdensity

kres dust2 kamp, kdensity

Performance

      kamp -- amplitude.

      kdensity -- average number of impulses per second.

Examples

      Here is an example of the dust2 opcode. It uses the file dust2.csd.

            Example 230. Example of the dust2 opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac     ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o oscil.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

instr 1

kdens expon 2, p3, 20000
aout  dust2 0.5, kdens
outs  aout, aout

endin
</CsInstruments>
<CsScore>
i1 0 10
e
</CsScore>
</CsoundSynthesizer>

See Also

      dust
      gausstrig
      mpulse

Credits

            Based on James McCartney's Dust2 (SuperCollider)

            Author: Tito Latini

            January 2012

New in Csound version 5.16

          Prev

            Up

           Next

          dust

            Home

           else


text:
<?xml version="1.0" encoding="utf-8"?>
<!--

-->
<resources>

	<string name="test_preference_key">com.albedinsky.android.preference.test.PREFERENCE.Key</string>
	<string name="test_preference_key_empty"/>

</resources>


text:
namespace net {
namespace {

TEST(IPAddressStructTraitsTest, Ipv4) {
  IPAddress original(1, 2, 3, 4);

  IPAddress deserialized;
  EXPECT_TRUE(mojo::test::SerializeAndDeserialize<network::mojom::IPAddress>(
      original, deserialized));

  EXPECT_EQ(original, deserialized);
}

TEST(IPAddressStructTraitsTest, Ipv6) {
  IPAddress original(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);

  IPAddress deserialized;
  EXPECT_TRUE(mojo::test::SerializeAndDeserialize<network::mojom::IPAddress>(
      original, deserialized));

  EXPECT_EQ(original, deserialized);
}

// Serialization/deserialization not expected to work for invalid addresses,
// e.g. an address with 5 octets.
TEST(IPAddressStructTraitsTest, InvalidAddress) {
  uint8_t bad_address_bytes[] = {1, 2, 3, 4, 5};
  IPAddress original(bad_address_bytes);
  ASSERT_FALSE(original.IsValid());

  IPAddress deserialized;
  EXPECT_FALSE(mojo::test::SerializeAndDeserialize<network::mojom::IPAddress>(
      original, deserialized));
}

}  // namespace
}  // namespace net