dap4/d4core/src/main/java/dap4/core/dmr/DapGroup.java
public void
    addDecl(DapNode newdecl)
            throws DapException
    {
        DapSort newsort = newdecl.getSort();
        String newname = newdecl.getShortName();
        boolean suppress = false;
        // Look for name conflicts (ignore anonymous dimensions)
        if(newsort != DapSort.DIMENSION || newname != null) {
            for(DapNode decl : decls) {
                if(newsort == decl.getSort()
                        && newname.equals(decl.getShortName()))
                    throw new DapException("DapGroup: attempt to add duplicate decl: " + newname);
            }
        } else { // Anonymous
            DapDimension anon = (DapDimension) newdecl;
            assert (newsort == DapSort.DIMENSION && newname == null);
            // Search for matching anonymous dimension
            boolean found = false;
            for(DapDimension dim : dimensions) {
                if(!dim.isShared() && dim.getSize() == anon.getSize()) {
                    found = true;
                    break;
                }
            }
            // Define the anondecl in root group
            if(!found && !isTopLevel()) getDataset().addDecl(anon);
            suppress = found || !isTopLevel();
        }
        if(!suppress) {
            decls.add(newdecl);
            newdecl.setParent(this); // Cross link
        }
        switch (newdecl.getSort()) {
        case ATTRIBUTE:
        case ATTRIBUTESET:
        case OTHERXML:
            super.addAttribute((DapAttribute) newdecl);
            break;
        case DIMENSION:
            if(!suppress)
                dimensions.add((DapDimension) newdecl);
            break;
        case ENUMERATION:
            enums.add((DapEnumeration) newdecl);
            break;
        case ATOMICTYPE:
            break; // do nothing
        case STRUCTURE:
        case SEQUENCE:
            compounds.add((DapStructure)newdecl);
            break;
        case VARIABLE:
            variables.add((DapVariable) newdecl);
            break;
        case GROUP:
        case DATASET:
            if(this != (DapGroup) newdecl)
                groups.add((DapGroup) newdecl);
            break;
        default:
            throw new ClassCastException(newdecl.getShortName());
        }
    }
public void
    addDecl(DapNode newdecl)
            throws DapException
    {
        DapSort newsort = newdecl.getSort();
        String newname = newdecl.getShortName();
        boolean suppress = false;
        // Look for name conflicts (ignore anonymous dimensions)
        if(newsort != DapSort.DIMENSION || newname != null) {
            for(DapNode decl : decls) {
                if(newsort == decl.getSort()
                        && newname.equals(decl.getShortName()))
                    throw new DapException("DapGroup: attempt to add duplicate decl: " + newname);
            }
        } else { // Anonymous
            DapDimension anon = (DapDimension) newdecl;
            assert (newsort == DapSort.DIMENSION && newname == null);
            // Search for matching anonymous dimension
            boolean found = false;
            for(DapDimension dim : dimensions) {
                if(!dim.isShared() && dim.getSize() == anon.getSize()) {
                    found = true;
                    break;
                }
            }
            // Define the anondecl in root group
            if(!found && !isTopLevel()) getDataset().addDecl(anon);
            suppress = found || !isTopLevel();
        }
        if(!suppress) {
            decls.add(newdecl);
            newdecl.setParent(this); // Cross link
        }
        switch (newdecl.getSort()) {
        case ATTRIBUTE:
        case ATTRIBUTESET:
        case OTHERXML:
            super.addAttribute((DapAttribute) newdecl);
            break;
        case DIMENSION:
            if(!suppress)
                dimensions.add((DapDimension) newdecl);
            break;
        case ENUMERATION:
            enums.add((DapEnumeration) newdecl);
            break;
        case ATOMICTYPE:
            break; // do nothing
        case STRUCTURE:
        case SEQUENCE:
            compounds.add((DapStructure)newdecl);
            break;
        case VARIABLE:
            variables.add((DapVariable) newdecl);
            break;
        case GROUP:
        case DATASET:
            if(this != (DapGroup) newdecl)
                groups.add((DapGroup) newdecl);
            break;
        default:
            throw new ClassCastException(newdecl.getShortName());
        }
    }
public void addDecl ( DapNode newdecl ) throws DapException { DapSort newsort = newdecl . getSort ( ) ; String newname = newdecl . getShortName ( ) ; boolean suppress = false ; // Look for name conflicts (ignore anonymous dimensions) if ( newsort != DapSort . DIMENSION || newname != null ) { for ( DapNode decl : decls ) { if ( newsort == decl . getSort ( ) && newname . equals ( decl . getShortName ( ) ) ) throw new DapException ( "DapGroup: attempt to add duplicate decl: " + newname ) ; } } else { // Anonymous DapDimension anon = ( DapDimension ) newdecl ; assert ( newsort == DapSort . DIMENSION && newname == null ) ; // Search for matching anonymous dimension boolean found = false ; for ( DapDimension dim : dimensions ) { if ( ! dim . isShared ( ) && dim . getSize ( ) == anon . getSize ( ) ) { found = true ; break ; } } // Define the anondecl in root group if ( ! found && ! isTopLevel ( ) ) getDataset ( ) . addDecl ( anon ) ; suppress = found || ! isTopLevel ( ) ; } if ( ! suppress ) { decls . add ( newdecl ) ; newdecl . setParent ( this ) ; // Cross link } switch ( newdecl . getSort ( ) ) { case ATTRIBUTE : case ATTRIBUTESET : case OTHERXML : super . addAttribute ( ( DapAttribute ) newdecl ) ; break ; case DIMENSION : if ( ! suppress ) dimensions . add ( ( DapDimension ) newdecl ) ; break ; case ENUMERATION : enums . add ( ( DapEnumeration ) newdecl ) ; break ; case ATOMICTYPE : break ; // do nothing case STRUCTURE : case SEQUENCE : compounds . add ( ( DapStructure ) newdecl ) ; break ; case VARIABLE : variables . add ( ( DapVariable ) newdecl ) ; break ; case GROUP : case DATASET : if ( this != ( DapGroup ) newdecl ) groups . add ( ( DapGroup ) newdecl ) ; break ; default : throw new ClassCastException ( newdecl . getShortName ( ) ) ; } }
Add single declaration
Add single declaration