New Look!
Welcome to www.PENETRATIONTEST.com!
Things sure are looking different around here! In our second quarter meeting, a member of our planning team remembered something they were asked in a business development course:
"What would your customers create if they were
given total control of your marketing?"
This is a question that doesn't get asked anywhere near often enough. So we did. We asked a whole lot of our prized customers what they would hope to see on a website like ours. Then we set out to build it. We couldn't be happier with what we've come up with. And we're pretty sure you will be too.
The number one request was that our customers want to see a more balanced approach to the technical and human elements of Information Security. Nobody needs yet another technical HOWTO when simply googling a specific topic will provide endless amounts of exactly the same information repackaged to look like original content. Especially when that information confuzingly sticks around well past it's expiry date. The direction you want to see is loud and clear.
One of our favourite new addition is the Dossier. It's not a blog. It's not a magazine. We can't say too much about it until it is ready to launch in May. It is looking amazing. Watch here for the announcements!
The customer is always right. We're onto something GREAT!
Karsten Johansson
Managing Information Security with E's
XAMINE - Our expert auditors, penetration testers and social engineers will help you identify and manage risks that impact your valuable information.
NFORCE - We provide seasoned advisors to help you proactively control the flow of information and manage secure operations.
MPOWER - Reduce the risks and costs associated to outsourcing. Our training programs bring control of how your information is used back to you.
One of the benefits www.PENETRATIONTEST.com enjoys from being directly involved in the Information Security business for almost 2 decades, is that we have played an integral role helping businesses keep up with the constantly changing threatscape. We've worked with companies ranging from tens of employees to Fortune 50 and 500 companies whose numbers are in the tens of thousands.
All this exposure has given us a holistic view and approach to securing information. To us, security is part of the overall process that governs the most successful of organizations. There are three core ways we make secure operations a reality for our customers:
- Examine - This is our core competancy - what we've been doing the world over for 17 years. At the turn of the century, we developed the Offensive Operations Model as the framework to set a consistent and demonstrably high level of success in our penetration testing, auditing and social engineering engagements. The Offensive Operations Model is published by IEEE under document 0.1109/ICTTA.2004.1307886. A number of standards have appeared since, but the Offensive Operations Model is the only one that can withstand the test of time, and used to audit the others.
- Enforce - Maintaining a high degree of Information Security is all about having appropriate controls everywhere information is processed, stored, or transferred. Our Information Security Advisors pride themselves on working with some of the most advanced knowlege and techniques available to develop and maintain thorough and consistent information security at the management, operational and technical levels.
- Empower - You hired a great team based on each person's ability to deliver the results you need for your company to succeed. But chances are, Information Security was not part of their training. Consultants and advisors from www.PENETRATIONTEST.com deliver some of the most pertinent training available. We have taught at colleges and universities around the globe as well as in Fortune 500 and Fortune 50 education facilities. We also provide customized training to companies of all sizes. We also do public speaking engagements covering many Information Security subjects. Our advisors do keynote speeches at technical tradeshows and have appeared in numerous blogs, news programs, magazines and so on.
The year 2014 began as the first time the general public fully understood how every aspect of the information lifecycle cannot leave our immediate control. Everywhere information is stored, processed or transported without stringent security controls represents an opportunity for someone - Friend or Foe (we no longer can tell) - to exploit it for their own purposes. Our experts will help you gain and maintain that control.
Contact us at<EMAIL_ADDRESS>to discuss how we can help you get there.


Court clears Thaksin’s son in Thai bank money laundering case
by Coconuts BangkokThe only son of fugitive former Prime Minister Thaksin Shinawatra was acquitted today of money laundering charges.
Panthongtae “Oak” Shinawatra, 39, walked out of the Central Criminal Court for Corruption and Misconduct Cases a free man just before 11am after judges found him not guilty, saying prosecutors had provided insufficient evidence of wrongdoing.
He had been accused of helping launder money in a scandal involving loans fraudulently approved by a state-run bank amounting to nearly THB10 billion (US$43 million) 13 years ago during his father’s administration.
Panthongtae had received a THB10 million check from that largesse, but the court determined that there was insufficient evidence that Panthongtae knew where the money came from.
A billionaire in his own right, Panthongtae struck a more apolitical public stance until late last year when he joined the Pheu Thai Party, which was founded and is still guided by his father’s influence.
Thaksin was deposed in a 2006 coup d’etat, and Panthongtae’s Voice TV television station frequently ran afoul of the military government which ousted his aunt, Yingluck Shinawatra, from power in 2014. It was ordered to cease broadcasting on several occasions for political commentary the junta objected to.
Related:
Thaksin’s son gives Thai police B7 million reward for Bangkok blast probe


Ibsen
Valath
Expertise:
Reactjs,
Redux, Core
Web Development
Engineer
Javascript,
ES6,
Webpack, HTML5, CSS3.
Experience:
Current Role
:
● Front End Developer at
Contact:
SupportCentral,
GE
Digital, GE
Company at Tata
Consultancy
Services.
● Reactjs CoE member at Tata
Consultancy
Services.
Summary
Experienced
Front
End Developer with + years of industry experience building
static
websites and web
applications based out at Kochi, India.
Specializing in
Core
JavaScript, I have professional experience using libraries like
React.js, Redux
,
javascript bundlers like Webpack, Requirejs, task runners like Nodejs,
Grunt, Gulp,
package
managers like Bower, NPM, css preprocessors like SASS,LESS and
also in Angular
js
framework. I also have JAVA certification from Cognizant and a short
professional
experience using JAVA and hybrid mobile application development.
After graduation
from
National Institute of Technology Agartala, I started exploring
my career at
Cognizant Technology Solutions in 2011 and later joined Tata
Consultancy
Services
in 2016. Currently I am part of Reactjs CoE at TCS.
I would describe
myself as a passionate coder and a perfectionist web developer.
Primary
Skills:
Skills
Core Javascript,
ES6, HTML5, CSS3, Reactjs, Redux, Webpack, Requirejs, Nodejs, NPM,
LESS,
SASS.
Secondary
Skills:
Angular js,
Grunt,
Gulp, JAVA, React Native.
Tools
Used:
Visual Studio
Code,
Gitlab, Github, Notepad++, GIT, Tortoise Git, Tortoise SVN.
Project
Support Central -
GE
Digital / General Electric.
Jul 20 16 -
present
Experience
Role : Worked as
UI
Developer
Name Of Company
:
TATA Consultancy Services
Project
Description:
SupportCentral is an enterprise resource planning portal for GE
employees.
Technologies
Used :
React js, Redux, Webpack, Angularjs,
Mar 2016 - Jul
2016
StarTrak /
MetLife
Insurance
Role : Worked as
UI
Developer/AngularJS Support
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
MetLife StarTrak system supports the administration of the
following
areas:
Statement of Health processing &
Recordkeeping.
The
primary objective of this application is
to
manage the
additional
insurance cover request by a user.
Technologies
Used :
AngularjS 1.3.18, HTML5, CSS3. GIT.
Aug 2015 - Mar
2016
FNOL / Mapfre
Insurance
Role : Worked as
Team Lead
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
The FNOL (First Notice of Loss) application is a web app
designed to
facilitate users to raise insurance claims. The
project was
well
received by the client and had a huge
response from
the
users in the initial week itself.
Technologies
Used:
AngularjS 1.2.9, HTML5, CSS3. Tortoise SVN.
StarTrak /
MetLife
Insurance
Role : Worked as
UI
Developer
Jan 2015 – Aug
2015
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
MetLife StarTrak system supports the administration of the
following
areas:
Statement of Health processing &
Recordkeeping.
The
primary objective of this application is to
manage the
additional
insurance cover request by a user.
Technologies
Used :
AngularjS, HTML5, CSS3. GIT.
Nov 2014 – Jan
2015
BrandEye /
Cognizant
Internal
Role : Worked as
UI
Developer
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
This was a short project and the goal of this project was to
design a new
webpage
for quanteye.
Technologies
Used :
HTML5, CSS3,Jquery.
Aug 2014 – Nov
2014
M-app/ MaxLife
Insurance
Role : Worked as
UI
Developer
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
The goal of this project is to design an app from agents in
maxlife
insurance
company.
Technologies
Used :
Angular JS, Phonegap Jquery , Javascript,SVN.
Oct 2013 - May
2014
MRecruitment /
MaxLife Insurance
Role : Worked as
UI
Developer
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
The goal of this project is to design an app from agents in
maxlife
insurance
company for training purposes.
Technologies Used
:
Angular JS, Phonegap Jquery , Javascript.
Mar 2013 - Oct
2013
MSales / MaxLife
Insurance
Role :
development
and production support
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
The goal of this project is to design an app from agents in
maxlife
insurance
company for training purposes.
Technologies
Used :
Angular JS, Phonegap Jquery , Javascript.
Dec 2012 – Feb
2013
HISNA /
Hyundai-Kia
Motor group
Role : Worked as
UI
Developer
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
In order to improve the customer experience when a customer
brings the car
for
service, this Mobile App will track the status
of the
customer’s
vehicle from the time it is brought into the
dealership
until it
is delivered. Based on the customer
preference an
email
or SMS will be generated to the customer
Technologies
Used:
HTML5, CSS3, Jquery mobile, Phonegap.
Feb 2012 - Sept
2012
First Data/
First
Data Corporation
Role: MDM
(Master
Data Management) Developer.
Name Of Company
:
Cognizant Technology Solutions
Project
Description:
The goal of this project is to design Master Data Management
solution for
First
Data Corporation using IBM
WebSphere/Infosphere.
Technologies
Used:
Java/J2EE.
Education
B-Tech :
National Institute of Technology, Agartala.
2007 -
2011
Class XII :
Adarsha
Vidya Bhavan School, Kochi, Kerala.
2005 -
2007
Class X : HDPY
Higher Secondary School,Kochi, Kerala.
1993 –
2005
Contact
Details
I hereby declare
that all the above information is true and can be verified at any me.
Kochi,
India


Documentation of the pw85
library¶
This library implements the “contact function” defined by Perram and Wertheim (J. Comp. Phys. 58(3), 409–416, DOI:10.1016/0021-9991(85)90171-8) for two ellipsoids. Given two ellipsoids, this function returns the square of the common factor by which both ellipsoids must be scaled (their centers being fixed) in order to be tangentially in contact.
This library is released under a BSD 3-Clause License.
A PDF version of this documentation can be dowloaded
here
.


public class SortBy
extends java.lang.Object
This class contains a sub-set of strings that ShopGun uses for sorting lists queries. All sort types are in ascending order, but can be reverted to descending order by prepending the string "-" to any of them.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
COUNT |
static java.lang.String |
CREATED
SortBy a list by created in ascending order.
|
static java.lang.String |
DEALER |
static java.lang.String |
DISTANCE
SortBy a list by distance in ascending order.
|
static java.lang.String |
EXPIRATION_DATE
SortBy a list by expired in ascending order.
|
static java.lang.String |
NAME
SortBy a list by name in ascending order.
|
static java.lang.String |
PAGE
SortBy a list by page (in catalog) in ascending order.
|
static java.lang.String |
POPULARITY
SortBy a list by popularity in ascending order.
|
static java.lang.String |
PRICE
SortBy a list by price in ascending order.
|
static java.lang.String |
PUBLICATION_DATE
SortBy a list by published in ascending order.
|
static java.lang.String |
QUANTITY |
static java.lang.String |
SAVINGS |
static java.lang.String |
SCORE
SortBy a list by it's internal score in ascending order.
|
static java.lang.String |
VALID_DATE |
| Constructor and Description |
|---|
SortBy() |
public static final java.lang.String POPULARITY
public static final java.lang.String DISTANCE
public static final java.lang.String NAME
public static final java.lang.String PUBLICATION_DATE
public static final java.lang.String EXPIRATION_DATE
public static final java.lang.String CREATED
public static final java.lang.String PAGE
public static final java.lang.String SCORE
public static final java.lang.String PRICE
public static final java.lang.String DEALER
public static final java.lang.String SAVINGS
public static final java.lang.String QUANTITY
public static final java.lang.String COUNT
public static final java.lang.String VALID_DATE


--- title: nareix description: --- {{# posts_latest }} {{title}} {{ date }} {{{ summary }}} Continue reading → {{/ posts_latest }}


CSS Design: The Box Model
What is all this Padding business, anyway?
October 25, 2014
Cascading Style Sheets can at times be a very simple language, and at other times make you bang your head against a wall. It's important to realize that each feature has a logical reason for existing.
We use CSS to separate the styling of our page from the content of it. The word "page" there is insignificant; our strategy in styling is to define and work with the areas of the white space in front of us on the screen. A popular way to break down this white space is with the Box Model
The Box Model (not BM for short) is a way of visualizing parts or the whole of the page. We want to put something on the page; this is called our content. Our content can be text, it can be an image, it can be anything we wish to display. There are then certain parameters that form a "shell" around that content, or element, in the shape of a box, which tell the element where to go on the page.
The outermost portion of the box is the margin. The margin is used to space the element within the page and from other elements on the page. It does not appear on the page, but is largely responsible for the spacing of elements on the page. Inside the margin is the border, which tells us the area in which the actual content will go. The border can be visible if we give it styling to be such, or can be merely an indicator in our code of where the element will be. Finally we have our padding. The padding allows us to space our content within the element, by telling us where the content itself will be relative to the border.
So there we have it. The box model is an important way to think about every piece of information we want to put on the page. It lets us play Tetris on multiple levels with our elements, fine-tuning until they look just right.
twitter facebook email>


close road
Kanto
Show road
Show Team
hp:
Catch:
All
New
Using:
Pokeballs:
10
Greatballs:
0
Ultraballs:
0
Masterballs:
0
hp:
xp:
Back
Front
Fight
Info
Catch
Balls
All
Enable console
Clear game data
Clear Console
View Stats
Save
Load
Copy to clipboard
Export your save
Load
Version: NGGYU NGLYD
Github
Subreddit
Discord
close team
Manage Team
View Pokedex
Own + Owned Pokemon :
Heal
Level
Pokedex #
Level, attack
Asc
Desc
All
Missing
Shiny
Statistics


Commentary: Have the Hong Kong police lost control?
by Carol Anne Goodwin JonesTwo deaths and video of a police man shooting a protester have hardened attitudes of Hong Kongers against the police, say the University of Birmingham's Carol Anne Goodwin Jones.
BIRMINGHAM: The situation in Hong Kong has become decidedly more serious and more intense in the past week.
The sporadic violence associated with small groups of protesters and police has escalated into full-scale battles.
There have been two deaths, more arrests, more teargas, more people injured, some critically. Lines have well and truly been drawn and crossed by both sides.
READ: Hong Kong protests: 1,100 people arrested in a day, 3,900 petrol bombs found at university
READ: Fresh university clashes in Hong Kong as protesters hurl petrol bombs
OUT OF CONTROL?
The government claims it is in control of the situation but, among the public, there is a widespread belief that the police are being allowed to act out of control.
It was the death of a young student, Alex Chow, during a police clearance operation in early November, and the police shooting, at point blank range, of an unarmed protester a few days later, which prompted this turn to violence.
READ: Commentary: Are Hong Kong police officers equipped to deal with new wave of protests?
READ: Commentary: Has the use of violence in Hong Kong’s protests backfired?
Together with the force’s unwillingness to acknowledge any wrongdoing, this has simply contributed to the growing feeling that the police are now acting with impunity.
No one has yet been held to account.
The police’s resolute rejection of allegations that they have abused their power is fuelling the public’s belief that the government is simply not prepared to listen to them.
This is what some protesters have argued since the start, when the government failed to respond to the 2 million people who marched peaceably through Hong Kong in June.
ACTION AND REACTION
The failure to persuade the government of the need for political reform and an independent police inquiry by peaceful means is the rationale of those who have turned to violence.
The protesters have targeted specific places and property associated with mainland China. Until this week, violence against people was not part of their repertoire.
It was the police, not the protesters, who first opened fire and who have continued to engage in confrontational acts designed to provoke a reaction, including calling the protesters “cockroaches” and banging their shields as they move forwards in formation.
This has simply produced a spiral of action-and-reaction, descending into acts of revenge and retaliation on both sides.
READ: Commentary: Have the Hong Kong protesters lost the narrative?
TEAR GAS TALES
It’s not only the groups of violent protesters who are affected. Verifiable footage, witness statements by lawyers, first aiders and Amnesty all testify to the police strong-arming of by-standers, spraying tear gas directly into the face of anyone who gets in their way.
The gas has also been sprayed in such volume that it has seeped into buses, the underground, and shops, afflicting one reporter with chloracne, a known effect of direct exposure to the dioxins used in tear gas.
Face masks – commonly used to stifle the spread of germs during the flu season – are now being worn by some families inside their own homes because tear gas has been fired into their buildings.
Children, fathers, mothers and grandparents now have their own stories of daily, small-scale but deeply serious violations by the police.
READ: Commentary: How did Hong Kong, my home, turn into a war zone?
READ: Commentary: The fight behind closed doors at home in Hong Kong
They have watched live video of the police spraying tear gas and pepper spray in enclosed spaces, directly into a person’s face at close quarters, and at very young children running along the street.
They have heard police officers swearing at those they deem protesters, threatening them with batons and firearms.
Whether it be from the top deck of their bus, on the streets or in their living rooms, Hong Kongers have witnessed water cannon laced with blue die and chemicals spraying water indiscriminately along the streets, and even into the entrance of a well-known mosque.
Ordinary people in football stadiums, sports centres and shopping malls can now be heard booing the Chinese National Anthem, cursing the police, and filing out of their downtown city offices to show their support for the protesters.
When a police spokesman spoke on Nov 12 of the breakdown of the rule of law, it was not, therefore, on the protesters that the public first placed the blame.
LOSING LEGITIMACY?
Since the 1997 handover, Hong Kong has been badly governed by a succession of weak leaders, but it retains its common law system, under which no one, including the police, is above the law.
In common with police forces around the world, the Hong Kong Police receive special training in public order policing which should equip them to handle riot situations appropriately. Internal police guidelines also regulate the use of force in public order policing.
READ: Commentary: Is there a way forward in Hong Kong?
READ: Commentary: How violence and brazen actions in Hong Kong were normalised
It’s the existence of these regulations and legal restraints which, though imperfect, have until now led Hong Kongers to accept the police force as the only institution which can legitimately employ coercive means against the citizen.
But the visible lack of restraint exercised by the police in recent days has undermined this legitimacy.
The fact that being captured on film has had no restraining effect whatsoever has convinced many members of the public that the police must have been given some assurance of immunity.
Carrie Lam, Hong Kong’s chief executive, has repeatedly stated her support for the police and refused outright to criticise their misconduct.
An independent panel of experts said in mid-November that the existing mechanisms of police accountability were incapable of conducting a proper investigation, but so far the government has not responded to its recommendations.
READ: Hong Kong leader Carrie Lam says campus protesters must surrender
It is this idea that the state actively sanctions police violence that has cemented the belief that the Hong Kong government stands against the people. Only the state can alter that.
The restoration of law and order demanded by Beijing can only be achieved by reining in the police, not by further use of force.
That is likely to transform the 2 million peaceful protesters of June into millions more protesters, coming to the aid of those on the frontline, fighting for their way of life.
Strong-arm policing is not so much a sign of authoritarianism, as it is a symptom of a failed state.
Carol Anne Goodwin Jones is Reader at University of Birmingham’s Birmingham Law School. This commentary first appeared in The Conversation.
READ: Our coverage of the Hong Kong protests
Follow us on Telegram for the latest on Hong Kong: https://cna.asia/telegram


Codeaia
For more information and test the beta, head over:
Codeaia.ga
Personal Web Page
My personal web page can be accessed from
here


Followed by p text
A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long. A paragraph with some text on a line that is fairly long.
some lists (in a para again):
some lists:This paragraph contains a bunch of phrase elements. Up first in an [A]nchor, followed by an ABBR with a title value, followed by an
ADDRESS, followed by a CITE element, followed by a TT TT element element, followed by a CODE CODE-BLOCK element element, followed by a CODECODE element
element, followed by a Qelement, followed by a SAMP element, followed by a SPAN element, followed by a STRONG element, followed by a TT element, followed by a VAR element, all within a containing P.
Another paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with text
Another paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with textAnother paragraph with text
This is a BLOCKQUOTE element.
Start of a table
| This is a TH in a TR in a THEAD in a TABLE | This is a TD in a TR in a THEAD in a TABLE |
|---|---|
| This is a TH in a TR in a TFOOT in a TABLE | This is a TD in a TR in a TFOOT in a TABLE |
| This is a TH in a TR in a TBODY in a TABLE | This is a TD in a TR in a TBODY in a TABLE |
An xmp section
This paragraph contains a bunch of phrase elements. Up first in an [A]nchor, followed by an ABBR with a title value #include if (a  c)
A pre section

!This paragraph contains a bunch of phrase elements. Up first in an [A]nchor, followed by an ABBR with a title value #include if (a  c)Finished.
A pre section starting ending on new line:

!This paragraph contains a bunch of phrase elements. Up first in an [A]nchor, followed by an ABBR with a title value #include if (a  c)Finished. A pre class section
This paragraph contains a bunch of phrase elements. Up first in an [A]nchor, followed by an ABBR with a title value if (entity instanceof OxClass) description = "Class"; else if (entity instanceof OxMethod) { if ( ((OxMethod) entity).parentClass() != null) { shortdescription = project.linkToEntity(((OxMethod) entity).parentClass()); description = "Function of " + shortdescription; } else if (entity.isInternal()) // JAD description = "Local function"; // JAD else description = "Global function"; } #include if (a  c) if (entity instanceof OxClass) description = "Class"; else if (entity instanceof OxMethod) { if ( ((OxMethod) entity).parentClass() != null) { shortdescription = project.linkToEntity(((OxMethod) entity).parentClass()); description = "Function of " + shortdescription; } else if (entity.isInternal()) // JAD description = "Local function"; // JAD else description = "Global function"; } #include if (a  c) if (entity instanceof OxClass) description = "Class"; else if (entity instanceof OxMethod) { if ( ((OxMethod) entity).parentClass() != null) { shortdescription = project.linkToEntity(((OxMethod) entity).parentClass()); description = "Function of " + shortdescription; } else if (entity.isInternal()) // JAD description = "Local function"; // JAD else description = "Global function"; } #include if (a  c) Finished.
| # | Name | S | something |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | |
| 3 | Larry | the Bird |
| # | Name | S | something |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | |
| 3 | Larry | the Bird |
| # | Name | S | something |
|---|---|---|---|
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | @fat |
| 3 | Larry | the Bird | |
| 1 | Mark | Otto | @mdo |
| 2 | Jacob | Thornton | |
| 3 | Larry |
This paragraph contains a bunch of phrase elements. This paragraph contains a bunch of phrase elements. This paragraph contains a bunch of phrase elements. This paragraph contains a bunch of phrase elements. This paragraph contains a bunch of phrase elements. Some text xt xt xt xt This paragraph contains a bunch of phrase elements. This paragraph contains a bunch of phrase elements. This paragraph contains a bunch of phrase elements.
An iframe:
Done


|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Graphics
public abstract class Graphics
The Graphics
class is the abstract base class for
all graphics contexts that allow an application to draw onto
components that are realized on various devices, as well as
onto off-screen images.
A Graphics
object encapsulates state information needed
for the basic rendering operations that Java supports. This
state information includes the following properties:
Component
object on which to draw.
setXORMode(java.awt.Color)
).
Coordinates are infinitely thin and lie between the pixels of the output device. Operations that draw the outline of a figure operate by traversing an infinitely thin path between pixels with a pixel-sized pen that hangs down and to the right of the anchor point on the path. Operations that fill a figure operate by filling the interior of that infinitely thin path. Operations that render horizontal text render the ascending portion of character glyphs entirely above the baseline coordinate.
The graphics pen hangs down and to the right from the path it traverses. This has the following implications:
All coordinates that appear as arguments to the methods of this
Graphics
object are considered relative to the
translation origin of this Graphics
object prior to
the invocation of the method.
All rendering operations modify only pixels which lie within the
area bounded by the current clip, which is specified by a Shape
in user space and is controlled by the program using the
Graphics
object. This user clip
is transformed into device space and combined with the
device clip, which is defined by the visibility of windows and
device extents. The combination of the user clip and device clip
defines the composite clip, which determines the final clipping
region. The user clip cannot be modified by the rendering
system to reflect the resulting composite clip. The user clip can only
be changed through the setClip
or clipRect
methods.
All drawing or writing is done in the current color,
using the current paint mode, and in the current font.
Component
,
clipRect(int, int, int, int)
,
setColor(java.awt.Color)
,
setPaintMode()
,
setXORMode(java.awt.Color)
,
setFont(java.awt.Font)
| Constructor Summary | |
|---|---|
protected |
Graphics()
Constructs a new Graphics object. |
| Method Summary | |
|---|---|
abstract void |
clearRect(int x,
int y,
int width,
int height)
Clears the specified rectangle by filling it with the background color of the current drawing surface. |
abstract void |
clipRect(int x,
int y,
int width,
int height)
Intersects the current clip with the specified rectangle. |
abstract void |
copyArea(int x,
int y,
int width,
int height,
int dx,
int dy)
Copies an area of the component by a distance specified by dx and dy . |
abstract Graphics |
create()
Creates a new Graphics object that is
a copy of this Graphics object. |
Graphics |
create(int x,
int y,
int width,
int height)
Creates a new Graphics object based on this
Graphics object, but with a new translation and clip area. |
abstract void |
dispose()
Disposes of this graphics context and releases any system resources that it is using. |
void |
draw3DRect(int x,
int y,
int width,
int height,
boolean raised)
Draws a 3-D highlighted outline of the specified rectangle. |
abstract void |
drawArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Draws the outline of a circular or elliptical arc covering the specified rectangle. |
void |
drawBytes(byte[] data,
int offset,
int length,
int x,
int y)
Draws the text given by the specified byte array, using this graphics context's current font and color. |
void |
drawChars(char[] data,
int offset,
int length,
int x,
int y)
Draws the text given by the specified character array, using this graphics context's current font and color. |
abstract boolean |
drawImage(Image img,
int x,
int y,
Color bgcolor,
ImageObserver observer)
Draws as much of the specified image as is currently available. |
abstract boolean |
drawImage(Image img,
int x,
int y,
ImageObserver observer)
Draws as much of the specified image as is currently available. |
abstract boolean |
drawImage(Image img,
int x,
int y,
int width,
int height,
Color bgcolor,
ImageObserver observer)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. |
abstract boolean |
drawImage(Image img,
int x,
int y,
int width,
int height,
ImageObserver observer)
Draws as much of the specified image as has already been scaled to fit inside the specified rectangle. |
abstract boolean |
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
Color bgcolor,
ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. |
abstract boolean |
drawImage(Image img,
int dx1,
int dy1,
int dx2,
int dy2,
int sx1,
int sy1,
int sx2,
int sy2,
ImageObserver observer)
Draws as much of the specified area of the specified image as is currently available, scaling it on the fly to fit inside the specified area of the destination drawable surface. |
abstract void |
drawLine(int x1,
int y1,
int x2,
int y2)
Draws a line, using the current color, between the points (x1, y1) and (x2, y2)
in this graphics context's coordinate system. |
abstract void |
drawOval(int x,
int y,
int width,
int height)
Draws the outline of an oval. |
abstract void |
drawPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Draws a closed polygon defined by arrays of x and y coordinates. |
void |
drawPolygon(Polygon p)
Draws the outline of a polygon defined by the specified Polygon object. |
abstract void |
drawPolyline(int[] xPoints,
int[] yPoints,
int nPoints)
Draws a sequence of connected lines defined by arrays of x and y coordinates. |
void |
drawRect(int x,
int y,
int width,
int height)
Draws the outline of the specified rectangle. |
abstract void |
drawRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draws an outlined round-cornered rectangle using this graphics context's current color. |
abstract void |
drawString(AttributedCharacterIterator iterator,
int x,
int y)
Draws the text given by the specified iterator, using this graphics context's current color. |
abstract void |
drawString(String str,
int x,
int y)
Draws the text given by the specified string, using this graphics context's current font and color. |
void |
fill3DRect(int x,
int y,
int width,
int height,
boolean raised)
Paints a 3-D highlighted rectangle filled with the current color. |
abstract void |
fillArc(int x,
int y,
int width,
int height,
int startAngle,
int arcAngle)
Fills a circular or elliptical arc covering the specified rectangle. |
abstract void |
fillOval(int x,
int y,
int width,
int height)
Fills an oval bounded by the specified rectangle with the current color. |
abstract void |
fillPolygon(int[] xPoints,
int[] yPoints,
int nPoints)
Fills a closed polygon defined by arrays of x and y coordinates. |
void |
fillPolygon(Polygon p)
Fills the polygon defined by the specified Polygon object with the graphics context's current color. |
abstract void |
fillRect(int x,
int y,
int width,
int height)
Fills the specified rectangle. |
abstract void |
fillRoundRect(int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Fills the specified rounded corner rectangle with the current color. |
void |
finalize()
Disposes of this graphics context once it is no longer referenced. |
abstract Shape |
getClip()
Gets the current clipping area. |
abstract Rectangle |
getClipBounds()
Returns the bounding rectangle of the current clipping area. |
Rectangle |
getClipBounds(Rectangle r)
Returns the bounding rectangle of the current clipping area. |
Rectangle |
getClipRect()
Deprecated. As of JDK version 1.1, replaced by getClipBounds() . |
abstract Color |
getColor()
Gets this graphics context's current color. |
abstract Font |
getFont()
Gets the current font. |
FontMetrics |
getFontMetrics()
Gets the font metrics of the current font. |
abstract FontMetrics |
getFontMetrics(Font f)
Gets the font metrics for the specified font. |
boolean |
hitClip(int x,
int y,
int width,
int height)
Returns true if the specified rectangular area might intersect the current clipping area. |
abstract void |
setClip(int x,
int y,
int width,
int height)
Sets the current clip to the rectangle specified by the given coordinates. |
abstract void |
setClip(Shape clip)
Sets the current clipping area to an arbitrary clip shape. |
abstract void |
setColor(Color c)
Sets this graphics context's current color to the specified color. |
abstract void |
setFont(Font font)
Sets this graphics context's font to the specified font. |
abstract void |
setPaintMode()
Sets the paint mode of this graphics context to overwrite the destination with this graphics context's current color. |
abstract void |
setXORMode(Color c1)
Sets the paint mode of this graphics context to alternate between this graphics context's current color and the new specified color. |
String |
toString()
Returns a String object representing this
Graphics object's value. |
abstract void |
translate(int x,
int y)
Translates the origin of the graphics context to the point (x, y) in the current coordinate system. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected Graphics()
Graphics
object.
This constructor is the default contructor for a graphics
context.
Since Graphics
is an abstract class, applications
cannot call this constructor directly. Graphics contexts are
obtained from other graphics contexts or are created by calling
getGraphics
on a component.
create()
,
Component.getGraphics()
| Method Detail |
|---|
public abstract Graphics create()
Graphics
object that is
a copy of this Graphics
object.
public Graphics create(int x, int y, int width, int height)
Graphics
object based on this
Graphics
object, but with a new translation and clip area.
The new Graphics
object has its origin
translated to the specified point (x, y).
Its clip area is determined by the intersection of the original
clip area with the specified rectangle. The arguments are all
interpreted in the coordinate system of the original
Graphics
object. The new graphics context is
identical to the original, except in two respects:
0
, 0
) in the
new graphics context is the same as (x, y) in
the original graphics context.
0
, 0
), and its size
is specified by the width
and height
arguments.
x
- the x coordinate.y
- the y coordinate.width
- the width of the clipping rectangle.height
- the height of the clipping rectangle.
translate(int, int)
,
clipRect(int, int, int, int)
public abstract void translate(int x, int y)
x
- the x coordinate.y
- the y coordinate.public abstract Color getColor()
Color
,
setColor(Color)
public abstract void setColor(Color c)
c
- the new rendering color.Color
,
getColor()
public abstract void setPaintMode()
public abstract void setXORMode(Color c1)
When drawing operations are performed, pixels which are the current color are changed to the specified color, and vice versa.
Pixels that are of colors other than those two colors are changed in an unpredictable but reversible manner; if the same figure is drawn twice, then all pixels are restored to their original values.
c1
- the XOR alternation colorpublic abstract Font getFont()
Font
,
setFont(Font)
public abstract void setFont(Font font)
font
- the font.getFont()
,
drawString(java.lang.String, int, int)
,
drawBytes(byte[], int, int, int, int)
,
drawChars(char[], int, int, int, int)
public FontMetrics getFontMetrics()
getFont()
,
FontMetrics
,
getFontMetrics(Font)
public abstract FontMetrics getFontMetrics(Font f)
f
- the specified font
getFont()
,
FontMetrics
,
getFontMetrics()
public abstract Rectangle getClipBounds()
setClip(null)
, this method returns
null
.
The coordinates in the rectangle are relative to the coordinate
system origin of this graphics context.
null
if no clip is set.getClip()
,
clipRect(int, int, int, int)
,
setClip(int, int, int, int)
,
setClip(Shape)
public abstract void clipRect(int x, int y, int width, int height)
setClip(null)
,
the specified rectangle becomes the new clip.
This method sets the user clip, which is independent of the
clipping associated with device bounds and window visibility.
This method can only be used to make the current clip smaller.
To set the current clip larger, use any of the setClip methods.
Rendering operations have no effect outside of the clipping area.
x
- the x coordinate of the rectangle to intersect the clip withy
- the y coordinate of the rectangle to intersect the clip withwidth
- the width of the rectangle to intersect the clip withheight
- the height of the rectangle to intersect the clip withsetClip(int, int, int, int)
,
setClip(Shape)
public abstract void setClip(int x, int y, int width, int height)
x
- the x coordinate of the new clip rectangle.y
- the y coordinate of the new clip rectangle.width
- the width of the new clip rectangle.height
- the height of the new clip rectangle.clipRect(int, int, int, int)
,
setClip(Shape)
,
getClip()
public abstract Shape getClip()
setClip(null)
, this method returns
null
.
Shape
object representing the
current clipping area, or null
if
no clip is set.getClipBounds()
,
clipRect(int, int, int, int)
,
setClip(int, int, int, int)
,
setClip(Shape)
public abstract void setClip(Shape clip)
Shape
interface can be used to set the clip. The only
Shape
objects that are guaranteed to be
supported are Shape
objects that are
obtained via the getClip
method and via
Rectangle
objects. This method sets the
user clip, which is independent of the clipping associated
with device bounds and window visibility.
clip
- the Shape
to use to set the clipgetClip()
,
clipRect(int, int, int, int)
,
setClip(int, int, int, int)
public abstract void copyArea(int x, int y, int width, int height, int dx, int dy)
dx
and dy
. From the point specified
by x
and y
, this method
copies downwards and to the right. To copy an area of the
component to the left or upwards, specify a negative value for
dx
or dy
.
If a portion of the source rectangle lies outside the bounds
of the component, or is obscured by another window or component,
copyArea
will be unable to copy the associated
pixels. The area that is omitted can be refreshed by calling
the component's paint
method.
x
- the x coordinate of the source rectangle.y
- the y coordinate of the source rectangle.width
- the width of the source rectangle.height
- the height of the source rectangle.dx
- the horizontal distance to copy the pixels.dy
- the vertical distance to copy the pixels.public abstract void drawLine(int x1, int y1, int x2, int y2)
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system.
x1
- the first point's x coordinate.y1
- the first point's y coordinate.x2
- the second point's x coordinate.y2
- the second point's y coordinate.public abstract void fillRect(int x, int y, int width, int height)
x
and x + width - 1
.
The top and bottom edges are at
y
and y + height - 1
.
The resulting rectangle covers an area
width
pixels wide by
height
pixels tall.
The rectangle is filled using the graphics context's current color.
x
- the x coordinate
of the rectangle to be filled.y
- the y coordinate
of the rectangle to be filled.width
- the width of the rectangle to be filled.height
- the height of the rectangle to be filled.clearRect(int, int, int, int)
,
drawRect(int, int, int, int)
public void drawRect(int x, int y, int width, int height)
x
and x + width
.
The top and bottom edges are at
y
and y + height
.
The rectangle is drawn using the graphics context's current color.
x
- the x coordinate
of the rectangle to be drawn.y
- the y coordinate
of the rectangle to be drawn.width
- the width of the rectangle to be drawn.height
- the height of the rectangle to be drawn.fillRect(int, int, int, int)
,
clearRect(int, int, int, int)
public abstract void clearRect(int x, int y, int width, int height)
Beginning with Java 1.1, the background color
of offscreen images may be system dependent. Applications should
use setColor
followed by fillRect
to
ensure that an offscreen image is cleared to a specific color.
x
- the x coordinate of the rectangle to clear.y
- the y coordinate of the rectangle to clear.width
- the width of the rectangle to clear.height
- the height of the rectangle to clear.fillRect(int, int, int, int)
,
drawRect(int, int, int, int)
,
setColor(java.awt.Color)
,
setPaintMode()
,
setXORMode(java.awt.Color)
public abstract void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
x
and x + width
,
respectively. The top and bottom edges of the rectangle are at
y
and y + height
.
x
- the x coordinate of the rectangle to be drawn.y
- the y coordinate of the rectangle to be drawn.width
- the width of the rectangle to be drawn.height
- the height of the rectangle to be drawn.arcWidth
- the horizontal diameter of the arc
at the four corners.arcHeight
- the vertical diameter of the arc
at the four corners.fillRoundRect(int, int, int, int, int, int)
public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
x
and x + width - 1
,
respectively. The top and bottom edges of the rectangle are at
y
and y + height - 1
.
x
- the x coordinate of the rectangle to be filled.y
- the y coordinate of the rectangle to be filled.width
- the width of the rectangle to be filled.height
- the height of the rectangle to be filled.arcWidth
- the horizontal diameter
of the arc at the four corners.arcHeight
- the vertical diameter
of the arc at the four corners.drawRoundRect(int, int, int, int, int, int)
public void draw3DRect(int x, int y, int width, int height, boolean raised)
The colors used for the highlighting effect are determined
based on the current color.
The resulting rectangle covers an area that is
width + 1
pixels wide
by height + 1
pixels tall.
x
- the x coordinate of the rectangle to be drawn.y
- the y coordinate of the rectangle to be drawn.width
- the width of the rectangle to be drawn.height
- the height of the rectangle to be drawn.raised
- a boolean that determines whether the rectangle
appears to be raised above the surface
or sunk into the surface.fill3DRect(int, int, int, int, boolean)
public void fill3DRect(int x, int y, int width, int height, boolean raised)
x
- the x coordinate of the rectangle to be filled.y
- the y coordinate of the rectangle to be filled.width
- the width of the rectangle to be filled.height
- the height of the rectangle to be filled.raised
- a boolean value that determines whether the
rectangle appears to be raised above the surface
or etched into the surface.draw3DRect(int, int, int, int, boolean)
public abstract void drawOval(int x, int y, int width, int height)
x
, y
,
width
, and height
arguments.
The oval covers an area that is
width + 1
pixels wide
and height + 1
pixels tall.
x
- the x coordinate of the upper left
corner of the oval to be drawn.y
- the y coordinate of the upper left
corner of the oval to be drawn.width
- the width of the oval to be drawn.height
- the height of the oval to be drawn.fillOval(int, int, int, int)
public abstract void fillOval(int x, int y, int width, int height)
x
- the x coordinate of the upper left corner
of the oval to be filled.y
- the y coordinate of the upper left corner
of the oval to be filled.width
- the width of the oval to be filled.height
- the height of the oval to be filled.drawOval(int, int, int, int)
public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)
The resulting arc begins at startAngle
and extends
for arcAngle
degrees, using the current color.
Angles are interpreted such that 0 degrees
is at the 3 o'clock position.

The center of the arc is the center of the rectangle whose origin
is (x, y) and whose size is specified by the
width
and height
arguments.
The resulting arc covers an area
width + 1
pixels wide
by height + 1
pixels tall.
The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
x
- the x coordinate of the
upper-left corner of the arc to be drawn.y
- the y coordinate of the
upper-left corner of the arc to be drawn.width
- the width of the arc to be drawn.height
- the height of the arc to be drawn.startAngle
- the beginning angle.arcAngle
- the angular extent of the arc,
relative to the start angle.fillArc(int, int, int, int, int, int)
public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle)
The resulting arc begins at startAngle
and extends
for arcAngle
degrees.
Angles are interpreted such that 0 degrees
is at the 3 o'clock position.

The center of the arc is the center of the rectangle whose origin
is (x, y) and whose size is specified by the
width
and height
arguments.
The resulting arc covers an area
width + 1
pixels wide
by height + 1
pixels tall.
The angles are specified relative to the non-square extents of the bounding rectangle such that 45 degrees always falls on the line from the center of the ellipse to the upper right corner of the bounding rectangle. As a result, if the bounding rectangle is noticeably longer in one axis than the other, the angles to the start and end of the arc segment will be skewed farther along the longer axis of the bounds.
x
- the x coordinate of the
upper-left corner of the arc to be filled.y
- the y coordinate of the
upper-left corner of the arc to be filled.width
- the width of the arc to be filled.height
- the height of the arc to be filled.startAngle
- the beginning angle.arcAngle
- the angular extent of the arc,
relative to the start angle.drawArc(int, int, int, int, int, int)
public abstract void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
xPoints
- an array of x pointsyPoints
- an array of y pointsnPoints
- the total number of pointsdrawPolygon(int[], int[], int)
public abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
This method draws the polygon defined by nPoint
line
segments, where the first nPoint - 1
line segments are line segments from
(xPoints[i - 1], yPoints[i - 1])
to (xPoints[i], yPoints[i])
, for
1 ≤ i ≤ nPoints
.
The figure is automatically closed by drawing a line connecting
the final point to the first point, if those points are different.
xPoints
- a an array of x
coordinates.yPoints
- a an array of y
coordinates.nPoints
- a the total number of points.fillPolygon(int[], int[], int)
,
drawPolyline(int[], int[], int)
public void drawPolygon(Polygon p)
Polygon
object.
p
- the polygon to draw.fillPolygon(int[], int[], int)
,
drawPolyline(int[], int[], int)
public abstract void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
This method draws the polygon defined by nPoint
line
segments, where the first nPoint - 1
line segments are line segments from
(xPoints[i - 1], yPoints[i - 1])
to (xPoints[i], yPoints[i])
, for
1 ≤ i ≤ nPoints
.
The figure is automatically closed by drawing a line connecting
the final point to the first point, if those points are different.
The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.
xPoints
- a an array of x
coordinates.yPoints
- a an array of y
coordinates.nPoints
- a the total number of points.drawPolygon(int[], int[], int)
public void fillPolygon(Polygon p)
The area inside the polygon is defined using an even-odd fill rule, also known as the alternating rule.
p
- the polygon to fill.drawPolygon(int[], int[], int)
public abstract void drawString(String str, int x, int y)
str
- the string to be drawn.x
- the x coordinate.y
- the y coordinate.drawBytes(byte[], int, int, int, int)
,
drawChars(char[], int, int, int, int)
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y)
iterator
- the iterator whose text is to be drawnx
- the x coordinate.y
- the y coordinate.drawBytes(byte[], int, int, int, int)
,
drawChars(char[], int, int, int, int)
public void drawChars(char[] data, int offset, int length, int x, int y)
data
- the array of characters to be drawnoffset
- the start offset in the datalength
- the number of characters to be drawnx
- the x coordinate of the baseline of the texty
- the y coordinate of the baseline of the textdrawBytes(byte[], int, int, int, int)
,
drawString(java.lang.String, int, int)
public void drawBytes(byte[] data, int offset, int length, int x, int y)
data
- the data to be drawnoffset
- the start offset in the datalength
- the number of bytes that are drawnx
- the x coordinate of the baseline of the texty
- the y coordinate of the baseline of the textdrawChars(char[], int, int, int, int)
,
drawString(java.lang.String, int, int)
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer)
This method returns immediately in all cases, even if the complete image has not yet been loaded, and it has not been dithered and converted for the current output device.
If the image has completely loaded and its pixels are
no longer being changed, then
drawImage
returns true
.
Otherwise, drawImage
returns false
and as more of
the image becomes available
or it is time to draw another frame of animation,
the process that loads the image notifies
the specified image observer.
img
- the specified image to be drawn. This method does
nothing if img
is null.x
- the x coordinate.y
- the y coordinate.observer
- object to be notified as more of
the image is converted.
false
if the image pixels are still changing;
true
otherwise.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
The image is drawn inside the specified rectangle of this graphics context's coordinate space, and is scaled if necessary. Transparent pixels do not affect whatever pixels are already there.
This method returns immediately in all cases, even if the
entire image has not yet been scaled, dithered, and converted
for the current output device.
If the current output representation is not yet complete, then
drawImage
returns false
. As more of
the image becomes available, the process that loads the image notifies
the image observer by calling its imageUpdate
method.
A scaled version of an image will not necessarily be available immediately just because an unscaled version of the image has been constructed for this output device. Each size of the image may be cached separately and generated from the original data in a separate image production sequence.
img
- the specified image to be drawn. This method does
nothing if img
is null.x
- the x coordinate.y
- the y coordinate.width
- the width of the rectangle.height
- the height of the rectangle.observer
- object to be notified as more of
the image is converted.
false
if the image pixels are still changing;
true
otherwise.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer)
This operation is equivalent to filling a rectangle of the width and height of the specified image with the given color and then drawing the image on top of it, but possibly more efficient.
This method returns immediately in all cases, even if the complete image has not yet been loaded, and it has not been dithered and converted for the current output device.
If the image has completely loaded and its pixels are
no longer being changed, then
drawImage
returns true
.
Otherwise, drawImage
returns false
and as more of
the image becomes available
or it is time to draw another frame of animation,
the process that loads the image notifies
the specified image observer.
img
- the specified image to be drawn. This method does
nothing if img
is null.x
- the x coordinate.y
- the y coordinate.bgcolor
- the background color to paint under the
non-opaque portions of the image.observer
- object to be notified as more of
the image is converted.
false
if the image pixels are still changing;
true
otherwise.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
The image is drawn inside the specified rectangle of this graphics context's coordinate space, and is scaled if necessary. Transparent pixels are drawn in the specified background color. This operation is equivalent to filling a rectangle of the width and height of the specified image with the given color and then drawing the image on top of it, but possibly more efficient.
This method returns immediately in all cases, even if the
entire image has not yet been scaled, dithered, and converted
for the current output device.
If the current output representation is not yet complete then
drawImage
returns false
. As more of
the image becomes available, the process that loads the image notifies
the specified image observer.
A scaled version of an image will not necessarily be available immediately just because an unscaled version of the image has been constructed for this output device. Each size of the image may be cached separately and generated from the original data in a separate image production sequence.
img
- the specified image to be drawn. This method does
nothing if img
is null.x
- the x coordinate.y
- the y coordinate.width
- the width of the rectangle.height
- the height of the rectangle.bgcolor
- the background color to paint under the
non-opaque portions of the image.observer
- object to be notified as more of
the image is converted.
false
if the image pixels are still changing;
true
otherwise.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer)
This method returns immediately in all cases, even if the
image area to be drawn has not yet been scaled, dithered, and converted
for the current output device.
If the current output representation is not yet complete then
drawImage
returns false
. As more of
the image becomes available, the process that loads the image notifies
the specified image observer.
This method always uses the unscaled version of the image to render the scaled rectangle and performs the required scaling on the fly. It does not use a cached, scaled version of the image for this operation. Scaling of the image from source to destination is performed such that the first coordinate of the source rectangle is mapped to the first coordinate of the destination rectangle, and the second source coordinate is mapped to the second destination coordinate. The subimage is scaled and flipped as needed to preserve those mappings.
img
- the specified image to be drawn. This method does
nothing if img
is null.dx1
- the x coordinate of the first corner of the
destination rectangle.dy1
- the y coordinate of the first corner of the
destination rectangle.dx2
- the x coordinate of the second corner of the
destination rectangle.dy2
- the y coordinate of the second corner of the
destination rectangle.sx1
- the x coordinate of the first corner of the
source rectangle.sy1
- the y coordinate of the first corner of the
source rectangle.sx2
- the x coordinate of the second corner of the
source rectangle.sy2
- the y coordinate of the second corner of the
source rectangle.observer
- object to be notified as more of the image is
scaled and converted.
false
if the image pixels are still changing;
true
otherwise.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
Transparent pixels are drawn in the specified background color. This operation is equivalent to filling a rectangle of the width and height of the specified image with the given color and then drawing the image on top of it, but possibly more efficient.
This method returns immediately in all cases, even if the
image area to be drawn has not yet been scaled, dithered, and converted
for the current output device.
If the current output representation is not yet complete then
drawImage
returns false
. As more of
the image becomes available, the process that loads the image notifies
the specified image observer.
This method always uses the unscaled version of the image to render the scaled rectangle and performs the required scaling on the fly. It does not use a cached, scaled version of the image for this operation. Scaling of the image from source to destination is performed such that the first coordinate of the source rectangle is mapped to the first coordinate of the destination rectangle, and the second source coordinate is mapped to the second destination coordinate. The subimage is scaled and flipped as needed to preserve those mappings.
img
- the specified image to be drawn. This method does
nothing if img
is null.dx1
- the x coordinate of the first corner of the
destination rectangle.dy1
- the y coordinate of the first corner of the
destination rectangle.dx2
- the x coordinate of the second corner of the
destination rectangle.dy2
- the y coordinate of the second corner of the
destination rectangle.sx1
- the x coordinate of the first corner of the
source rectangle.sy1
- the y coordinate of the first corner of the
source rectangle.sx2
- the x coordinate of the second corner of the
source rectangle.sy2
- the y coordinate of the second corner of the
source rectangle.bgcolor
- the background color to paint under the
non-opaque portions of the image.observer
- object to be notified as more of the image is
scaled and converted.
false
if the image pixels are still changing;
true
otherwise.Image
,
ImageObserver
,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
public abstract void dispose()
Graphics
object cannot be used after
dispose
has been called.
When a Java program runs, a large number of Graphics
objects can be created within a short time frame.
Although the finalization process of the garbage collector
also disposes of the same system resources, it is preferable
to manually free the associated resources by calling this
method rather than to rely on a finalization process which
may not run to completion for a long period of time.
Graphics objects which are provided as arguments to the
paint
and update
methods
of components are automatically released by the system when
those methods return. For efficiency, programmers should
call dispose
when finished using
a Graphics
object only if it was created
directly from a component or another Graphics
object.
finalize()
,
Component.paint(java.awt.Graphics)
,
Component.update(java.awt.Graphics)
,
Component.getGraphics()
,
create()
public void finalize()
finalize
in class Object
dispose()
public String toString()
String
object representing this
Graphics
object's value.
toString
in class Object
@Deprecated public Rectangle getClipRect()
getClipBounds()
.
null
if no clip is set.public boolean hitClip(int x, int y, int width, int height)
x
- the x coordinate of the rectangle to test against the clipy
- the y coordinate of the rectangle to test against the clipwidth
- the width of the rectangle to test against the clipheight
- the height of the rectangle to test against the clip
true
if the specified rectangle intersects
the bounds of the current clip; false
otherwise.public Rectangle getClipBounds(Rectangle r)
getClipBounds
in that an existing
rectangle is used instead of allocating a new one.
This method refers to the user clip, which is independent of the
clipping associated with device bounds and window visibility.
If no clip has previously been set, or if the clip has been
cleared using setClip(null)
, this method returns the
specified Rectangle
.
r
- the rectangle where the current clipping area is
copied to. Any current values in this rectangle are
overwritten.
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.


Password Generator
Password Generator
Choose the length of your password. Must be between 8-128 characters
Number
Symbol
Uppercase Letters
Lowercase Letters
Submit


Indeterminate loader keeps moving around until told to stop, this loader gives a sense that item is under progress but it's uncertain about the completion of the task.
noscript


Put web site in field and push "Send"
This is test web site for measure sub html`s in page, which you entered.
Coming soon:
checking for valid html!!
change speedl!!


Action
Another action
Something else here
Edit information
First Name:
Last Name:
Phone Number:
Email:
LinkedIn:
GitHub:
Facebook:
Edit About Me:
Save Changes
Erase Changes


This Privacy Policy was last modified on December 12, 2014.
Textalysis ("us", "we", or "our") operates http://www.textalysis.tech/ (the "Site"). This page informs you of our policies regarding the collection, use and disclosure of Personal Information we receive from users of the Site.
Information Collection And Use
While using our Site, we may ask you to provide us with certain personally identifiable information that can be used to contact or identify you. Personally identifiable information may include, but is not limited to, your name, email address, and phone number ("Personal Information").
Log Data
Like many site operators, we collect information that your browser sends whenever you visit our Site ("Log Data"). This Log Data may include information such as your computer's Internet Protocol ("IP") address, browser type, browser version, the pages of our Site that you visit, the time and date of your visit, the time spent on those pages and other statistics.
Cookies
Cookies are files with small amount of data, which may include an anonymous unique identifier. Cookies are sent to your browser from a web site and stored on your computer's hard drive.
Like many sites, we use "cookies" to collect information. You can instruct your browser to refuse all cookies or to indicate when a cookie is being sent. However, if you do not accept cookies, you may not be able to use some portions of our Site.
Security
The security of your Information is important to us, but remember that no method of transmission over the Internet, or method of electronic storage, is 100% secure. While we strive to use commercially acceptable means to protect your Information, we cannot guarantee its absolute security.
We adopt appropriate data collection, storage and processing practices and security measures to protect against unauthorized access, alteration, disclosure or destruction of your personal information, username, password, transaction information and data stored on our Site. Sensitive and private data exchange between the Site and its Users happens over a SSL secured communication channel and is encrypted and protected with digital signatures. Communication with our backend servers happens purely over HTTP.
We do not sell, trade, or rent any of your data to others. We may share generic aggregated demographic information not linked to any personal identification information regarding visitors and users with our business partners, trusted affiliates and advertisers for the purposes outlined above. Data may only be shared with State authorities in case of any legal obligation arising out of any situation.
Acceptance of terms
By using this Site, you signify your acceptance of this policy. If you do not agree to this policy, please do not use our Site. Your continued use of the Site following the posting of changes to this policy will be deemed your acceptance of those changes.
Links To Other Sites
Our Site may contain links to other sites that are not operated by us. If you click on a third party link, you will be directed to that third party's site. We strongly advise you to review the Privacy Policy of every site you visit.
Textalysis has no control over, and assumes no responsibility for, the content, privacy policies, or practices of any third party sites or services.
Changes To This Privacy Policy
Textalysis may update this Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on the Site. You are advised to review this Privacy Policy periodically for any changes.
Contact Us
If you have any questions about this Privacy Policy, please contact us.


Encoder, Exploiter, Diffuser: Les humanités numériques dans les projets de recherche
University of Poitiers
12 February 2020
Twitter: #enexdi2020
Greta H. Franzini
Also known as TERMINAL in Unix systems.
A user interface to type commands directly to the machine
Why use it in NLP?
Test corpus
Normalised 17th century French drama (36 works, 8 authors)
Let's say we want to:
For our calculations and the use of many NLP tools, the corpus needs to meet these requirements:
The corpus
Move into the corpus directory
cd EnExDi2020/data-nlp/corpus
Open a file
cat BOYER_AGAMEMNON.xml
Merge all files into a single file
cat *.xml > corpus.xml
Open the file. What do you notice?
Remove all XML tags from the file
cat corpus.xml | sed 's/\<[^<>]*\>//g' > corpus.txt
Warning! If this command has the opposite effect (i.e. it keeps all the markup and deletes the text), change the command to:
cat corpus.xml | sed 's/<[^<>]*>//g' > corpus.txt
Open corpus.txt
cat corpus.txt
Delete punctuation
cat corpus.txt | tr -d '[:punct:]'
Text as single column of words
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n'
Remove blank lines
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d'
Save the file
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d' > corpus-tokens.txt
UPPER CASE > lower case
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d' | tr '[:upper:]' '[:lower:]'
Sort words alphabetically
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d' | tr '[:upper:]' '[:lower:]' | sort
Reverse sort
sort -r
Group duplicates in a single entry
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d' | tr '[:upper:]' '[:lower:]' | sort | uniq -c
Count the number of unique words in the corpus
= lines in the file
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d' | tr '[:upper:]' '[:lower:]' | sort | uniq -c | wc -l
Save results to a new file
cat corpus.txt | tr -d '[:punct:]' | tr '[:space:]' '\n' | sed '/^\s*$/d' | tr '[:upper:]' '[:lower:]' | sort | uniq -c > corpus-types.txt
Add text/corpus to the main treetagger folder as a clean raw text file
In our case, the text file is corpus-tokens.txt
Mac OSX and Linux
Open the command line and navigate to Desktop/treetagger
To tag a text with the french.par parameter:
cat corpus-tokens.txt | cmd/tree-tagger-french > corpus.tagged
Windows
Open the command prompt (NOT Cygwin)* and navigate to Desktop/treetagger
To tag a text with the french.par parameter:
tag-french corpus.txt > corpus.tagged
* TreeTagger and Cygwin are not compatible!
Open the corpus.tagged file with cat
Three columns:
form PoS lemma
Tagging accuracy
Try with your own text!
RegEx Tutorials
cat file.txt | grep "ciao"
Matches all occurrences of ciao in the file file.txt
cat file.txt | grep "window"
Matches all occurrences of window in the file file.txt
cat file.txt | grep -e "ciao" -e "addio"
Matches all occurrences of ciao and addio in a string in file.txt
egrep 'hello there' file.txt
to search for a specific string of text
\t(?=[a-z]): lookahead command matching a tab that is followed by text
\t(?!,): lookahead command matching tabs not followed by a comma; the ?! operator is a negation
(?<=[0-9])\t: lookbehind command matching a tab that is preceeded by a number
\w*: matches all words/text (not numbers)
chardetect file.txt gives me the character encoding of file.txt
df to reveal the amount of storage space in the current directory
top to view all running processes on a machine
| Windows | Description | Unix |
dir |
Show contents | ls |
cd |
Present Working Directory | pwd |
cd path/to/directory |
Change directory | cd path/to/directory |
cd.. |
Up one directory | cd .. |
cd |
Back to root directory | cd / |
mkdir nuovaCartella |
Create new folder | mkdir nuovaCartella |
echo some-text > fileName(.txt) |
Create new file | touch fileName(.txt) |
rmdir myFolder |
Remove folder* | rmdir myFolder |
ren oldFolderName newFolderName |
Rename folder | mv oldFolderName newFolderName |
robocopy myFolder path/to/destination/directory |
Copy a folder | cp -r myFolder path/to/destination/directory |
move myFolder path/to/destination/directory |
Move a folder | mv myFolder path/to/destination/directory |
del myFile |
Remove a file* | rm myFile |
ren oldFileName newFileName |
Rename a file | mv oldFileName newFileName |
copy myFile path/to/destination/directory |
Copy a file | cp myFile path/to/destination/directory |
move myFile path/to/destination/directory |
Move a file | mv myFile path/to/destination/directory |
cls |
Clear screen | clear |
type |
Open a file | cat |
type C:/../myFile.txt| find "" /v /c |
Count lines in a file | wc -l myFile(.txt) |
*NB: the delete command DOES NOT ask for confirmation.


{% extends 'layout.html' %} {% block content %}
|
Dear {{ message_content.get('name', '')|title }},
Its awesome to see your showing in one of our 1000+ verified co-working space.
We have shortlisted the following spaces matching your requirement. (Use the "Visit this Space" button if you want us to fix up a visit to the space. We will send you the required details as soon as we receive your request) |
|
|
|
|
You may also like to visit the following spaces specially designed for you.
|


This tutorial contains a few samples that details how type classes might be useful in Scala, as well as some tricks and tips you might not have seen before.
Type classes are a particularly useful abstraction in languages that have mechanisms to support them. They are a way of adding behavior to standard data classes (like case class domain objects and collections, for example) without needing to alter those classes directly, instead implicitly (in Scala at least) providing definitions of a type class for the type you want to add the behavior to. This is sometimes called ad-hoc polymorphism and more detail on the theory can be found on wikipedia.
There are many good libraries already available for Scala that take advantage of type classes for this kind of usage. For example, the Play Framework's own JSON support makes use of type classes like Format, Reads and Writes to make it easy to convert to and from JSON. The real advantage of type-classes over more traditional approaches to this problem like reflection is that more issues (like missing conversions, for example) can be detected by the compiler rather than just resulting in errors at runtime.
For these examples, we will be using Spray's JSON library rather than the Play Framework's mainly because the Spray JSON library is smaller and written very clearly, with only one purpose in mind - to convert items to and from JSON with a minimum of effort. If you are already using Play on a project then the tips and tricks demonstrated here can easily be adapted. There is also an alternative implementation which demonstrates a simple (and limited) example of targeting XML rather than JSON for the output as well.
Let's take a look at the code, move to the next page to continue the tutorial.
Let's look at a type class definition, starting with the JSON Savable first.
The Savable
defined in the json package is the definition of something that when provided,
will give a String output for a given item input, in this case we will implement the
string output to provide JSON for the item. First let's look at the Savable
class at the top of this file.
The Savable
class is parameterized with a single generic type. This is part of
the nature of a type class - it only makes sense to have one defined with a type parameter
because when you extend it or otherwise implement it, you want to do so for a specific type
so that it provides the extra functionality for that type.
The
abstract class Savable[RECORD <: Product : ClassManifest]
definition has
a fair amount going on in the type department so let's pull it apart. The first thing is that
the generic is called RECORD
. I used a longer name to make things clearer, but
it's quite common to see individual letters used to represent type parameters (I think because
programmers are lazy by nature :-) ).
RECORD <: Product
means that the RECORD parameter is bound to extend
Product. Bound in this
case means that the Scala compiler enforces this constraint, and it means that you know
any item of type RECORD will provide the methods defined on Product. Product is a
trait that is mixed in to a number of Scala classes and implementation including Tuples
and case classes, and it allows certain operations on the data inside those classes.
<:
is known as an upper bound (it means that the RECORD generic is bound at the upper
end by Product. I like to use mnemonics to read code and understand it, and since the bound has a
"less than" operator in it, I read it as RECORD implements at least Product.
There is another type bound on the generic, the : ClassManifest
.
: T
is known as a context bound, and it means that there must be a type class for RECORD (in this case)
that the compiler can see and use implicitly (or you may choose to fill it in explicitly if you
like pain). : ClassManifest
is the same as having an implicit parameter of type
ClassManifest[RECORD]
, like this:
abstract class Savable[RECORD <: Product](implicit ev1: ClassManifest[RECORD])
the context bound form is just shorthand for that implicit (but it also means it doesn't have
a name, so we need to get that ClassManifest using the implicitly method:
val ev1 = implicitly[ClassManifest[RECORD]]
is an example of doing that,
and assigns it to the same ev1 value as used in the implicit parameter example.
Manifests, ClassManifests and ClassTags are type classes but they are also known by the Scala compiler and exhibit very useful behavior. When Scala sees a Manifest or Tag type class specified implicitly, it creates one for the type being passed in, so that you can get type information that can be used at runtime. Manifests are deep (i.e. for complex container types, they hold all of the information of the type parameters in the container type as well) while ClassTags are shallow (like just having the classOf[RECORD] information filled in by the compiler.
The general rule of thumb is to use ClassTags (which are lighter and faster) unless you need the deep information of a Manifest. ClassManifest (used here) is actually deprecated, but right now the Spray JSON library still uses them, so I had to use them in this example. Typically use a ClassTag instead of a ClassManifest.
Within the definition of the abstract Savable class, we have a few interesting things as well:
implicit val saveableAdapter: Savable[RECORD] = this
bears some
explanation. The Savable class, and it's subclasses Savable1..SavableN (also abstract) are
designed to be extended by companion objects to classes. Implicits inside of the companion
object for a class are automatically available to the compiler to be able to use to satisfy
context bounds, so by setting an implicit val
of type Savable[RECORD]
and using a self reference this
as the value, we make the companion object also
satisfy the requirement for an implicit Savable within itself. It's a neat trick that works
fairly well in practice and lets you define more streamlined type classes, as we will see
in a minute.
implicit val jsonFormat: JsonFormat[RECORD]
is a pure abstract, and
means that any implementing class must supply a JsonFormat type class for RECORD as a part of
its implementation contract. These will be filled in by Savable1..Savable2, etc. and need to
be a different implementation for each based on the arity of the class represented. Having this
requirement in the Savable class means that any Savable also must have a JsonFormat defined for it,
an implementation detail that is useful for our purposes. However if Savable meant something other
than JSON (e.g. XML, SQL, etc.) then we could drop that requirement and add another. The point is
that we have raised the abstraction level from a specific format or serialization to something that
is simply "Savable".
The final two lines just give us a handy string name for the RECORD based on its Manifest information, and a pretty toString for it so it's easy to spot in diagnostic messages, stack traces and so on.
Also supplied in Savable.scala are the definitions of the
Savable1, Savable2, Savable3
and Savable4
classes.
For a real system these would probably go higher
(all the way up to 22 is conventional), and are prime candidates for either some kind
of code generation or macro generation.
Let's take a look at Savable2
to choose just one of them, the rest use the same
principle other than the arity changing.
abstract class Savable2[A : JsonFormat, B : JsonFormat,
RECORD <: Product : ClassManifest] extends Savable[RECORD] {
is the definition of
the class. It is still abstract, since we don't want people creating new instance of this
class directly. Instead it should be extended by a companion object, and ideally one for a
case class
. More on why in a moment.
Notice that this Savable2 has 3 type parameters, A, B and RECORD. RECORD is the type for which this is the companion (this might make more sense when you see the definition later). The other types, A and B are any types (they will actually need to agree with the types used for those field positions in the case class) and they have a context bound on them also which is that they must have a JsonFormat supplied as well. This kind of "recursive" context bounding is very useful for ensuring that all the types, all the way down, can be converted to JSON. If you remember, creating a Savable also means that a JsonFormat must be available for that type, so it means we can nest Savables into each other as well as other JsonFormat types (including types like Int, Double, String, Boolean, etc.)
Notice also that each of the SavableNs extend Savable[RECORD] so that we can refer to just a generic Savable wherever we want to use it, rather than Savable2 or Savable3.
The body of Savable2 has two items defined in it:
def apply(f1: A, f2: B): RECORD
val jsonFormat: JsonFormat[RECORD] = jsonFormat2(this.apply)
The first line states that we must have an apply
method that takes two parameters,
one of type A and one of type B. The definition of a case class
is such that apply
(and unapply) methods are created with suitable signatures. This means that if we extend Savable2
in the companion object of a case class arity 2, we will satisfy that requirement. It also means
you can use Savable2 for non-case classes, but if you do you will be required to supply a suitable
apply method.
The second line is the implementation of the JsonFormat for RECORD. Spray JSON supplies handy
helper methods for anything that has a suitable apply method (i.e this.apply), in this case
jsonFormat2
but for other arities, change the number. You could also supply a
more explicit version of this JsonFormat[RECORD] which you may need to do for more customized
behavior. Take a look at the Spray JSON
documentation for more options on providing a JsonFormat.
Of course, all of this is a minimal example and a real implementation will probably have a lot more code in the Savables, but the point is that this code is only written once and will be available to any companion object that extends the SavableN class, meaning you can pack a lot of useful behavior into a single line definition.
Speaking of single line definitions, let's take a look at how we can use these Savables.
Now take a look at ExampleDomainObjects.scala. Here you will see a number of definitions like this:
case class Dog(name: String, age: Int, weight: Float)
object Dog extends Savable3[String, Int, Float, Dog]
The first line is the definition of a pure case class, one that has fields for name, age
and weight of a dog, types String, Int and Float respectively. There is nothing special
about this definition other than that we have made it a case class (primarily so it is a
Product
and has apply
and unapply
methods generated
for us in the companion object
The next line is the definition of our companion object for Dog. The resulting companion
object will still have apply
and unapply
methods generated for us, and will still have
the Product
trait supported, but we are also going to include all of our Savable
logic as well, by extending the Savable3
abstract class as well.
Savable3
takes 4 type parameters. The first three must match the types
of the fields in the case class (i.e. String, Int
and Float
and the
last must be the type we are defining the Savable for (i.e. Dog
). This is a bit of
boilerplate, but it's not much (not for everything we get) and the compiler will ensure you get
it right. Try changing the Int to a Double for example, to see what the compiler says, then
change it back to get everything compiling again.
This one line of code makes our Dog case class a Savable thing. It does mean that we have some concept of Savable in our domain objects now, so they are no longer completely pure, but as we will see in a minute, Savable itself is pretty general and may have alternative implementations, e.g. XML instead of JSON, if we decide we want to switch the storage formats.
If you are really worried about keeping the domain object pure, then don't supply the Savable
definition in the companion object but just put it somewhere else that the compiler can find it
implicitly. However, if you aren't too worried about the domain object declaring itself to be
Savable
then this is about the minimum of boilerplate code that you can get short of
using macros to generate the companions.
Enough of all this theory! Does it work or doesn't it?
The Demo App which creates a Dog, Person and Fruit, and then uses the
StringSaver.saveToString
method to make a string out of it and print it to the
console. We will look at saveToString
in a moment, but for now, click on Run over
on the left side of the activator window, and hit the Start button.
You should see three lines of JSON created in the output for the run. It works!
Let's take a look at that StringSaver.saveToString definition. It's pretty simple:
def saveToString[S <: Product : Savable](item: S): String =
implicitly[Savable[S]].saveToString(item)
Remember that in order to be Savable
, a type has to implement at least
Product
and this bound must be captured here or it won't compile
(of course we could have implemented Savable
without the Product
bound, but it would have been less cool then). Other than that, the method is very straightforward:
it will take any type S that is a Product and has a Savable implicit type class supplied for it.
The implicit is then looked up (using implicitly
and used to call the saveToString
method on Savable
to do the actual work.
Now comes the real payoff (well, if single line serialization to JSON definitions were not enough). What about if we want to switch the format from JSON to something else, say XML?
Take a look at
Savable in the xml package to see an alternative implementation of
Savable
, this one targeting XML strings instead of JSON.
Ponder the code for a while and notice some of the differences. This is a quick and dirty example
and not intended to be useful XML serialization (which would no doubt be a lot more intricate
and cover more of the corner cases).
You will notice that the SavableN definitions don't really add any value, they are provided for API compatibility with the JSON versions, and don't improve on the implementation of Savable in any way for XML. Also, there is a limitation in the XML implementation compared to the JSON one. In the JSON one, fields can be any valid JSON-able field themselves, but the XML one just assumes that any field will be represented by its toString method. The exercise of making a more flexible and complete type class implementation for XML is left to you, and if you really want to understand type class implementations better I heartily recommend you try it out.
To switch to the xml implementation, you need to make changes in a couple of the source files:
In Savable in the xml package comment out the three import lines:
import com.example.save.json._
import spray.json._
import DefaultJsonProtocol._
and uncomment the line:
import com.example.save.xml._
this will activate the xml type classes for Savable instead of the JSON ones. You will also need to
edit StringSaver to comment out the line:
import com.example.save.json._
and uncomment the line
import com.example.save.xml._
and then run the app again, you should see XML output instead of JSON output now.
To get more comfortable with type classes, especially the implementation of them, some of the following exercises may be of interest.
case class Planet(name: String, pos: Int, color: String, mass: Double, yearLength: Double
and define the corresponding Savable companion type class for it in
Example Domain Objects files using the one of the other SavableNs
as an example.
Savable[String], Savable[Double], Savable[Int]
and Savable[Float]
in order to get it to compile now. If you understand why, great, if not, go back and read
the section on implicit context again to grok it. Try out your new implementation on some
nested Savables in both JSON and XML to check that they now work as expected.


| @id | ./ |
|---|---|
| @type | Dataset |
| datePublished [?] | 2023-03-23T14:39:57+00:00 |
| conformsTo [?] | |
| hasPart [?] | |
| license [?] | Apache-2.0 |
| mainEntity [?] | packed.cwl |
| mentions [?] | Run of workflow/packed.cwl#main |
| Items that reference this one | |
| about [?] | ro-crate-metadata.json |
| @id | https://w3id.org/ro/wfrun/process/0.1 |
|---|---|
| name [?] | Process Run Crate |
| @type | CreativeWork |
| version [?] | 0.1 |
| Items that reference this one | |
| conformsTo [?] | ./ |
| @id | https://w3id.org/ro/wfrun/workflow/0.1 |
|---|---|
| name [?] | Workflow Run Crate |
| @type | CreativeWork |
| version [?] | 0.1 |
| Items that reference this one | |
| conformsTo [?] | ./ |
| @id | https://w3id.org/ro/wfrun/provenance/0.1 |
|---|---|
| name [?] | Provenance Run Crate |
| @type | CreativeWork |
| version [?] | 0.1 |
| Items that reference this one | |
| conformsTo [?] | ./ |
| @id | https://w3id.org/workflowhub/workflow-ro-crate/1.0 |
|---|---|
| name [?] | Workflow RO-Crate |
| @type | CreativeWork |
| version [?] | 1.0 |
| Items that reference this one | |
| conformsTo [?] |
| @id | packed.cwl |
|---|---|
| name [?] | packed.cwl |
| @type |
|
| connection [?] | #994ee4db-540c-431c-9d04-f46379582100 |
| hasPart [?] | |
| input [?] | |
| output [?] | output |
| programmingLanguage [?] | Common Workflow Language |
| step [?] | |
| Items that reference this one | |
| hasPart [?] | ./ |
| mainEntity [?] | ./ |
| instrument [?] | Run of workflow/packed.cwl#main |
| @id | 97fe1b50b4582cebc7d853796ebd62e3e163aa3f |
|---|---|
| @type | File |
| alternateName [?] | output.txt |
| exampleOfWork [?] | |
| sha1 [?] | 97fe1b50b4582cebc7d853796ebd62e3e163aa3f |
| Items that reference this one | |
| hasPart [?] | ./ |
| result [?] | Run of workflow/packed.cwl#main/rev |
| object [?] | Run of workflow/packed.cwl#main/sorted |
| @id | #654421a2-66b7-47c0-889a-4047fd22aace |
|---|---|
| name [?] | Run of workflow/packed.cwl#main |
| @type | CreateAction |
| endTime [?] | 2018-10-25T15:46:43.020168 |
| instrument [?] | packed.cwl |
| object [?] |
|
| result [?] | b9214658cc453331b62c2282b772a5c063dbd284 |
| startTime [?] | 2018-10-25T15:46:35.211153 |
| Items that reference this one | |
| mentions [?] | ./ |
| result [?] | Run of cwltool 1.0.20181012180214 |


Hello
I'd like to kindly invite you to another stroll through the park
Location
Central Park, Cluj-Napoca
Date & Time
Whenever you like/can


Pizza palace.
Hello, and welcome to our new website aimed at improving your experience while shopping for your favourite pizza. Enjoy our new option to customize your order right here on the webpage as well as choose whether to have it delivered or to pick it yourself. Bon appétit!
Menu
Please choose your specifications:
Item:
Size:
Enter the toppings you want:
Crust
Drinks
Choose whether to pick-up the order or to have it dropped:
Please be aware that by choosing to have
the package delivered you are subscribing to a
payment charge of 200/=.
Item:
Charge:
Number of pizzas:
Charge:
Size:
Charge:
Toppings:
Charge:
Crust:
Charge:
Drinks:
Charge:
Grand-total:
Thank you for choosing to shop
with us, your package will be delivered to will be waiting for you!


[gecode-users] Change of behaviour since Gecode 3
Mikael Zayenz Lagerkvist
zayenz at kth.se
Mon Mar 23 15:49:22 CET 2009
Hi,
Both your test-programs actually give the same result: failure. A
change in propagation order can easily result in different paths to
the failure, giving the seemingly different domains. See also Section
3.1.7 in "Modeling with Gecode".
Cheers,
Mikael
On Wed, Mar 18, 2009 at 3:22 PM, Vincent Barichard
<Vincent.Barichard at univ-angers.fr> wrote:
> Hi,
>
> I noticed a change of behaviour with Gecode 3. When I run some test problems
> I get a different number of propagations and different domains. Is there any
> trouble in some propagators or maybe I missed something.
>
> I attached a small example:
>
> test.cc is for Gecode 2.2
>
> test.cpp is for Gecode 3
>
> Thanks for your help.
>
> Cheers,
>
> Vincent
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users
>
>
--
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/
More information about the gecode-users
mailing list


Maps and Dictionaries¶
MicroPython dictionaries and maps use techniques called open addressing and linear probing. This chapter details both of these methods.
Open addressing¶
Open addressing is used to resolve collisions. Collisions are very common occurrences and happen when two items happen to hash to the same slot or location. For example, given a hash setup as this:
If there is a request to fill slot 0
with 70
, since the slot 0
is not empty, open addressing
finds the next available slot in the dictionary to service this request. This sequential search for an alternate
location is called probing. There are several sequence probing algorithms but MicroPython uses
linear probing that is described in the next section.
Linear probing¶
Linear probing is one of the methods for finding an available address or slot in a dictionary. In MicroPython,
it is used with open addressing. To service the request described above, unlike other probing algorithms,
linear probing assumes a fixed interval of 1
between probes. The request will therefore be serviced by
placing the item in the next free slot which is slot 4
in our example:
The same methods i.e open addressing and linear probing are used to search for an item in a dictionary.
Assume we want to search for the data item 33
. The computed hash value will be 2. Looking at slot 2
reveals 33
, at this point, we return True
. Searching for 70
is quite different as there was a
collision at the time of insertion. Therefore computing the hash value is 0
which is currently
holding 44
. Instead of simply returning False
, we perform a sequential search starting at point
1
until the item 70
is found or we encounter a free slot. This is the general way of performing
look-ups in hashes:
// not yet found, keep searching in this table
pos = (pos + 1) % set->alloc;
if (pos == start_pos) {
// search got back to starting position, so index is not in table
if (lookup_kind & MP_MAP_LOOKUP_ADD_IF_NOT_FOUND) {
if (avail_slot != NULL) {
// there was an available slot, so use that
set->used++;
*avail_slot = index;
return index;
} else {
// not enough room in table, rehash it
mp_set_rehash(set);
// restart the search for the new element
start_pos = pos = hash % set->alloc;
}
}
} else {
return MP_OBJ_NULL;
}