All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yangcentral.yangkit.model.impl.stmt.KeyImpl Maven / Gradle / Ivy

There is a newer version: 1.4.5
Show newest version
package org.yangcentral.yangkit.model.impl.stmt;

import org.yangcentral.yangkit.base.YangBuiltinKeyword;
import org.yangcentral.yangkit.common.api.QName;

import org.yangcentral.yangkit.model.api.stmt.Key;
import org.yangcentral.yangkit.model.api.stmt.Leaf;

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

public class KeyImpl extends YangBuiltInStatementImpl implements Key {
   private List keyNodes = new ArrayList<>();

   public KeyImpl(String argStr) {
      super(argStr);
   }

   public List getkeyNodes() {
      return Collections.unmodifiableList(this.keyNodes);
   }

   public boolean addKeyNode(Leaf keyNode) {
      Iterator leafIterator = this.keyNodes.iterator();

      Leaf key;
      do {
         if (!leafIterator.hasNext()) {
            return this.keyNodes.add(keyNode);
         }

         key = leafIterator.next();
      } while(!key.getArgStr().equals(keyNode.getArgStr()));

      return false;
   }



   public Leaf getKeyNode(QName identifier) {
      Iterator leafIterator = this.keyNodes.iterator();

      Leaf key;
      do {
         if (!leafIterator.hasNext()) {
            return null;
         }

         key = leafIterator.next();
      } while(!key.getIdentifier().equals(identifier));

      return key;
   }

   @Override
   public Leaf removeKeyNode(QName identifier) {
      for(Leaf node:keyNodes){
         if(node.getIdentifier().equals(identifier)){
            keyNodes.remove(node);
            return node;
         }
      }
      return null;
   }

   @Override
   public void removeKeyNodes() {
      this.keyNodes.clear();
   }

   public QName getYangKeyword() {
      return YangBuiltinKeyword.KEY.getQName();
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy