<commit_before>
//(c) Copyright 2005, <NAME>.  All rights reserved.

package com.vzome.core.editor;

import java.util.Iterator;

import org.w3c.dom.Element;

import com.vzome.core.commands.XmlSaveFormat;
import com.vzome.core.commands.Command.Failure;
import com.vzome.core.construction.Point;
import com.vzome.core.construction.Segment;
import com.vzome.core.construction.SegmentJoiningPoints;
import com.vzome.core.model.Connector;
import com.vzome.core.model.Manifestation;
import com.vzome.core.model.RealizedModel;

public class JoinPoints extends ChangeConstructions
{
    public JoinPoints( Selection selection, RealizedModel realized, boolean groupInSelection, boolean closedLoop )
    {
        super( selection, realized, groupInSelection );
        this .closedLoop = closedLoop;
    }

    protected void getXmlAttributes( Element element )
    {
        if ( ! closedLoop )
            element .setAttribute( "closedLoop", "false" );
    }

    protected void setXmlAttributes( Element xml, XmlSaveFormat format ) throws Failure
    {
        String attr = xml .getAttribute( "closedLoop" );
        if ( attr != null )
            closedLoop = Boolean .valueOf( attr ) .booleanValue();
    }

    public void perform() throws Failure
    {
        Point firstPoint = null, lastPoint = null;
        for ( Iterator mans = mSelection .iterator(); mans .hasNext(); ) {
            Manifestation man = (Manifestation) mans .next();
            unselect( man );
            if ( man instanceof Connector )
            {
                Point nextPoint = (Point) ((Connector) man) .getConstructions() .next();
                if ( lastPoint != null )
                {
                    Segment segment = new SegmentJoiningPoints( lastPoint, nextPoint );
                    addConstruction( segment );
                    select( manifestConstruction( segment ) );
                }
                else
                    firstPoint = nextPoint;<commit_msg>fixes #5: DOM returns "" for a missing attribute, whereas XOM used to return null<commit_after>
//(c) Copyright 2005, <NAME>.  All rights reserved.

package com.vzome.core.editor;

import java.util.Iterator;

import org.w3c.dom.Element;

import com.vzome.core.commands.XmlSaveFormat;
import com.vzome.core.commands.Command.Failure;
import com.vzome.core.construction.Point;
import com.vzome.core.construction.Segment;
import com.vzome.core.construction.SegmentJoiningPoints;
import com.vzome.core.model.Connector;
import com.vzome.core.model.Manifestation;
import com.vzome.core.model.RealizedModel;

public class JoinPoints extends ChangeConstructions
{
    public JoinPoints( Selection selection, RealizedModel realized, boolean groupInSelection, boolean closedLoop )
    {
        super( selection, realized, groupInSelection );
        this .closedLoop = closedLoop;
    }

    protected void getXmlAttributes( Element element )
    {
        if ( ! closedLoop )
            element .setAttribute( "closedLoop", "false" );
    }

    protected void setXmlAttributes( Element xml, XmlSaveFormat format ) throws Failure
    {
        String attr = xml .getAttribute( "closedLoop" );
        if ( attr != null && ! attr.isEmpty() )
            closedLoop = Boolean .valueOf( attr ) .booleanValue();
    }

    public void perform() throws Failure
    {
        Point firstPoint = null, lastPoint = null;
        for ( Iterator mans = mSelection .iterator(); mans .hasNext(); ) {
            Manifestation man = (Manifestation) mans .next();
            unselect( man );
            if ( man instanceof Connector )
            {
                Point nextPoint = (Point) ((Connector) man) .getConstructions() .next();
                if ( lastPoint != null )
                {
                    Segment segment = new SegmentJoiningPoints( lastPoint, nextPoint );
                    addConstruction( segment );
                    select( manifestConstruction( segment ) );
                }
                else
                    firstPoint = nextPoint;
{'fraction_non_alphanumeric': 0.09558093346573981, 'fraction_numerical': 0.002730883813306852, 'mean_word_length': 2.423109600679694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2975179', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1048, 'n_words': 287}