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

com.intellij.util.xml.GenericValueUtil Maven / Gradle / Ivy

Go to download

A packaging of the IntelliJ Community Edition dom-openapi library. This is release number 1 of trunk branch 142.

The newest version!
/*
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * 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 com.intellij.util.xml;

import com.intellij.openapi.util.Comparing;
import com.intellij.util.NullableFunction;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

/**
 * @author Gregory.Shrago
 */
public class GenericValueUtil {
  private GenericValueUtil() {
  }

  public static NullableFunction STRING_VALUE = new NullableFunction() {
    @Override
    public String fun(final GenericValue genericValue) {
      return genericValue.getStringValue();
    }
  };
  public static NullableFunction OBJECT_VALUE = new NullableFunction() {
    @Override
    public Object fun(final GenericValue genericValue) {
      return genericValue.getValue();
    }
  };


  public static boolean containsString(final Collection> collection, String value) {
    for (GenericValue o : collection) {
      if (Comparing.equal(value, o.getStringValue())) return true;
    }
    return false;
  }

  public static  boolean containsValue(final Collection> collection, T value) {
    for (GenericValue o : collection) {
      if (Comparing.equal(value, o.getValue())) return true;
    }
    return false;
  }

  @NotNull
  public static  Collection getValueCollection(final Collection> collection, Collection result) {
    for (GenericValue o : collection) {
      ContainerUtil.addIfNotNull(o.getValue(), result);
    }
    return result;
  }

  @NotNull
  public static Collection getStringCollection(final Collection collection, Collection result) {
    for (GenericValue o : collection) {
      ContainerUtil.addIfNotNull(o.getStringValue(), result);
    }
    return result;
  }

  @NotNull
  public static Collection getClassStringCollection(final Collection collection, Collection result) {
    for (GenericValue o : collection) {
      final String value = o.getStringValue();
      if (value != null) {
        result.add(value.replace('$', '.'));
      }
    }
    return result;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy