org.phoebus.applications.alarm.model.AlarmTreePath Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2010 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.phoebus.applications.alarm.model;
import java.util.ArrayList;
import java.util.List;
/** Helper for handling the path names of alarm tree elements.
* Path looks like "/root/area/system/subsystem/pv_name".
* @author Kay Kasemir
*/
@SuppressWarnings("nls")
public class AlarmTreePath
{
/** Separator used to create path names to items in the alarm tree */
final public static String PATH_SEP = "/";
/** @param path String to test
* @return true
if a string is a path or just a plain name
*/
public static boolean isPath(final String path)
{
return path.startsWith(PATH_SEP);
}
/** Build path name
* @param path Parent path or null
when starting at root
* @param item Name of item at end of path
* @return Full path name to item
*/
public static String makePath(final String path, String item)
{
final StringBuilder result = new StringBuilder();
if (path != null)
{
if (! isPath(path))
result.append(PATH_SEP);
// Skip path it it's only '/'
if (!PATH_SEP.equals(path))
result.append(path);
}
result.append(PATH_SEP);
if (item != null && !item.isEmpty())
{
// If item already starts with '/', skip it
if (item.startsWith(PATH_SEP))
item = item.substring(1);
// Escape any path-seps inside item with backslashes
result.append(item.replace(PATH_SEP, "\\/"));
}
return result.toString();
}
/** Build path name
* @param path_items Path elements
* @param length_to_use How many elements of path_items to use,
* 0 ... path_items.length-1
* @return Full path name to item
*/
public static String makePath(final String path_items[], int length_to_use)
{
final int N = Math.min(path_items.length, length_to_use);
final StringBuilder path = new StringBuilder();
for (int i=0; i items = new ArrayList<>();
for (String item : path.split("(?
© 2015 - 2024 Weber Informatics LLC | Privacy Policy