org.joda.beans.impl.direct.DirectMetaPropertyMap Maven / Gradle / Ivy
/*
* Copyright 2001-present Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.beans.impl.direct;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.joda.beans.MetaProperty;
/**
* A map of name to meta-property designed for use by the code generator.
*
* This meta-property map implementation is designed primarily for code-generation.
* It stores a reference to the meta-bean and the meta-properties.
* The meta-properties are accessed using {@link DirectMetaBean#metaPropertyGet(String)}.
*
* This class is immutable and thread-safe.
*/
@SuppressWarnings("rawtypes")
public final class DirectMetaPropertyMap implements Map> {
/** The meta-bean. */
private final DirectMetaBean metaBean;
/** The property names. */
private final Set keys;
/** The meta-properties. */
private final Collection> values;
/** The map entries. */
private final Set>> entries;
/**
* Constructor.
*
* @param metaBean the meta-bean, not null
* @param parent the superclass parent, may be null
* @param propertyNames the property names, not null
*/
@SuppressWarnings("unchecked")
public DirectMetaPropertyMap(final DirectMetaBean metaBean, DirectMetaPropertyMap parent, String... propertyNames) {
if (metaBean == null) {
throw new NullPointerException("MetaBean must not be null");
}
this.metaBean = metaBean;
int parentSize = 0;
final Entry>[] metaProperties;
if (parent != null) {
parentSize = parent.size();
metaProperties = Arrays.copyOf(((Entries) parent.entries).metaProperties, parentSize + propertyNames.length);
} else {
metaProperties = new Entry[propertyNames.length];
}
for (int i = 0; i < propertyNames.length; i++) {
metaProperties[i + parentSize] = new AbstractMap.SimpleImmutableEntry(propertyNames[i], metaBean.metaPropertyGet(propertyNames[i]));
}
keys = new Keys(metaProperties);
values = new Values(metaProperties);
entries = new Entries(metaProperties);
}
//-----------------------------------------------------------------------
@Override
public int size() {
return keys.size();
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@SuppressWarnings("unchecked")
@Override
public MetaProperty