alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lift Framework example source code file (ValueHolder.scala)

This example Lift Framework source code file (ValueHolder.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lift Framework tags/keywords

liftvalue, psettablevalueholder, pvalueholder, pvalueholder, settable, settablevalueholder, t, t, use, valueholder, valueholder, valuetype, valuetype

The Lift Framework ValueHolder.scala source code

/*
 * Copyright 2009-2011 WorldWide Conferencing, LLC
 *
 * 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 net.liftweb 
package util 

trait ValueHolder {
  type ValueType

  /**
   * Get the value.  Use get.
   *
   * @deprecated
   */
  @deprecated("Use get")
  def is: ValueType

  /**
   * get the value
   */
  def get: ValueType
}

/**
 * A value that can be set
 */
trait Settable extends ValueHolder {
  def set(in: ValueType): ValueType

  /**
   * Perform an atomic update of this Settable.
   * The current value is passed to the function and the ValueHolder
   * is set to the result of the function.  This is enclosed in the
   * performAtomicOperation method which will, by default, synchronize
   * this instance
   */
  def atomicUpdate(f: ValueType => ValueType): ValueType =
    performAtomicOperation(set(f(get)))

  /**
   * Perform an atomic operation on the Settable. By default
   * synchronizes the instance, but it could use other mechanisms
   */
  def performAtomicOperation[T](f: => T): T = synchronized {
    f
  }
}

trait SettableValueHolder extends Settable

trait PValueHolder[T] extends ValueHolder {
 type ValueType = T
}

object PValueHolder {
  implicit def tToVHT[T](in: T): PValueHolder[T] = new PValueHolder[T] {def is = in; def get = is}
  def apply[T](in: T) = tToVHT(in)
}

object ValueHolder {
  implicit def tToVHT[T](in: T): ValueHolder = new PValueHolder[T] {def is = in; def get = is}
  def apply[T](in: T) = tToVHT(in)
}

trait PSettableValueHolder[T] extends PValueHolder[T] with SettableValueHolder

/**
 * Kinda like a JavaBean property.  It's something that can
 * be set and retrieved
 */
trait LiftValue[T] extends PSettableValueHolder[T] {
  def is: T = get
}

Other Lift Framework examples (source code examples)

Here is a short list of links related to this Lift Framework ValueHolder.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.