代码段1

public interface GraphObject {
	public long getId();
	public String getType();

	public Iterable<String> getPropertyKeys(String propertyView);
	public void setProperty(String key, Object value) throws FrameworkException;
	public Object getProperty(String key);
	public String getStringProperty(String key);
	public Date getDateProperty(String key);
	public void removeProperty(String key) throws FrameworkException;
	public PropertyKey getDefaultSortKey();
	public String getDefaultSortOrder();
	public abstract boolean isValid(ErrorBuffer errorBuffer);	
}

 

public class PropertyValueComparator implements Comparator<GraphObject> {

	public enum Order {
		Ascending, Descending
	}

	private static final Logger logger = Logger.getLogger(PropertyValueComparator.class.getName());
	private PropertyKey propertyKey = null;
	private Order order = null;

	public PropertyValueComparator(PropertyKey propertyKey) {
		this(propertyKey, Order.Ascending);
	}

	public PropertyValueComparator(PropertyKey propertyKey, Order order) {
		this.propertyKey = propertyKey;
		this.order = order;
	}

	@Override
	public int compare(GraphObject o1, GraphObject o2) {

		Object value1 = o1.getProperty(propertyKey.name());
		Object value2 = o2.getProperty(propertyKey.name());

		if(value1 != null && value2 != null) {
			if(value1 instanceof Comparable && value2 instanceof Comparable) {

				Comparable comp1 = (Comparable)value1;
				Comparable comp2 = (Comparable)value2;

				if(order.equals(Order.Ascending)) {
					
					return comp1.compareTo(comp2);

				} else if(order.equals(Order.Descending)){

					return comp2.compareTo(comp1);
				}

			} else {

				logger.log(Level.WARNING, "Cannot compare {0} to {1}!", new Object[] { value1.getClass().getName(), value2.getClass().getName() } );
			}

		} else {

			logger.log(Level.WARNING, "Cannot compare null values!");
		}

		return 0;
	}
}

public interface StatusInfo
{
    public Object getStatusProperty(String key);
}

 

public interface RunnableService extends Service

{

    public void startService();

    public void stopService();

    public boolean runOnStartup();

    public boolean isRunning();
}

 

public interface Delayed extends Comparable<Delayed>

{

     long getDelay(TimeUnit unit);
}

 

public abstract class DataContainer implements Serializable
{

    protected Map<String, Object> properties = new HashMap<String, Object>();

    /**
     * Estimated size, needed to calculate buffer size.
     * <p/>
     * Start with a reasonable size, say 1K
     */
    protected int estimatedSize = 1024;

    /**
     * Return the properties map
     *
     * @return
     */
    public Map<String, Object> getProperties()
    {
        return properties;
    }

    public int getEstimatedSize()
    {
        return estimatedSize;
    }

    // <editor-fold defaultstate="collapsed" desc="toString() method">

    /**
     * Implement standard toString() method
     */
    @Override
    public String toString()
    {
        StringBuilder out = new StringBuilder();

        List<String> props = new LinkedList<String>();

        for (String key : properties.keySet())
        {

            Object value = properties.get(key);
            String displayValue = "";

            if (value.getClass().isPrimitive())
            {
                displayValue = value.toString();
            }
            else if (value.getClass().isArray())
            {

                if (value instanceof byte[])
                {

                    displayValue = new String((byte[]) value);

                }
                else if (value instanceof char[])
                {

                    displayValue = new String((char[]) value);

                }
                else if (value instanceof double[])
                {

                    Double[] values = ArrayUtils.toObject((double[]) value);
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";

                }
                else if (value instanceof float[])
                {

                    Float[] values = ArrayUtils.toObject((float[]) value);
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";

                }
                else if (value instanceof short[])
                {

                    Short[] values = ArrayUtils.toObject((short[]) value);
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";

                }
                else if (value instanceof long[])
                {

                    Long[] values = ArrayUtils.toObject((long[]) value);
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";

                }
                else if (value instanceof int[])
                {

                    Integer[] values = ArrayUtils.toObject((int[]) value);
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";

                }
                else if (value instanceof boolean[])
                {

                    Boolean[] values = (Boolean[]) value;
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";

                }
                else if (value instanceof byte[])
                {

                    displayValue = new String((byte[]) value);

                }
                else
                {

                    Object[] values = (Object[]) value;
                    displayValue = "[ " + StringUtils.join(values, " , ") + " ]";
                }


            }
            else
            {
                displayValue = value.toString();
            }

            props.add("\"" + key + "\"" + " : " + "\"" + displayValue + "\"");

        }

        out.append("{ ").append(StringUtils.join(props.toArray(), " , ")).append(" }");

        return out.toString();
    }// </editor-fold>

}

 

public interface PropertyKey
{
    public String name();
    public int ordinal();
}

public enum Key implements PropertyKey

{

    propertyName, filterExpression
}

 

 public enum Permission implements PropertyKey {
  allowed, denied, read, showTree, write, execute, createNode, deleteNode, editProperties, addRelationship, removeRelationship, accessControl;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值