java.util.List Scala Examples

The following examples show how to use java.util.List. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: ItemAntimatter.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.quantum.items

import java.util.List

import cpw.mods.fml.relauncher.{Side, SideOnly}
import edx.core.{EDXCreativeTab, Reference}
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.util.IIcon
import net.minecraft.world.World
import resonantengine.lib.wrapper.CollectionWrapper._

class ItemAntimatter extends ItemCell
{

  private var iconGram: IIcon = null

  //Constructor
  this.setMaxDamage(0)
  this.setHasSubtypes(true)
  this.setUnlocalizedName(Reference.prefix + "antimatter")
  this.setTextureName(Reference.prefix + "antimatter")
  setCreativeTab(EDXCreativeTab)

  @SideOnly(Side.CLIENT) override def registerIcons(iconRegister: IIconRegister)
  {
    this.itemIcon = iconRegister.registerIcon(Reference.prefix + "antimatter_milligram")
    this.iconGram = iconRegister.registerIcon(Reference.prefix + "antimatter_gram")
  }

  override def getIconFromDamage(metadata: Int): IIcon =
  {
    if (metadata >= 1)
    {
      return this.iconGram
    }
    else
    {
      return this.itemIcon
    }
  }

  override def getSubItems(item: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
  {
    par3List.add(new ItemStack(item, 1, 0))
    par3List.add(new ItemStack(item, 1, 1))
  }

  override def getEntityLifespan(itemStack: ItemStack, world: World): Int =
  {
    return 160
  }
} 
Example 2
Source File: BrokerConverter.scala    From activemq-cli   with Apache License 2.0 5 votes vote down vote up
package activemq.cli.converter

import activemq.cli.ActiveMQCLI
import activemq.cli.domain.Broker

import java.util.List

import org.springframework.shell.core.Completion
import org.springframework.shell.core.Converter
import org.springframework.shell.core.MethodTarget
import org.springframework.stereotype.Component
import scala.collection.JavaConversions._

@Component
class BrokerConverter extends Converter[Broker] {

  @Override
  def convertFromText(text: String, requiredType: Class[_], optionContext: String): Broker = {
    new Broker(text, null, null, null, null, null) //scalastyle:ignore
  }

  @Override
  def supports(requiredType: Class[_], optionContext: String): Boolean = {
    classOf[Broker].isAssignableFrom(requiredType)
  }

  @Override
  def getAllPossibleValues(completions: List[Completion], requiredType: Class[_],
    existingData: String, optionContext: String, target: MethodTarget): Boolean = {
    ActiveMQCLI.Config.getObject("broker").foreach({ case (k: String, v) ⇒ completions.add(new Completion(k)) })
    true
  }
} 
Example 3
Source File: Public.scala    From recogito2   with Apache License 2.0 5 votes vote down vote up
package services.generated


import java.util.ArrayList
import java.util.Arrays
import java.util.List

import javax.annotation.Generated

import org.jooq.Sequence
import org.jooq.Table
import org.jooq.impl.SchemaImpl

import services.generated.tables.AuthorityFile
import services.generated.tables.Document
import services.generated.tables.DocumentFilepart
import services.generated.tables.DocumentPreferences
import services.generated.tables.FeatureToggle
import services.generated.tables.Folder
import services.generated.tables.FolderAssociation
import services.generated.tables.ServiceAnnouncement
import services.generated.tables.SharingPolicy
import services.generated.tables.Similarity
import services.generated.tables.Task
import services.generated.tables.Upload
import services.generated.tables.UploadFilepart
import services.generated.tables.User
import services.generated.tables.UserRole


object Public {

	
@Generated(
	value = Array(
		"http://www.jooq.org",
		"jOOQ version:3.7.2"
	),
	comments = "This class is generated by jOOQ"
)
class Public extends SchemaImpl("public") {

	override def getSequences : List[Sequence[_]] = {
		val result = new ArrayList[Sequence[_]]
		result.addAll(getSequences0)
		result
	}

	private def getSequences0() : List[Sequence[_]] = {
		return Arrays.asList[Sequence[_]](
			Sequences.FEATURE_TOGGLE_ID_SEQ,
			Sequences.SHARING_POLICY_ID_SEQ,
			Sequences.UPLOAD_ID_SEQ,
			Sequences.USER_ROLE_ID_SEQ)
	}

	override def getTables : List[Table[_]] = {
		val result = new ArrayList[Table[_]]
		result.addAll(getTables0)
		result
	}

	private def getTables0() : List[Table[_]] = {
		return Arrays.asList[Table[_]](
			AuthorityFile.AUTHORITY_FILE,
			Document.DOCUMENT,
			DocumentFilepart.DOCUMENT_FILEPART,
			DocumentPreferences.DOCUMENT_PREFERENCES,
			FeatureToggle.FEATURE_TOGGLE,
			Folder.FOLDER,
			FolderAssociation.FOLDER_ASSOCIATION,
			ServiceAnnouncement.SERVICE_ANNOUNCEMENT,
			SharingPolicy.SHARING_POLICY,
			Similarity.SIMILARITY,
			Task.TASK,
			Upload.UPLOAD,
			UploadFilepart.UPLOAD_FILEPART,
			User.USER,
			UserRole.USER_ROLE)
	}
} 
Example 4
Source File: ScalaPsiImplementationHelper.scala    From intellij-lsp   with Apache License 2.0 5 votes vote down vote up
package org.jetbrains.plugins.scala.lang.psi

import java.util.List

import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.{OrderEntry, ProjectFileIndex, ProjectRootManager}
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.{PsiClass, PsiFile}
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait}
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager

object ScalaPsiImplementationHelper {
  def getOriginalClass(psiClass: PsiClass): PsiClass = {
    val psiFile: PsiFile = psiClass.getContainingFile
    val vFile: VirtualFile = psiFile.getVirtualFile
    val project: Project = psiClass.getProject
    val idx: ProjectFileIndex = ProjectRootManager.getInstance(project).getFileIndex
    if (vFile == null || !idx.isInLibrarySource(vFile)) return psiClass
    val orderEntries: List[OrderEntry] = idx.getOrderEntriesForFile(vFile)
    val fqn: String = psiClass.qualifiedName
    if (fqn == null) return psiClass
    val classes: Array[PsiClass] = ScalaPsiManager.instance(project).getCachedClasses(new GlobalSearchScope((project)) {
      def compare(file1: VirtualFile, file2: VirtualFile): Int = 0
      def contains(file: VirtualFile): Boolean = {
        val entries: List[OrderEntry] = idx.getOrderEntriesForFile(file)
        var i: Int = 0
        while (i < entries.size) {
          {
            val entry: OrderEntry = entries.get(i)
            if (orderEntries.contains(entry)) return true
          }
            i += 1
        }
        false
      }
      def isSearchInModuleContent(aModule: Module): Boolean = false
      def isSearchInLibraries: Boolean = true
    }, fqn)
    if (classes.length == 0) psiClass
    else if (classes.length == 1) classes(0)
    else {
      psiClass match {
        case _: ScTrait | _: ScClass =>
          classes.find(td => td.isInstanceOf[ScTrait] || td.isInstanceOf[ScClass]).getOrElse(classes(0))
        case _: ScObject =>
          classes.find(td => td.isInstanceOf[ScObject]).getOrElse(classes(0))
        case _ => classes(0)
      }
    }
  }
} 
Example 5
Source File: SimpleMethodLookupSpec.scala    From finagle-protobuf   with Apache License 2.0 5 votes vote down vote up
package com.twitter.finagle.protobuf.rpc

import org.specs2.mutable.SpecificationWithJUnit

import org.junit.Assert._

import java.util.List

import org.junit.Test

import com.google.common.collect.Lists
import com.twitter.finagle.protobuf.rpc.channel.SimpleMethodLookup

object SimpleMethodLookupSpec extends SpecificationWithJUnit {

  "A method lookup" should {

    "find no collisions for eat, drink" in {
      val l = Lists.newArrayList("eat", "drink")
      var collision = false
      try {
        new SimpleMethodLookup(l) {
          override def createEncoding(s: String): Int = {
            eatAndEssenCollidingHash(s);
          }
        }
      } catch {
        case e: IllegalArgumentException => collision = true
      }
      collision must beFalse
    }

    "find collisions for eat, essen, drink" in {
      val l = Lists.newArrayList("eat", "essen", "drink")
      var collision = false
      try {
        new SimpleMethodLookup(l) {

          override def createEncoding(s: String): Int = {
            eatAndEssenCollidingHash(s)
          }
        }
      } catch {
        case e: IllegalArgumentException => collision = true
      }
      collision must beTrue
    }

    "find a valid method" in {
      val l = Lists.newArrayList("doThis", "doThat")
      val repo = new SimpleMethodLookup(l)
      val code = repo.encode("doThis")
      repo.lookup(code) mustEqual "doThis"
    }
  }

  def eatAndEssenCollidingHash(s: String): Int = {
    if ("eat".equals(s) || "essen".equals(s)) {
      return 1
    }
    return s.hashCode()
  }

} 
Example 6
Source File: Util.scala    From finagle-protobuf   with Apache License 2.0 5 votes vote down vote up
package com.twitter.finagle.protobuf.rpc

import java.util.List

import com.google.common.base.Function
import com.google.common.collect.Lists
import com.google.protobuf.Descriptors.MethodDescriptor
import com.google.protobuf.Service
import com.google.protobuf.Message

import scala.collection.JavaConversions._
import scala.collection.mutable._

import org.slf4j.LoggerFactory

object Util {

  private val log = LoggerFactory.getLogger(getClass)

  def extractMethodNames(s: Service): List[String] = {
    return Lists.transform(s.getDescriptorForType().getMethods(),
      new Function[MethodDescriptor, String]() {

        @Override
        def apply(d: MethodDescriptor): String = {
          return d.getName()
        }
      })
  }

  def log(reqOrResp: String, method: String, m: Message) {
    if (log.isDebugEnabled()) {
      log.debug("#log# {} {}: {}", Array[AnyRef](reqOrResp, method, m.toString()))
    }
  }
} 
Example 7
Source File: WailaFluidTank.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.basic.waila

import java.util.List
import com.calclavia.edx.basic.fluid.tank.TileTank
import mcp.mobius.waila.api.{IWailaConfigHandler, IWailaDataAccessor, IWailaDataProvider}
import net.minecraft.item.ItemStack
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.fluids.IFluidTank
import resonantengine.lib.utility.LanguageUtility


class WailaFluidTank extends IWailaDataProvider
{
  override def getWailaBody(itemStack: ItemStack, currenttip: List[String], accessor: IWailaDataAccessor, config: IWailaConfigHandler): List[String] =
  {
    val tile: TileEntity = accessor.getTileEntity
    if (tile.isInstanceOf[TileTank])
    {
      val tank: IFluidTank = tile.asInstanceOf[TileTank].fluidNode
      if (tank != null && tank.getFluid != null)
      {
        currenttip.add(LanguageUtility.getLocal("info.waila.tank.fluid") + " " + tank.getFluid.getFluid.getLocalizedName)
        currenttip.add(LanguageUtility.getLocal("info.waila.tank.vol") + " " + tank.getFluidAmount + " / " + tank.getCapacity)
      }
    }
    return currenttip
  }

  override def getWailaHead(itemStack: ItemStack, currenttip: List[String], accessor: IWailaDataAccessor, config: IWailaConfigHandler): List[String] =
  {
    return currenttip
  }

  override def getWailaStack(accessor: IWailaDataAccessor, config: IWailaConfigHandler): ItemStack =
  {
    return null
  }

  override def getWailaTail(itemStack: ItemStack, currenttip: List[String], accessor: IWailaDataAccessor, config: IWailaConfigHandler): List[String] =
  {
    return currenttip
  }
} 
Example 8
Source File: Permission.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.resonant.core.access

import java.util.List

import nova.core.util.collection.TreeNode

import scala.collection.JavaConversions._


class Permission(val id: String) extends TreeNode[Permission] {

	def addChild(perm: String): Permission = {
		return super.addChild(new Permission(perm))
	}

	def find(id: String): Permission = {
		import scala.collection.JavaConversions._
		for (child <- children) {
			if (child.id == id) {
				return child
			}
		}
		return null
	}

	override def equals(o: Any): Boolean = {
		return o.isInstanceOf[Permission] && (o.toString == toString)
	}

	override def toString: String = {
		val list: List[Permission] = hierarchy
		val builder: StringBuilder = new StringBuilder
		for (perm <- list) {
			builder.append(perm.id)
			builder.append(".")
		}
		builder.append(id)
		return builder.toString
	}
} 
Example 9
Source File: ItemUranium.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.quantum.items

import java.util.List

import net.minecraft.creativetab.CreativeTabs
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.{Item, ItemStack}
import org.lwjgl.input.Keyboard
import resonantengine.lib.render.EnumColor
import resonantengine.lib.utility.LanguageUtility
import resonantengine.lib.wrapper.CollectionWrapper._


class ItemUranium extends ItemRadioactive
{
  //Constructor
  this.setHasSubtypes(true)
  this.setMaxDamage(0)

  override def addInformation(itemStack: ItemStack, par2EntityPlayer: EntityPlayer, list: List[_], par4: Boolean)
  {
    val tooltip: String = LanguageUtility.getLocal(getUnlocalizedName(itemStack) + ".tooltip")
    if (tooltip != null && tooltip.length > 0)
    {
      if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
      {
        list.add(LanguageUtility.getLocal("tooltip.noShift").replace("#0", EnumColor.AQUA.toString).replace("#1", EnumColor.GREY.toString))
      }
      else
      {
        list.addAll(LanguageUtility.splitStringPerWord(tooltip, 5))
      }
    }
  }

  override def getUnlocalizedName(itemStack: ItemStack): java.lang.String =
  {
    return super.getUnlocalizedName() + "." + itemStack.getItemDamage
  }

  override def getSubItems(item: Item, par2CreativeTabs: CreativeTabs, list: List[_])
  {
    list.add(new ItemStack(item, 1, 0))
    list.add(new ItemStack(item, 1, 1))
  }
} 
Example 10
Source File: ContextIdParserImpl.scala    From Linkis   with Apache License 2.0 5 votes vote down vote up
package com.webank.wedatasphere.linkis.gateway.ujes.route.contextservice

import java.util
import java.util.{ArrayList, List}

import com.webank.wedatasphere.linkis.common.utils.Logging
import com.webank.wedatasphere.linkis.cs.common.entity.source.{ContextIDParser, HAContextID}
import com.webank.wedatasphere.linkis.cs.common.utils.CSHighAvailableUtils
import com.webank.wedatasphere.linkis.rpc.instancealias.InstanceAliasManager
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component



@Component
class ContextIdParserImpl extends ContextIDParser with Logging {

  @Autowired
  var instanceAliasManager : InstanceAliasManager = _

  override def parse(contextId: String): util.List[String] = {

    if (CSHighAvailableUtils.checkHAIDBasicFormat(contextId)) {
      val instances = new util.ArrayList[String](2)
      val haContextID = CSHighAvailableUtils.decodeHAID(contextId)
      if (instanceAliasManager.isInstanceAliasValid(haContextID.getInstance)) {
        instances.add(instanceAliasManager.getInstanceByAlias(haContextID.getInstance).getInstance)
      } else {
        error(s"parse HAID instance invalid. haIDKey : " + contextId)
      }
      if (instanceAliasManager.isInstanceAliasValid(haContextID.getBackupInstance)) {
        instances.add(instanceAliasManager.getInstanceByAlias(haContextID.getBackupInstance).getInstance)
      } else {
        error("parse HAID backupInstance invalid. haIDKey : " + contextId)
      }
      instances
    } else {
      new util.ArrayList[String](0)
    }
  }

  private def isNumberic(s:String):Boolean = {
    s.toCharArray foreach {
      c => if (c < 48 || c >57) return false
    }
    true
  }

} 
Example 11
Source File: ItemFuelRod.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.quantum.items

import java.util.List

import cpw.mods.fml.relauncher.{Side, SideOnly}
import edx.core.{EDXCreativeTab, Reference}
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import resonantengine.api.edx.machine.{IReactor, IReactorComponent}
import resonantengine.lib.grid.thermal.GridThermal
import resonantengine.lib.transform.vector.VectorWorld
import resonantengine.lib.wrapper.CollectionWrapper._


      reactor.heat(ItemFuelRod.energyPerTick)

      if (reactor.world.getWorldTime % 20 == 0)
      {
        itemStack.setItemDamage(Math.min(itemStack.getItemDamage + 1, itemStack.getMaxDamage))
      }
    }
  }

  @SideOnly(Side.CLIENT)
  override def getSubItems(item: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
  {
    par3List.add(new ItemStack(item, 1, 0))
    par3List.add(new ItemStack(item, 1, getMaxDamage - 1))
  }
} 
Example 12
Source File: BlockRadioactive.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.quantum.blocks

import java.util.{List, Random}

import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.client.Minecraft
import net.minecraft.client.particle.EntitySmokeFX
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.entity.{Entity, EntityLiving, EntityLivingBase}
import net.minecraft.init.Blocks
import net.minecraft.util.{AxisAlignedBB, IIcon}
import net.minecraft.world.World
import resonantengine.lib.potion.PoisonRadiation
import resonantengine.lib.transform.vector.Vector3

import scala.collection.JavaConversions._

class BlockRadioactive(material: Material) extends Block(material)
{
  var canSpread: Boolean = true
  var radius: Float = 5
  var amplifier: Int = 2
  var canWalkPoison: Boolean = true
  var isRandomlyRadioactive: Boolean = true
  var spawnParticle: Boolean = true
  private var iconTop: IIcon = null
  private var iconBottom: IIcon = null

  //Constructor
  this.setTickRandomly(true)
  this.setHardness(0.2F)

  override def getIcon(side: Int, metadata: Int): IIcon =
  {
    return if (side == 1) this.iconTop else (if (side == 0) this.iconBottom else this.blockIcon)
  }

  @SideOnly(Side.CLIENT) override def registerBlockIcons(iconRegister: IIconRegister)
  {
    super.registerBlockIcons(iconRegister)
    this.iconTop = iconRegister.registerIcon(this.getUnlocalizedName.replace("tile.", "") + "_top")
    this.iconBottom = iconRegister.registerIcon(this.getUnlocalizedName.replace("tile.", "") + "_bottom")
  }

  
  override def onEntityWalking(par1World: World, x: Int, y: Int, z: Int, par5Entity: Entity)
  {
    if (par5Entity.isInstanceOf[EntityLiving] && this.canWalkPoison)
    {
      PoisonRadiation.INSTANCE.poisonEntity(new Vector3(x, y, z), par5Entity.asInstanceOf[EntityLiving])
    }
  }

  override def quantityDropped(par1Random: Random): Int =
  {
    return 0
  }

  @SideOnly(Side.CLIENT) override def randomDisplayTick(world: World, x: Int, y: Int, z: Int, par5Random: Random)
  {
    if (this.spawnParticle)
    {
      if (Minecraft.getMinecraft.gameSettings.particleSetting == 0)
      {
        val radius: Int = 3
        for (i <- 0 to 2)
        {
          val pos: Vector3 = new Vector3(x, y, z)
          pos.add(Math.random * radius - radius / 2, Math.random * radius - radius / 2, Math.random * radius - radius / 2)
          val fx: EntitySmokeFX = new EntitySmokeFX(world, pos.x, pos.y, pos.z, (Math.random - 0.5) / 2, (Math.random - 0.5) / 2, (Math.random - 0.5) / 2)
          fx.setRBGColorF(0.2f, 0.8f, 0)
          Minecraft.getMinecraft.effectRenderer.addEffect(fx)

        }
      }
    }
  }

} 
Example 13
Source File: ItemBlockThermometer.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.quantum.machine.thermometer

import java.util.List

import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.ChatComponentText
import net.minecraft.world.World
import resonantengine.lib.transform.vector.Vector3
import resonantengine.lib.utility.LanguageUtility
import resonantengine.lib.utility.nbt.NBTUtility
import resonantengine.lib.wrapper.CollectionWrapper._
import resonantengine.prefab.block.itemblock.ItemBlockSaved

class ItemBlockThermometer(block: Block) extends ItemBlockSaved(block: Block)
{
  override def addInformation(itemStack: ItemStack, player: EntityPlayer, par3List: List[_], par4: Boolean)
  {
    super.addInformation(itemStack, player, par3List, par4)

    val coord: Vector3 = getSavedCoord(itemStack)
    if (coord != null)
    {
      par3List.add("\uaa74" + LanguageUtility.getLocal("tooltip.trackingTemperature"))
      par3List.add("X: " + coord.xi + ", Y: " + coord.yi + ", Z: " + coord.zi)
    }
    else
    {
      par3List.add("\u00a74" + LanguageUtility.getLocal("tooltip.notTrackingTemperature"))
    }
  }

  def getSavedCoord(itemStack: ItemStack): Vector3 =
  {
    val nbt: NBTTagCompound = NBTUtility.getNBTTagCompound(itemStack)
    if (nbt.hasKey("trackCoordinate"))
    {
      return new Vector3(nbt.getCompoundTag("trackCoordinate"))
    }
    return null
  }

  override def onItemRightClick(itemStack: ItemStack, world: World, player: EntityPlayer): ItemStack =
  {
    setSavedCoords(itemStack, null)
    if (!world.isRemote)
    {
      player.addChatMessage(new ChatComponentText("Cleared tracking coordinate."))
    }
    return itemStack
  }

  override def onItemUse(itemStack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, par7: Int, par8: Float, par9: Float, par10: Float): Boolean =
  {
    if (player.isSneaking)
    {
      if (!world.isRemote)
      {
        setSavedCoords(itemStack, new Vector3(x, y, z))
        player.addChatMessage(new ChatComponentText("Tracking coordinate: " + x + ", " + y + ", " + z))
      }
      return true
    }
    return super.onItemUse(itemStack, player, world, x, y, z, par7, par8, par9, par10)
  }

  def setSavedCoords(itemStack: ItemStack, position: Vector3)
  {
    val nbt: NBTTagCompound = NBTUtility.getNBTTagCompound(itemStack)
    if (position != null)
    {
      nbt.setTag("trackCoordinate", position.writeNBT(new NBTTagCompound))
    }
    else
    {
      nbt.removeTag("trackCoordinate")
    }
  }
} 
Example 14
Source File: ItemQuantumGlyph.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.quantum.gate

import java.util.List

import codechicken.lib.vec.{BlockCoord, Vector3}
import codechicken.microblock.CornerPlacementGrid
import codechicken.multipart._
import edx.core.ResonantPartFactory
import edx.core.prefab.part.IHighlight
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.world.World
import resonantengine.lib.wrapper.CollectionWrapper._

class ItemQuantumGlyph extends Item with TItemMultiPart with IHighlight
{
  setHasSubtypes(true)

  override def getUnlocalizedName(itemStack: ItemStack): String =
  {
    return super.getUnlocalizedName(itemStack) + "." + itemStack.getItemDamage
  }

  def newPart(itemStack: ItemStack, player: EntityPlayer, world: World, pos: BlockCoord, side: Int, hit: Vector3): TMultiPart =
  {
    val part = ResonantPartFactory.create(classOf[PartQuantumGlyph])
    var slot = CornerPlacementGrid.getHitSlot(hit, side)
    val tile = world.getTileEntity(pos.x, pos.y, pos.z)

    if (tile.isInstanceOf[TileMultipart])
    {
      val checkPart: TMultiPart = (tile.asInstanceOf[TileMultipart]).partMap(slot)
      if (checkPart != null)
      {
        side match
        {
          case 0 => slot -= 1
          case 1 => slot += 1
          case 2 => slot -= 2
          case 3 => slot += 2
          case 4 => slot -= 4
          case 5 => slot += 4
        }
      }
    }

    part.preparePlacement(slot, itemStack.getItemDamage)

    return part
  }

  override def getSubItems(item: Item, tab: CreativeTabs, listToAddTo: List[_])
  {
    for (i <- 0 until PartQuantumGlyph.MAX_GLYPH)
    {
      listToAddTo.add(new ItemStack(item, 1, i))
    }
  }

  def getHighlightType: Int = 1
} 
Example 15
Source File: ItemMultimeter.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.electrical.multimeter

import java.util.List

import codechicken.lib.vec.{BlockCoord, Vector3}
import codechicken.microblock.FacePlacementGrid
import codechicken.multipart.{JItemMultiPart, PartMap, TMultiPart, TileMultipart}
import edx.core.ResonantPartFactory
import edx.core.prefab.part.IHighlight
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.MathHelper
import net.minecraft.world.World
import org.lwjgl.input.Keyboard
import resonantengine.lib.render.EnumColor
import resonantengine.lib.utility.LanguageUtility
import resonantengine.lib.wrapper.CollectionWrapper._

class ItemMultimeter extends JItemMultiPart with IHighlight
{
  def newPart(itemStack: ItemStack, player: EntityPlayer, world: World, pos: BlockCoord, vSide: Int, hit: Vector3): TMultiPart =
  {
    val side = FacePlacementGrid.getHitSlot(hit, vSide)
    val tile: TileEntity = world.getTileEntity(pos.x, pos.y, pos.z)

    if (tile.isInstanceOf[TileMultipart])
    {
      val centerPart: TMultiPart = tile.asInstanceOf[TileMultipart].partMap(PartMap.CENTER.ordinal)
      if (centerPart != null && !player.isSneaking)
      {
        pos.offset(side ^ 1)
      }
    }

    val part = ResonantPartFactory.create(classOf[PartMultimeter])

    if (part != null)
    {
      val l = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3
      val facing = if (l == 0) 2 else (if (l == 1) 5 else (if (l == 2) 3 else (if (l == 3) 4 else 0)))
      part.preparePlacement(side, facing)
    }

    return part
  }

  override def addInformation(itemStack: ItemStack, par2EntityPlayer: EntityPlayer, list: List[_], par4: Boolean)
  {
    if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
    {
      list.add(LanguageUtility.getLocal("tooltip.noShift").replace("#0", EnumColor.AQUA.toString).replace("#1", EnumColor.GREY.toString))
    }
    else
    {
      list.addAll(LanguageUtility.splitStringPerWord(LanguageUtility.getLocal("item.resonantinduction:multimeter.tooltip"), 5))
    }
  }

  def getDetection(itemStack: ItemStack): Float =
  {
    if (itemStack.stackTagCompound == null || !itemStack.getTagCompound.hasKey("detection"))
    {
      return -1
    }
    return itemStack.stackTagCompound.getFloat("detection")
  }

  def setDetection(itemStack: ItemStack, detection: Float)
  {
    if (itemStack.stackTagCompound == null)
    {
      itemStack.setTagCompound(new NBTTagCompound)
    }
    itemStack.stackTagCompound.setFloat("detection", detection)
  }

  def getHighlightType: Int = 0
} 
Example 16
Source File: BlockDecoration.scala    From Electrodynamics   with GNU Lesser General Public License v3.0 5 votes vote down vote up
package com.calclavia.edx.core.resource.content

import java.util.List

import com.calclavia.edx.core.Reference
import Reference
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.util.IIcon
import resonantengine.lib.modcontent.block.ResonantBlock
import resonantengine.lib.wrapper.CollectionWrapper._
import resonantengine.prefab.block.itemblock.ItemBlockMetadata


class BlockDecoration extends ResonantBlock(Material.rock)
{
  var iconNames = Array("material_stone_brick", "material_stone_brick2", "material_stone_chiseled", "material_stone_cobble", "material_stone_cracked", "material_stone", "material_stone_slab", "material_stone_mossy", "material_steel_dark", "material_steel_tint", "material_steel")
  var icons = new Array[IIcon](iconNames.length)

  // Constructor
  name = "industrialStone"
  blockHardness = 1
  stepSound = Block.soundTypeStone
  this.itemBlock = classOf[ItemBlockMetadata]

  override def getIcon(side: Int, metadata: Int): IIcon =
  {
    return icons(metadata)
  }

  override def registerIcons(register: IIconRegister)
  {
    super.registerIcons(register)
    (0 until icons.size) foreach (i => icons(i) = register.registerIcon(Reference.prefix + iconNames(i)))
  }

  override def getSubBlocks(item: Item, par2CreativeTabs: CreativeTabs, list: List[_])
  {
    (0 until iconNames.length) foreach (i => list.add(new ItemStack(item, 1, i)))
  }
} 
Example 17
Source File: RMCallbackHandler.scala    From DataXServer   with Apache License 2.0 5 votes vote down vote up
package org.tianlangstudio.data.hamal.yarn

import java.io.File
import java.util.{Collections, List}

import org.tianlangstudio.data.hamal.core.{Constants, HamalConf}
import org.tianlangstudio.data.hamal.core.HamalConf
//import java.util.Collections

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.{FileSystem, Path, FileContext}
import org.apache.hadoop.yarn.api.records._
import org.apache.hadoop.yarn.client.api.{AMRMClient, NMClient}
import org.apache.hadoop.yarn.client.api.async.AMRMClientAsync
import org.apache.hadoop.yarn.conf.YarnConfiguration
import org.apache.hadoop.yarn.util.{ConverterUtils, Records}
import scala.jdk.CollectionConverters._
//import scala.collection.JavaConverters._
/**
 * Created by zhuhq on 2016/4/29.
 */
class RMCallbackHandler(nmClient:NMClient,containerCmd:Container => String,hamalConf: HamalConf,yarnConfiguration: Configuration)  extends  AMRMClientAsync.CallbackHandler {
  private val logging = org.slf4j.LoggerFactory.getLogger(classOf[RMCallbackHandler])
  override def onContainersCompleted(statuses: List[ContainerStatus]): Unit = {
    for(containerStatus <- statuses.asScala) {
      logging.info(s"containerId:${containerStatus} exitStatus:${containerStatus}")
    }
  }

  override def onError(e: Throwable): Unit = {
    logging.error("on error",e)

  }

  override def getProgress: Float = {

    0
  }

  override def onShutdownRequest(): Unit = {
    logging.info("on shutdown request")

  }

  override def onNodesUpdated(updatedNodes: List[NodeReport]): Unit = {
    logging.info("on nodes updated")
    for(nodeReport <- updatedNodes.asScala) {
      logging.info(s"node id:${nodeReport} node labels:${nodeReport}");
    }
  }

  override def onContainersAllocated(containers: List[Container]): Unit = {
    logging.info("on containers allocated");
    for (container:Container <- containers.asScala) {
      try {
        // Launch container by create ContainerLaunchContext
        val  ctx = Records.newRecord(classOf[ContainerLaunchContext]);

        //ctx.setCommands(Collections.singletonList(""" echo "begin";sleep 900;echo "end"; """))
        ctx.setCommands(Collections.singletonList(containerCmd(container)))
        val packagePath = hamalConf.getString(Constants.DATAX_EXECUTOR_FILE,"executor.zip");
        val archiveStat = FileSystem.get(yarnConfiguration).getFileStatus(new Path(packagePath))
        val  packageUrl = ConverterUtils.getYarnUrlFromPath(
          FileContext.getFileContext.makeQualified(new Path(packagePath)));
        val packageResource = Records.newRecord[LocalResource](classOf[LocalResource])

        packageResource.setResource(packageUrl);
        packageResource.setSize(archiveStat.getLen);
        packageResource.setTimestamp(archiveStat.getModificationTime);
        packageResource.setType(LocalResourceType.ARCHIVE);
        packageResource.setVisibility(LocalResourceVisibility.APPLICATION)
        ctx.setLocalResources(Collections.singletonMap(Constants.DATAX_EXECUTOR_ARCHIVE_FILE_NAME,packageResource))
        logging.info("[AM] Launching container " + container.getId());
        nmClient.startContainer(container, ctx);
      } catch {
        case ex:Exception =>
          logging.info("[AM] Error launching container " + container.getId() + " " + ex);
      }
    }
  }

}