In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to become taller and wider in Scala". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve taller and wider in Scala".
The version of Element shown in Code 10.11 is not complete because it does not allow customers to stack elements of different widths or lean elements of different heights together. For example, the following expression will not work because the second line of the combined element is longer than the * line:
New ArrayElement (Array ("hello")) above new ArrayElement (Array ("world!"))
Similarly, the following expression does not work because the height of the * ArrayElement is two, while the height of the second is only one:
New ArrayElement (Array ("one", "two")) beside new ArrayElement (Array ("one"))
Code 10.13 shows a private helper method, widen, that takes a width as an argument and returns an Element of that width. The result contains the contents of the Element, centered, leaving spaces on the left and right to get the desired width. Code 10.13 also shows a similar method, heighten, that performs the same function in a vertical direction. The widen method is called by above to ensure that the Element is stacked with the same width. Similarly, the heighten method is called by beside to ensure that the elements next to each other have the same height. With these changes, the layout library is ready for use.
Import Element.elem abstract class Element {def contents: Array [String] def width: Int = contents (0). Length def height: Int = contents.length def above (that: Element): Element = {val this1 = this widen that.width val that1 = that widen this.width elem (this1.contents + + that1.contents)} def beside (that: Element): Element = {val this1 = this heighten that.height val that1 = that heighten this.height elem (for ((line1 Line2) <-this1.contents zip that1.contents) yield line1 + line2)} def widen (w: Int): Element = if (w < = width) this else {val left = elem (', (w-width) / 2, height) var right = elem (', w-width-left.width) Height) left beside this beside right} def heighten (h: Int): Element = if (h < = height) this else {val top = elem ('', width, (h-height) / 2) var bot = elem (', width, h-height-top.height) top above this above bot} override def toString = contents mkString "\ n"}
Code-10.13 has the Element of the widen and heighten methods
Thank you for your reading, the above is the content of "how to achieve height and width in Scala". After the study of this article, I believe you have a deeper understanding of how to achieve height and width in Scala, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.