PropertyTokenizer.java

  1. /*
  2.  *    Copyright 2009-2021 the original author or authors.
  3.  *
  4.  *    Licensed under the Apache License, Version 2.0 (the "License");
  5.  *    you may not use this file except in compliance with the License.
  6.  *    You may obtain a copy of the License at
  7.  *
  8.  *       http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  *    Unless required by applicable law or agreed to in writing, software
  11.  *    distributed under the License is distributed on an "AS IS" BASIS,
  12.  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  *    See the License for the specific language governing permissions and
  14.  *    limitations under the License.
  15.  */
  16. package org.apache.ibatis.reflection.property;

  17. import java.util.Iterator;

  18. /**
  19.  * @author Clinton Begin
  20.  */
  21. public class PropertyTokenizer implements Iterator<PropertyTokenizer> {
  22.   private String name;
  23.   private final String indexedName;
  24.   private String index;
  25.   private final String children;

  26.   public PropertyTokenizer(String fullname) {
  27.     int delim = fullname.indexOf('.');
  28.     if (delim > -1) {
  29.       name = fullname.substring(0, delim);
  30.       children = fullname.substring(delim + 1);
  31.     } else {
  32.       name = fullname;
  33.       children = null;
  34.     }
  35.     indexedName = name;
  36.     delim = name.indexOf('[');
  37.     if (delim > -1) {
  38.       index = name.substring(delim + 1, name.length() - 1);
  39.       name = name.substring(0, delim);
  40.     }
  41.   }

  42.   public String getName() {
  43.     return name;
  44.   }

  45.   public String getIndex() {
  46.     return index;
  47.   }

  48.   public String getIndexedName() {
  49.     return indexedName;
  50.   }

  51.   public String getChildren() {
  52.     return children;
  53.   }

  54.   @Override
  55.   public boolean hasNext() {
  56.     return children != null;
  57.   }

  58.   @Override
  59.   public PropertyTokenizer next() {
  60.     return new PropertyTokenizer(children);
  61.   }

  62.   @Override
  63.   public void remove() {
  64.     throw new UnsupportedOperationException("Remove is not supported, as it has no meaning in the context of properties.");
  65.   }
  66. }